Conversation
116aebb to
fcf30af
Compare
| require 'minitest/autorun' | ||
| require_relative 'custom_set' | ||
|
|
||
| # rubocop:disable Metrics/LineLength |
There was a problem hiding this comment.
Hmm, I don't like this. The offending lines seem overly verbose. Would it be advisable to shorten them up in the x-common json?
There was a problem hiding this comment.
Yes, it does make sense to attack this in the common file. I did not like it when I did it either. I am not addressing it here though, as it is not the 'source'. The source is the linked issues, I think I have linked them in the PR.
There was a problem hiding this comment.
This file is generated and the lines are only long because the test names are verbose so I have no problem with disabling the LineLength metric here.
c00472e to
305d594
Compare
| "set1 = CustomSet.new #{set1} | ||
| set2 = CustomSet.new #{set2} | ||
| expected = CustomSet.new(#{expected}) | ||
| #{assert_or_refute}_equal set1.union(set2), expected" |
There was a problem hiding this comment.
I like how you're assigning expected to a variable, but it appears that you have expected and actual inverted which will cause confusing test failure messages.
(A lot of the test templates in this file have this issue.)
The signature for assert_equal is: assert_equal(exp, act, msg = nil)
305d594 to
695ff51
Compare
| end | ||
|
|
||
| def test_body | ||
| send section |
There was a problem hiding this comment.
I was trying to attack this vector from the other end... This is much simpler... Thanks @Insti !
| json = JSON.parse(data) | ||
| cases = [] | ||
| (json.keys - ['#']).each do |section| | ||
| json[section]['cases'].each_with_index do |row, i| |
There was a problem hiding this comment.
I believe this each_with_index should be simply an each while the above line's each should be the each_with_index. This is currently leaving the first exercise of each type (diff, union, etc.) unskipped.
There was a problem hiding this comment.
@Cohen-Carlisle Thanks for keeping an eye on this...
|
Noticed one more thing about skips but other than that I think it looks good. |
695ff51 to
ee5ff9f
Compare
|
Manual index had to go back in, if that is the only thing with the skips, I think we are ready to merge. |
| skip | ||
| set = CustomSet.new [1] | ||
| refute_equal CustomSet.new, set | ||
| end |
There was a problem hiding this comment.
Shouldn't the empty tests use the empty? method? As written, these are really testing equality and not emptiness.
There was a problem hiding this comment.
The test assert_empty? requires that the object responds to empty? and there is no spec for that currently.
There was a problem hiding this comment.
I believe this should be that very spec. The metadata for these exercises is:
"empty": {
"description": "Returns true if the set contains no elements",
"cases": [
"..."
]
},This is not the place to rely on equality. Equality has its own section later on.
|
Looked more closely and had more comments 😛 |
ee5ff9f to
0b14fa1
Compare
|
There seems to be some confusion over whether to use |
|
If I am following the leads properly, it seems that there no common data that dictates a test that forces a method to be defined strictly named "empty?". That is an implementation that may be wise, but at the moment I am not seeing that it is forced. The same with equality. The metadata that I am looking at is specifically 'example.rb', and 'custom-set.json', and nothing else. The restriction is "refactoring" level, so no changes in behavior, hopefully. The goal for this PR is simply to bring in the tests from x-common repository. Definitely not to make improvements in the testing at this time. I may not be looking at it from the proper point of view though. If I have accomplished this, with this goal in mind, then I think we can bring it in, and then address the "we should have the implementation have I think you are correct about the equality and the empty being defined... and an "empty?" method being desirable. Especially since "empty" is defined, and so a query partner for that method makes even more sense, because of it. |
|
There should not be an There is an The tests that @kotp has implemented accurately reflect the intent of the common data and the problem description. |
|
I strongly disagree. Looking at the PR that put the current ordering into place (exercism/problem-specifications#257), we see the comment:
Edit: Tagging @ryanplusplus for make him aware there is still confusion over the appropriate time to use equality, and for any input. |
|
I was wrong. Having re-read the referenced thread and reviewed the json file I now agree with @Cohen-Carlisle |
| skip | ||
| set = CustomSet.new [] | ||
| element = 1 | ||
| refute set.member? element |
There was a problem hiding this comment.
member? should be contains?
member is not referenced in the custom-set.json but contains is.
There was a problem hiding this comment.
I would actually make an argument for include? as its the most common duck typed method for this kind of thing in Ruby. I don't think we have to stick to the description exactly, especially when ruby has a clear pattern for this kind of query.
Edit: And include? is the Enumerable standard. http://ruby-doc.org/core-2.3.1/Enumerable.html#method-i-include-3F
There was a problem hiding this comment.
The names in section don't necessarily have to match the methods, they are section headers for common-data. But I changed it in the example code anyway.
0b14fa1 to
a6b9c93
Compare
|
Two of my comments seem to have been buried after unrelated diff changes.
assert CustomSet.new([1]).subset? CustomSet.new([])Read in English, this reads:
Which is actually backwards. Ruby's standard library agrees.
|
|
Also, #386 applies here. Not sure if we want to hold it up over that or fix it later. |
|
I think it was taken care of, if this is the code that you are thinking of. def test_empty_set_is_a_subset_of_non_empty_set
skip
set1 = CustomSet.new []
set2 = CustomSet.new [1]
assert set2.subset? set1
end
def test_non_empty_set_is_not_a_subset_of_empty_set
skip
set1 = CustomSet.new [1]
set2 = CustomSet.new []
refute set2.subset? set1
end |
a6b9c93 to
db189a6
Compare
|
|
When you use a named test in minitest it can use a specific method. When you use equals, then you use whatever you want to compare together. This is why using them will sometimes expose that a certain method is not used, due to internals, at least that is what I am seeing when I apply suggested changes with specific method names. In the code that appears wrong, feel free to clone the PR branch and play with it, and propose a solution... because I am not seeing what you are seeing, or I am not properly recreating the situation. I have changed it over and over again, and get feedback based on the actual runs. |
|
I'm unfortunately pretty busy right now and will be for a while. I was trying to say that the logic around the receiver and argument should be swapped. Instead of In other words, it should be implemented as "is the receiver a subset of the argument?", while its currently "is the argument a subset of the receiver?" |
|
I had changed it I think at least twice now... Going from def test_empty_set_is_a_subset_of_non_empty_set
skip
set1 = CustomSet.new []
set2 = CustomSet.new [1]
assert set2.subset? set1
end
def test_non_empty_set_is_not_a_subset_of_empty_set
skip
set1 = CustomSet.new [1]
set2 = CustomSet.new []
refute set2.subset? set1
endto def test_empty_set_is_a_subset_of_non_empty_set
skip
set1 = CustomSet.new []
set2 = CustomSet.new [1]
assert set1.subset? set2
end
def test_non_empty_set_is_not_a_subset_of_empty_set
skip
set1 = CustomSet.new [1]
set2 = CustomSet.new []
refute set1.subset? set2
endand back again when I get a comment that it is incorrect. |
|
The second one looks correct, but does not match the code in the currently committed |
|
I do not have a version that has not been merged in. Would have to dig through the outdated ones to see. But I am pretty sure I had done this a few times and we keep going back and forth. |
|
Oh, "when I get a comment that it is incorrect" may be comments from the tests, not from a human. Perhaps the example.rb is not implemented correctly/backwards. |
|
The |
db189a6 to
9b35ab2
Compare
The custom-set exercise is generated using data from x-common repository. fixes #365 fixes #348 references exercism/problem-specifications#257
9b35ab2 to
e90b94f
Compare
| def member?(datum) | ||
| data.any? { |node| node.datum.eql?(datum) } | ||
| end | ||
| alias include? member? |
There was a problem hiding this comment.
Enumerable aliases member? to include? while internally, it uses member. Standard library Set has Ruby method include? which it aliases to member?.
|
I think the most recent change fixed most of the problems we had with this PR. |
|
Thanks @Cohen-Carlisle and @Insti the goal of at least having it generated is now complete. Now we can focus on any changes that come out, based on common data. |
The custom-set exercise is generated using data from x-common
repository.
fixes #365
fixes #348
references exercism/problem-specifications#257