-
-
Notifications
You must be signed in to change notification settings - Fork 525
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
Conversation
skip | ||
question = 'What is -3 plus 7 multiplied by -2?' | ||
message = 'You should ignore order of precedence. -3 + 7 * -2 = -8, not -17' |
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 the custom message that isn't currently generated.
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.
Can you work out how to make the generator add this message yourself, or would you like some hints?
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.
Hints would be perfect, actually 😄 ! I can't quite work out how I would implement this without modifying the shared test data
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.
See my latest comments.
@@ -0,0 +1,20 @@ | |||
#!/usr/bin/env ruby |
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 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 😄
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 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' |
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 line doesn't need to be here.
require_relative 'wordy' | ||
|
||
# Test data version: | ||
# <%= sha1 %> |
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.
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) |
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.
Why does this one have brackets around the arguments?
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.
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?
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 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.
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.
Ah, yes. That sounds great to me!
This is a good decision.
No, just create a .version 1 (which you have done.)
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. |
skip | ||
question = 'Who is the President of the United States?' |
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 question doesn't start with 'What is' but that's probably an issue for the common metadata.
@tommyschaefer you might be interested in looking at my proposal for how test generators should work in future: Insti#1 |
@Insti I took a look and it looks great! I based the interface of the Thank you so much for your help! |
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)) |
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 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.)
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.
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)" |
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.
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)
@Insti Fantastic! Thank you so much for the help! I'll make these updates and push them this evening! 😀 |
@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! |
This looks good. You could squash. |
be981a8
to
9aaa8a1
Compare
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:
|
6723f75
to
2588a3f
Compare
The configuration shows that rvm is version 2.1.2. I don't think this is correct..
The above snipped...
Shows the version of RVM that I am using that was updated only a few days ago. |
2588a3f
to
753d7af
Compare
Can you rebase on master and submit to test the travis-ci? |
753d7af
to
deddfa3
Compare
@kotp Looks like it worked! 😄 |
Ready for a squash again. |
deddfa3
to
bb75f81
Compare
Thanks for all your work on this @tommyschaefer ❤️ |
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:
and
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?
Does anything special have to happen since this wasn't originally book-kept?
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 😄 !