Conversation
| assertEquals(3, queue.size()); | ||
| assertEquals(5, secondQueue.size()); | ||
|
|
||
| secondQueue.dequeue() |
There was a problem hiding this comment.
Not sure about this structure. Isn't there an easier way of checking if all queue elements are in there? Queue is essentially an iterable so it should be doable easily
There was a problem hiding this comment.
Yes, Queue is iterable. But, I wanted to show that dequeue() function returns a Tuple2 which is different from a mutable Queue. And that there is a map() function to work on the contents of the Tuple2.
There was a problem hiding this comment.
This is definitely a must-have to show those things but not this way by nesting assertions in map calls and not by nesting dequeue calls inside map calls.
If you want to show that a Tuple gets returned containing head and tail, you can start easily with:
Tuple2<Integer, Queue<Integer>> result = secondQueue.dequeue();
and then perform necessary assertions.
Next thing, if you want to show a map call, definitely do not go with names like (k,v) which suggest that this key-value relationship. Keep in mind that map always needs to return another Tuple
result.map((head, tail) -> Tuple.of(head.toString(), tail))
There is also a method that you can use for transforming the whole tuple into something that is not wrapped in the Tuple:
result.apply((head, tail) -> head.toString());
and so on... you can store results of those operations as variables and perform assertions on them.
| Number sum = vavrList.map(i -> i * i) | ||
| .sum(); | ||
|
|
||
| assertEquals(new Long(14), sum); |
There was a problem hiding this comment.
The boxing of Long is unnecessary
|
|
||
| @Test | ||
| public void givenSortedSet_whenReversed_thenCorrect() { | ||
| Comparator<String> reverseCompare = (a, b) -> b.compareTo(a); |
There was a problem hiding this comment.
the (a, b) -> b.compareTo(a) can be replaced with Comparator.reverseOrder();
| java.util.List<Integer> javaList = java.util.Arrays.asList(1, 2, 3, 4); | ||
| List<Integer> vavrList = List.ofAll(javaList); | ||
|
|
||
| assertTrue(vavrList instanceof io.vavr.collection.List); |
There was a problem hiding this comment.
Those instanceof assertions do not really bring anything new here. You can easily remove them and leave this test without assertions. After all, those are just supposed to be a short main methods and not full-blown tests
There was a problem hiding this comment.
Is it Ok to have this example in a private method in the same test class? Just wondering if a separate main class is required just for a few lines of code.
For rest of the comments, will work on it as suggested.
| @Test | ||
| public void givenMap_whenIterated_thenCorrect() { | ||
| Map<Integer, List<Integer>> map = List.rangeClosed(0, 10) | ||
| .groupBy(i -> i % 2); |
There was a problem hiding this comment.
Please use the provided formatter. Continuation indents should be 2 spaces
Collection API in Vavr