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

Add vectorised unit test for Collatz Conjecture #111

Merged
merged 2 commits into from
Jan 17, 2019

Conversation

xarxziux
Copy link
Contributor

@xarxziux xarxziux commented Oct 6, 2018

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:

  • An extra test has been added to the unit tests that send a four-element vector to the function.
  • In the example, the 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.

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.
@xarxziux xarxziux changed the title Fix unit tests and example for Collatz Conjecture Add vectorised unit test for Collatz Conjecture Oct 6, 2018
@katrinleinweber
Copy link
Contributor

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

@katrinleinweber katrinleinweber Oct 13, 2018

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.

Copy link
Contributor

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

Copy link
Member

@jonmcalder jonmcalder left a comment

Choose a reason for hiding this comment

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

👍

@jonmcalder jonmcalder merged commit 27021c1 into exercism:master Jan 17, 2019
@xarxziux xarxziux deleted the issue_109 branch January 21, 2019 11:01
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.

3 participants