Skip to content

hyperia-forex: Add missing test cases and fix Exemplar.cs - #1666

Merged
ErikSchierboom merged 6 commits into
exercism:mainfrom
sanderploegsma:improvement/add-hyperia-forex-test-cases
Oct 1, 2021
Merged

ErikSchierboom merged 6 commits into
exercism:mainfrom
sanderploegsma:improvement/add-hyperia-forex-test-cases

Conversation

@sanderploegsma

Copy link
Copy Markdown
Contributor

This adds test cases to cover all tasks of the exercise, instead of just the == operator. To get all of the tests to pass two changes were required to the exemplar implementation:

  1. The != operator was not correctly overridden: it actually calls itself causing a stack overflow.
  2. The / operator was overloaded to support both new CurrencyAmount(100, "USD") / 2m and 2m / new CurrencyAmount(100, "USD"). The first version is part of the specification and makes total sense. However, the second version is not mentioned in the instructions anywhere, and in my opinion also doesn't make any sense: what would this even return?

This fixes #1652.

The existing test suite only covers the `==` operator, which is introduced in the initial sub-problem. All of the other operators were not tested.
The fact that the `*` operator is overloaded twice makes sense because multiplication is commutative (2 * X == X * 2), but the same does not hold for division. In fact, `2 / new CurrencyAmount(10, "UD")` does not even make sense, what type should it return?

Therefore, I don't think this method should be part of the exemplar implementation at all.
The existing implementation does not match the specification and also results in a StackOverflow because it calls itself.
Comment thread exercises/concept/hyperia-forex/HyperiaForexTests.cs Outdated
@ErikSchierboom

Copy link
Copy Markdown
Member

However, the second version is not mentioned in the instructions anywhere, and in my opinion also doesn't make any sense: what would this even return?

Yeah, let's remove this.

@sanderploegsma

Copy link
Copy Markdown
Contributor Author

I just realized that adding these test cases will mean that you are no longer able to run the tests half-way through the exercises, because the test suite won't compile until all the operators on CurrencyAmount are defined. I haven't worked much with the V3 online editor yet so I'm not sure whether running the tests before finishing all the tasks is possible/recommended, but I wanted to point it out nonetheless.

@ErikSchierboom

Copy link
Copy Markdown
Member

@sanderploegsma Yeah this is a problem that we have with several exercises, and not something that is easy to fix. It's fine for now.

Merging this is blocked by exercism/csharp-test-runner#67 BTW. I just found out that I don't unskip non-Fact tests. Whoops! Once that is merged (should be a couple of hours), I'll merge this.

@sanderploegsma

Copy link
Copy Markdown
Contributor Author

Ah that's a good catch! I did check the test.ps1 script to make sure that it was able to unskip the non-Fact tests (which it is) but I didn't think to check the test runner.

@ErikSchierboom ErikSchierboom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test runner update has been deployed. Thanks!

@ErikSchierboom
ErikSchierboom merged commit 6bc8e7a into exercism:main Oct 1, 2021
@sanderploegsma
sanderploegsma deleted the improvement/add-hyperia-forex-test-cases branch October 1, 2021 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hyperia-forex: add missing tests

2 participants