Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Vilkina
Copy link
Contributor

@Vilkina Vilkina commented Sep 7, 2019

No description provided.

Copy link
Member

@neko-kai neko-kai left a 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)
Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

@Vilkina

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.

@jdegoes
Copy link
Member

jdegoes commented Sep 9, 2019

@Vilkina Awesome work! Just the one bit of feedback from @neko-kai, and we should be good to merge!

@Vilkina
Copy link
Contributor Author

Vilkina commented Sep 9, 2019

oops ..

@neko-kai neko-kai merged commit b607621 into zio:master Sep 10, 2019
@neko-kai
Copy link
Member

Congratulations! 🎉

jdegoes pushed a commit that referenced this pull request Nov 18, 2019
* Add zipAllWith to Chunk #1164

* Add zipAllWith to Chunk #1164 #1612

* Add zipAllWith to Chunk #1164

* format ChunkSpec.scala

* Add a microsite section for ZIO Chunk #2267
Twizty pushed a commit to Twizty/zio that referenced this pull request Nov 19, 2019
* Add zipAllWith to Chunk zio#1164

* Add zipAllWith to Chunk zio#1164 zio#1612

* Add zipAllWith to Chunk zio#1164

* format ChunkSpec.scala

* Add a microsite section for ZIO Chunk zio#2267
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