Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Probability Kata part 2
OK so now you have implemented the kata. Your tests should look something like this:
We can say that the tests define the object "in a calculus of itself". They are not state based tests, they define how the behaviours of the object interact with each other.
To see the real value of this let's introduce some change ... I hear real system's do this occasionally. Because this is a high performance system decimal math is too slow. You now need to use floats instead.
Need help on floating point math? Check out: http://www-users.math.umd.edu/~jkolesar/mait613/floating_point_math.pdf
You will need to use a non-exact equality... How will this change your code?
Are you doing a refactor for this or a refuctor? Did you change a test? If you did the kata right you should not have any changes to your tests to make this change.
Remember there is no such thing as changing a test. A change to a test is a new test
you have no saftey net from it. Changing a test means a refuctor
@dlidstrom

This comment has been minimized.

Copy link

dlidstrom commented Sep 6, 2011

Here's what I did:

public class Probability
{
    public Probability(decimal prob);
    public Probability CombinedWith(Probability probability);
    public Probability InverseOf();
    public Probability Either(Probability other);
    public override bool Equals(object obj);
    public bool Equals(Probability other);
    public override int GetHashCode();
}

Ok, so I didn't actually implement the floating point math. I'm free to do so without any change to my tests since the Probability class is properly encapsulated. I know from experience that comparing floats probably cannot be reliably satisfied by a simple override of object.Equals, but I guess it is enough for this excercise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.