-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add complex numbers exercise - Part I #378
Conversation
Well, I've given it some thought, and I do think we should be using a separate
|
I would agree that a ComplexNumber class is the way to go. There already exist similar C# classes to achieve a similar concept (e.g. BigInteger). I also believe creating a new class is actually a little easier and more natural for students, and that a Tuple would make things harder in the end. I know I've written more classes than I have Tuples. |
@ErikSchierboom @jpreese thanks for the great feedback. I've updated the exercise with a ComplexNumber struct, so you guys can let me know what you think :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is starting to look great! Two remarks.
generators/Output/ValueFormatter.cs
Outdated
@@ -32,6 +32,8 @@ public static object Format(object val) | |||
return flt.ToString(CultureInfo.InvariantCulture); | |||
case char c: | |||
return $"'{c}'"; | |||
case Tuple<int, int> tuple: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this case anymore, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct I can remove this now
var z1 = new ComplexNumber { Real = 0, Imaginary = 1 }; | ||
var z2 = new ComplexNumber { Real = 0, Imaginary = 1 }; | ||
var expected = new ComplexNumber { Real = -1, Imaginary = 0 }; | ||
Assert.Equal(expected, ComplexNumbers.Mul(z1, z2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering of the static class approach makes sense. Shouldn't we be using instance methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ErikSchierboom I'm fine with that approach which will end up with using having pretty much the same solution as they do in the Java track:
https://github.com/exercism/java/blob/master/exercises/complex-numbers/src/example/java/ComplexNumber.java
The getReal
and getImaginary
methods are trivially to implement, but that's definitely not the main complexity of the question.
Another thing is once I implement part II, I'll have to convert the integers to be double to represent non-whole numbers with pi
and e
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good points! Good luck with pt. II
@robkeim The build has failed. Any idea why? |
@ErikSchierboom @robkeim It looks like ComplexNumbers wasn't added to the "All" solutions file. |
@ErikSchierboom @jpreese I'm making progress on this and it now includes Part II as well :) Now there are two issues left:
|
We also removed the Default from the build, so I don't think we even need this solution anymore. But we might still need it for legacy reasons that I'm unaware of so @ErikSchierboom can confirm or deny that.
|
@jpreese thanks for the linked issue about the GUIDs, I'll just let Visual Studio do it's thing then :) Regarding the failing test cases it's these two that are failing:
The reason for the failures is due to double precision so the answers are |
I think I know an easy solution. IIRC there is an Assert.Equal overload that takes a third parameter: the precision to use when comparing equality. |
@ErikSchierboom yes that method exists: However, that means the tests are going to have to call |
Hmmm, I don't have a great solution then |
By the way, I'd like to keep the Default solution for now, as I have plans that require it :) I'll create an issue for it. |
@ErikSchierboom I think that's the first time I've seen you not have a solution to a problem I'm asking... guess there's a first time for everything :) I've gone ahead and created a custom comparison that takes into account the precision and now the tests are green! You can go ahead and review @ErikSchierboom and @jpreese. |
@robkeim Don't hold it against me! ;) But I miss the comparer, isn't it just the precision overload of Assert.Equal that you are using? Looking great BTW! |
@ErikSchierboom I won't hold it against you don't worry :) Yes I decided to go down the route of the |
This is for #342
This is Part I because I didn't do the exponent portion yet, I wanted to get feedback first.
A couple of questions:
@ErikSchierboom the generator for this turned out to be pretty easy after all :)