-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add vectorised unit test for Collatz Conjecture #111
Conversation
Sync fork with main repo
As a demonstration of the point I raised in issue exercism#109, here is an update for the non-core Collatz Conjecture exercise. The current version of this does not test for vector parameters and the example would fail this test. The following changes have been made: - An extra test has been added to the unit tests that send a four-element vector to the function. - In the example, he original function `collatz_step_counter` has been renamed to `collatz_scalar`. - Also in the example, the line `collatz_step_counter <- Vectorize(collatz_scalar)` has been added. This is a very minor change to the example, but makes the function a lot more powerful by taking full advantage of R's vectorisation capabilities. R developers really shouldn't be thinking in single values the way most mainstream programming languages do.
I have this on the radar, and will try to review it this weekend. Sorry for the delay! |
@@ -27,4 +27,9 @@ test_that("Negative input results in an error", { | |||
expect_error(collatz_step_counter(-15)) | |||
}) | |||
|
|||
test_that("Answer can accept vector parameter", { |
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) Is this message a clear enough to provide a learner (who progressed through our track without having to think about vectorising!) with sufficient guidance, so that they are able to refactor their most-tests-passing solution according to this last test?
b) Should we update the ReadMe as well? Maybe with a note that we start testing for compatibility with the R-idiomatic vector-support here?
As I mentioned in #109 (comment), I'm a novice when it comes to this topic.
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.
How about we merge this, and observe the learner feedback? My worried comment about the wording being unclear may to totally unwarranted, and I will not be able to help for the next few weeks.
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.
👍
As a demonstration of the point I raised in issue #109, here is an update for the non-core Collatz Conjecture exercise. The current version of this does not test for vector parameters and the example would fail this test.
The following changes have been made:
collatz_step_counter
has been renamed tocollatz_scalar
.collatz_step_counter <- Vectorize(collatz_scalar)
has been added.This is a very minor change to the example, but makes the function a lot more powerful by taking full advantage of R's vectorisation capabilities. R developers really shouldn't be thinking in single values the way most mainstream programming languages do.