-
Couldn't load subscription status.
- Fork 1.4k
Add zipAllWith to Chunk #1164 #1612
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
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.
Congratulations! 🎉
| def testzipAllWith = { | ||
| Chunk(1, 2, 3).zipAllWith(Chunk(3, 2, 1))(_ => 0, _ => 0)(_ + _) == Chunk(4, 4, 4) | ||
| Chunk(1, 2, 3).zipAllWith(Chunk(3, 2))(_ => 0, _ => 0)(_ + _) == Chunk(4, 4, 0) | ||
| Chunk(1, 2).zipAllWith(Chunk(3, 2, 1))(_ => 0, _ => 0)(_ + _) == Chunk(4, 4, 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.
Note that only this line is actually being tested – only the value last of the last statement is returned and == is just a pure function here, not an assertion. You could try joining all the conditions with && to test the first 2 equalities too.
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 means that instead of writing:
Chunk(1, 2, 3).zipAllWith(Chunk(3, 2, 1))(_ => 0, _ => 0)(_ + _) == Chunk(4, 4, 4)
Chunk(1, 2, 3).zipAllWith(Chunk(3, 2))(_ => 0, _ => 0)(_ + _) == Chunk(4, 4, 0)
Chunk(1, 2).zipAllWith(Chunk(3, 2, 1))(_ => 0, _ => 0)(_ + _) == Chunk(4, 4, 0)You should instead write:
(Chunk(1, 2, 3).zipAllWith(Chunk(3, 2, 1))(_ => 0, _ => 0)(_ + _) == Chunk(4, 4, 4)) &&
(Chunk(1, 2, 3).zipAllWith(Chunk(3, 2))(_ => 0, _ => 0)(_ + _) == Chunk(4, 4, 0)) &&
(Chunk(1, 2).zipAllWith(Chunk(3, 2, 1))(_ => 0, _ => 0)(_ + _) == Chunk(4, 4, 0))The reason is that in Specs2, the line Chunk(...) == Chunk(..) constructs a value. So you have 3 lines of code, each constructing a value:
<construct value 1>
<construct value 2>
<construct value 3>But in Scala, when you define a method like so:
def method = {
<construct value 1>
<construct value 2>
<construct value 3>
}Then the first two values (1 and 2, in this example), will be "thrown away". The method will return only the final value (3).
We want to return a test value that combines all them together. We want all tests to pass, so we use the "and" operator &&, which can take two test results and return another test result, which will succeed only if both tests succeeded.
|
oops .. |
|
Congratulations! 🎉 |
No description provided.