Skip to content

wordy: Generate tests #509

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

Merged
merged 1 commit into from
Dec 29, 2016
Merged

Conversation

tommyschaefer
Copy link
Contributor

@tommyschaefer tommyschaefer commented Dec 19, 2016

Hi there!

I've made a first pass at converting the wordy exercise to use generated tests (#396).

I based the updates on #474, but I still have a few questions:

  1. The original tests use a mixture of the following forms:
question = '...'
assert_equal ...

and

assert_equal 1, WordProblem.new('...').answer

I'm assuming this has to do with not going past 80 characters per line. In my first pass I decided to just use the first form for all of the tests. Is this okay, or should I put some work into switching between the two forms based on the length of the assertion?

  1. Does anything special have to happen since this wasn't originally book-kept?

  2. In the test_add_then_multiply / test_addition_and_multiplication test, the xruby implementation includes a custom error message. Should this error message be removed (as it is currently), or should we add the custom error message to the shared metadata and generate based on that?

Thank you so much for your time 😄 !

skip
question = 'What is -3 plus 7 multiplied by -2?'
message = 'You should ignore order of precedence. -3 + 7 * -2 = -8, not -17'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the custom message that isn't currently generated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you work out how to make the generator add this message yourself, or would you like some hints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hints would be perfect, actually 😄 ! I can't quite work out how I would implement this without modifying the shared test data

Copy link
Contributor

Choose a reason for hiding this comment

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

See my latest comments.

@@ -0,0 +1,20 @@
#!/usr/bin/env ruby
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know that there was some discussion about removing this in #295. Should it be included in newly generated tests? I wasn't too sure whether a decision had been made 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think a conclusion was ever reached, you could try leaving it out and see if anyone notices.

@@ -0,0 +1,20 @@
#!/usr/bin/env ruby
gem 'minitest', '>= 5.0.0'
Copy link
Contributor

Choose a reason for hiding this comment

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

This line doesn't need to be here.

require_relative 'wordy'

# Test data version:
# <%= sha1 %>
Copy link
Contributor

@Insti Insti Dec 20, 2016

Choose a reason for hiding this comment

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

These 2 comments should be one line.

skip
assert_equal(-11, WordProblem.new('What is -1 plus -10?').answer)
question = 'What is -1 plus -10?'
assert_equal(-11, WordProblem.new(question).answer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this one have brackets around the arguments?

Copy link
Contributor Author

@tommyschaefer tommyschaefer Dec 20, 2016

Choose a reason for hiding this comment

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

Hi there!

I originally thought that it was something enforced by rubocop, but I'm not sure now. Whenever I save the file without the parentheses, I get a warning in Vim ambiguous first argument; put parentheses or a space even after '-' operator (only for cases with a negative number).

I'm assuming that's maybe why the original cases also had parens around negative cases?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's a Rubocop warning, it's not particularly important, but it's better to make all the cases consistent so in this case I'd wrap them all in parentheses. This has the pleasant side effect of making your value_assertion method much simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes. That sounds great to me!

@Insti
Copy link
Contributor

Insti commented Dec 20, 2016

The original tests use a mixture of the following forms:
(snip)
I decided to just use the first form for all of the tests.

This is a good decision.

Does anything special have to happen since this wasn't originally book-kept?

No, just create a .version 1 (which you have done.)

In the test_add_then_multiply / test_addition_and_multiplication test, the xruby implementation includes a custom error message. Should this error message be removed (as it is currently), or should we add the custom error message to the shared metadata and generate based on that?

The custom error message could be added to the shared metadata, but it is probably better to first implement it here in the xruby wordy generator.

See: https://github.com/exercism/xruby/blob/master/lib/triangle_cases.rb for a (poor) example of preprocessing the common data before creating the tests.

@Insti Insti changed the title Exercise Wordy: Generate Tests wordy: Generate tests Dec 20, 2016
skip
question = 'Who is the President of the United States?'
Copy link
Contributor

Choose a reason for hiding this comment

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

This question doesn't start with 'What is' but that's probably an issue for the common metadata.

@Insti
Copy link
Contributor

Insti commented Dec 20, 2016

@tommyschaefer you might be interested in looking at my proposal for how test generators should work in future: Insti#1

@tommyschaefer
Copy link
Contributor Author

@Insti I took a look and it looks great! I based the interface of the WordyCase class on the discussions on #463. Is there anything I can do to WordyCases to make it easier to convert to the future generator? The thing that jumped out most to me was the inclusion of a workload method, but is there anything else that would make it easier to update?

Thank you so much for your help!

@Insti
Copy link
Contributor

Insti commented Dec 20, 2016

Don't worry too much about making this future compatible, the new format is not finalized and there will be a project to review all the generators when it is.


WordyCases = proc do |data|
JSON.parse(data)['cases'].map.with_index do |row, i|
WordyCase.new(row.merge('index' => i))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can preprocess the json here to add a failure message:

wordy_case = WordyCase.new(row.merge('index' => i, failure_message => nil))
if wordy_case.question = 'What is -3 plus 7 multiplied by -2?'
  wordy_case.failure_message = 'You should ignore order of precedence. -3 + 7 * -2 = -8, not -17'
end
wordy_case

(untested, a Github comment box is not an ideal programming environment.)

Copy link
Contributor

@Insti Insti Dec 22, 2016

Choose a reason for hiding this comment

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

One thing to bear in mind here is that the failure message should show the actual value returned. (This will need to be inserted in the assertion method)

def assertion
return error_assertion unless expected

"assert_equal(#{expected}, WordProblem.new(question).answer)"
Copy link
Contributor

@Insti Insti Dec 22, 2016

Choose a reason for hiding this comment

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

Then you can add your custom failure message here.

message = failure_message || "Expected #{expected} but got #{result}"
"assert_equal(#{expected}, WordProblem.new(question).answer, #{message})"

(This code will not work as-is)

@tommyschaefer
Copy link
Contributor Author

@Insti Fantastic! Thank you so much for the help! I'll make these updates and push them this evening! 😀

@tommyschaefer
Copy link
Contributor Author

@Insti Does this look ready to review to you? If so, would you like me to go ahead and squash the commits? Thank you so much for your time and help!

@kotp
Copy link
Member

kotp commented Dec 27, 2016

This looks good. You could squash.

@tommyschaefer
Copy link
Contributor Author

Hmm... I'm not sure why this is failing all of the sudden. I don't think its based on these commits.

Relevant output of the log:

$ export BUNDLE_GEMFILE=$PWD/Gemfile
$ ruby --version
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
$ rvm --version
rvm 1.26.10 (latest-minor) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
$ bundle --version
Bundler version 1.6.5
$ gem --version
2.4.5
$ bundle install --quiet
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /home/travis/.rvm/rubies/ruby-2.1.2/bin/ruby mkrf_conf.rb 

/home/travis/.rvm/rubies/ruby-2.1.2/bin/ruby -rubygems /home/travis/.rvm/gems/ruby-2.1.2/gems/rake-12.0.0/exe/rake RUBYARCHDIR=/home/travis/.rvm/gems/ruby-2.1.2/extensions/x86_64-linux/2.1.0/rainbow-2.2.0 RUBYLIBDIR=/home/travis/.rvm/gems/ruby-2.1.2/extensions/x86_64-linux/2.1.0/rainbow-2.2.0
(in /home/travis/.rvm/gems/ruby-2.1.2/gems/rainbow-2.2.0)
fatal: Not a git repository (or any of the parent directories): .git
rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
/home/travis/.rvm/gems/ruby-2.1.2/gems/rainbow-2.2.0/Rakefile:2:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.1.2/gems/rake-12.0.0/exe/rake:27:in `<main>'
(See full trace by running task with --trace)

rake failed, exit code 1

@kotp
Copy link
Member

kotp commented Dec 27, 2016

The configuration shows that rvm is version 2.1.2. I don't think this is correct..

{
  "language": "ruby",
  "sudo": false,
  "rvm": "2.1.2",
  "install": [

The above snipped...

rvm:
    version:      "rvm 1.28.0 (master) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"

Shows the version of RVM that I am using that was updated only a few days ago.

@kotp
Copy link
Member

kotp commented Dec 28, 2016

Can you rebase on master and submit to test the travis-ci?

@tommyschaefer
Copy link
Contributor Author

@kotp Looks like it worked! 😄

@kotp
Copy link
Member

kotp commented Dec 28, 2016

Ready for a squash again.

@Insti Insti merged commit 00f9a48 into exercism:master Dec 29, 2016
@Insti
Copy link
Contributor

Insti commented Dec 29, 2016

Thanks for all your work on this @tommyschaefer ❤️

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