Skip to content
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

Merged
merged 8 commits into from
Jun 19, 2021

Conversation

jiegillet
Copy link
Contributor

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 through canonical-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 nested describe 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.

@github-actions
Copy link
Contributor

Thank you for contributing to exercism/elixir 💜 🎉. This is an automated PR comment 🤖 for the maintainers of this repository that helps with the PR review process. You can safely ignore it and wait for a maintainer to review your changes.

Based on the files changed in this PR, it would be good to pay attention to the following details when reviewing the PR:

  • General steps

    • 🏆 Does this PR need to receive a label with a reputation modifier (reputation/contributed_code/{minor,major})? (A medium reputation amount is awarded by default, see docs)
  • Any exercise changed

    • 👤 Does the author of the PR need to be added as an author or contributor in <exercise>/.meta/config.json (see docs)?
    • 🔬 Do the analyzer and the analyzer comments exist for this exercise? Do they need to be changed?
    • 📜 Does the design file (<exercise>/.meta/design.md) need to be updated to document new implementation decisions?
  • Practice exercise changed

    • 🌲 Do prerequisites, practices, and difficulty in config.json need to be updated?
    • 🧑‍🏫 Are the changes in accordance with the community-wide problem specifiations?
  • Practice exercise tests changed

    • ⚪️ Are all tests except the first one skipped?
    • 📜 Does <exercise>/.meta/tests.toml need updating?

Automated comment created by PR Commenter 🤖.

config.json Outdated
"floating-point-numbers"
],
"practices": [
"pattern-matching",
Copy link
Contributor Author

@jiegillet jiegillet Jun 16, 2021

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?

Copy link
Contributor

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.

@angelikatyborska
Copy link
Contributor

Thank you again! I'll try to review until the end of the week, I'm a bit busy in the next few days.

@angelikatyborska
Copy link
Contributor

I have not tested it very much on other exercises, (...) but if it's something that is worth pursuing, I'm willing to make it better.

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 bin/configlet sync, which should add them to the tests.toml files. A real test generator would read tests.toml files and on based on their contents and canonical-data.json files update the test suite. Different exercises are slightly incompatible with canonical-data.json in different ways, so it's possible that it would still require some manual work each time.

I will personally keep using it for more exercises.

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.

Copy link
Contributor

@angelikatyborska angelikatyborska left a 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",
Copy link
Contributor

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"
Copy link
Contributor

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:

Suggested change
"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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Comment on lines 61 to 66
%{
"description" => description,
"property" => property,
"input" => %{} = input,
"expected" => expected
} = c,
Copy link
Contributor

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 🙂

Copy link
Contributor Author

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.

Copy link
Contributor

@neenjaw neenjaw left a 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.

Copy link
Contributor

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}."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, thank you!

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:size/large Large amount of work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants