Open
Conversation
Member
Author
|
Incoming fly-by e-mail patch submitted, but I can not approve. |
Member
|
I can't see what this is testing. Do you have an example of code that previously was incorrectly passing pls? |
Member
Author
|
It is testing that we indeed get a total count for some products. Student code was passing but would not pass with this additional test. def total_stock
stock = items.map { |item| item[:quantity_by_size] }.first
stock.nil? || stock.empty? ? OUT_OF_STOCK : stock.each_value.inject(:+)
endWould pass the current tests, but would fail this situation as presented in the tests. The test was really testing that we got the total in the first listed type of product, rather than the indicated "total of some products". The additional test drove this solution for this student: def total_stock
items.inject(0) do |counter, item|
counter + item[:quantity_by_size].inject(0) { |sum, values| sum + values.last }
end
end |
This corrects a bug that would not account for all items in some inventory that would otherwise pass the tests.
6ba9260 to
dd240f4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This corrects a bug that would not account for all items in some
inventory that would otherwise pass the tests.