-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
[#765] New practice exercise complex-numbers
#769
[#765] New practice exercise complex-numbers
#769
Conversation
Thank you for contributing to Based on the files changed in this PR, it would be good to pay attention to the following details when reviewing the PR:
Automated comment created by PR Commenter 🤖. |
config.json
Outdated
"floating-point-numbers" | ||
], | ||
"practices": [ | ||
"pattern-matching", |
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.
Should I remove pattern matching? There are too many exercises. It's not crucial at all. Maybe replace by erlang-libraries
because of the :math
functions?
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.
Yes, good idea. Let's replace pattern-matching
with erlang-libraries
. Only 1 exercise so far practices erlang-libraries
.
Thank you again! I'll try to review until the end of the week, I'm a bit busy in the next few days. |
It's definitely something that we would want at some point. Ideally, it would allow you to automatically implement new tests for all exercise. Tests often get added to canonical data after the exercise has been around for while. You get new tests by running
Good plan! Let's keep it in the repository so that other people can use it too, and that it serves as a reference for when we will be building a proper test generator. |
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.
Looks great 🙂 we just need to update "practice" to get the checks passing and move the generator script somewhere else.
config.json
Outdated
"floating-point-numbers" | ||
], | ||
"practices": [ | ||
"pattern-matching", |
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.
Yes, good idea. Let's replace pattern-matching
with erlang-libraries
. Only 1 exercise so far practices erlang-libraries
.
config.json
Outdated
"prerequisites": [ | ||
"pattern-matching", | ||
"erlang-libraries", | ||
"floating-point-numbers" |
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.
Let's be explicit about needing tuples:
"floating-point-numbers" | |
"floating-point-numbers", | |
"tuples" |
@@ -0,0 +1,158 @@ | |||
# Generates test cases and basic template, which will need to be adapted by hand | |||
# Pass the name of the exercise (e. g, "complex-numbers") as an argument |
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.
This is pretty cool! It's not exactly a full blown test generator because it won't allow easily updating the test suite, but it's a really nice way to bootstrap a new exercise.
Th file cannot stay under exercises/practice/complex-numbers/generate_tests.exs
because it would get downloaded to student machines, but we can keep it under exercises/practice/complex-numbers/.meta/generate_tests.exs
or maybe even outside the exercise under bin/generate_tests.exs
?
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.
Yes, it should definitely be in bin
, I just left it here for now for discussion.
I will probably expand it a bit to generate all of the other files, might as well, and rename it bootstrap_practice_exercise.exs
or something to be more explicit. If it can serve as a basis for a better test generator later, that would be good.
%{ | ||
"description" => description, | ||
"property" => property, | ||
"input" => %{} = input, | ||
"expected" => expected | ||
} = c, |
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.
A heads-up for the future or maybe for when we will extend the script: there are some exercises that have deprecated test cases. If a test case is deprecated, there is another test case that has a key "reimplements", for example:
https://github.com/exercism/problem-specifications/blob/e2779fc84ff07cb5bd8ff89f38e78af6d17b5056/exercises/hamming/canonical-data.json#L117-L140
In such a case, only one of the two tests needs to be implemented, ideally the newer one 🙂
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 to know, thank you! As of now, it would print the test in the following way
test "disallow empty first strand" do
# Normalises error messages
# -- reimplements --
# db92e77e-7c72-499d-8fe6-9354d2bfd504
...
Which is not that bad, since there needs to be a manual check anyway.
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.
NIce work implementing this exercise, will be a good addition.
Left a comment about the description, I think it'd be useful to explain how we are representing the complex number with a tuple-pair.
I also agree with @angelikatyborska's suggestions.
Implement the following operations: | ||
- addition, subtraction, multiplication and division of two complex numbers, | ||
- conjugate, absolute value, exponent of a given complex number. | ||
|
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 would like to see a description of how the complex pair is represented with a tuple to represent the real and imaginary part.
Ex) "For this exercise, a complex number will be a tuple-pair where the number 4+3i
would be represented by {4, 3}
."
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 idea, thank you!
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.
All the documentation I saw discouraged me from changing the description of the exercise, so I updated the @typedoc
instead.
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.
You can put it in an append file: https://github.com/exercism/docs/blob/main/building/tracks/practice-exercises.md#documentation-files
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.
Just a word of explanation: we're not supposed to change anything in instructions.md
because there will be a script soon that allows synchronizing it with the problem specifications repository in case of changes, and then track-specific changes would get overwritten. That's why there's an append file for this.
New one!
Inspired by @elibdev I have written (and committed, I know it doesn't belong in this PR) a quick and dirty script
generate_tests.exs
. This goes throughcanonical-data.json
and build the test and lib files. Of course, it is still required to edit by hand, but I it was way easier than copy/pasting stuff from 31 tests.I have not tested it very much on other exercises, and even here it has limitations (this
canonical-data.json
had nesteddescribe
which is not allowed in Elixir, so I fixed that by hand), but if it's something that is worth pursuing, I'm willing to make it better. It could also generate other files pretty easily. Let me know what you think. I will personally keep using it for more exercises.