Created
November 3, 2017 14:00
-
-
Save franreyes/44b14720a4f32800df9cafee11e320ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exchange bank= new Exchange(). | |
bank.addRate("USD", "GBP", STANDARD_RATE); | |
bank.commission(STANDARD_COMMISSION); | |
Money result= bank.convert(new Note(100, "USD"), "GBP"); | |
assertEquals(new Note(49.25, "GBP"), result); | |
----- | |
Exchange bank= new Exchange(). | |
bank.addRate("USD", "GBP", 2); | |
bank.commission(0.0015); | |
Money result= bank.convert(new Note(100, "USD"), "GBP"); | |
assertEquals(new Note(100 / 2 * (1 - 0.0015), "GBP"), result); // <- Improving communication over simplification??? | |
// Connection between the numbers used in the input and the numbers used to calculate the expected result |
I think a middle ground hits a sweet spot:
val rate = 2
val commission = 0.0015
bank.addRate(USD, GBP, rate);
bank.commission(commission);
assertThat(bank.convert(Note(100, USD), GBP), equalTo(Note(100 / rate * (1 - commission), GBP)))
And turning it into a property...
forAll(doublesGreaterThan(0)) { rate ->
forAll(doublesGreaterThan(0)) { commission ->
bank.addRate(USD, GBP, rate);
bank.commission(commission);
assertThat(bank.convert(Note(100, USD), GBP), equalTo(Note(100 / rate * (1 - commission), GBP)))
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about a mix?