Skip to content

Commit b2477c1

Browse files
committed
Omit assertion values, cleanup
1 parent eaa5be3 commit b2477c1

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/test/java/com/jnape/palatable/lambdakoans/AboutApplicatives.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,27 @@
2626
import static com.jnape.palatable.lambda.functions.builtin.fn1.Repeat.repeat;
2727
import static com.jnape.palatable.lambda.functions.builtin.fn2.Take.take;
2828
import static com.jnape.palatable.lambda.functor.builtin.Lazy.lazy;
29+
import static com.jnape.palatable.lambdakoans.Koans.__;
2930
import static java.util.Arrays.asList;
3031
import static org.hamcrest.CoreMatchers.equalTo;
3132
import static org.hamcrest.MatcherAssert.assertThat;
3233
import static testsupport.matchers.IterableMatcher.iterates;
3334

3435
public class AboutApplicatives {
36+
3537
@Test
3638
public void applicativesZipEmbeddedValuesWithEmbeddedFunctions() {
3739
Fn1<Integer, Integer> inc = x -> x + 1;
3840

3941
assertThat(just(9).zip(just(inc)), equalTo(just(10)));
40-
assertThat(just(15).zip(just(inc)), equalTo(just(16)));
41-
// Explicit types on the nothing help the compiler
42-
assertThat(Maybe.<Integer>nothing().zip(just(inc)), equalTo(nothing()));
42+
assertThat(just(15).zip(just(inc)), equalTo(just(__)));
43+
// Explicit types help the compiler
44+
assertThat(Maybe.<Integer>nothing().zip(just(inc)), equalTo(__));
4345

4446
Fn1<? super String, ? extends Integer> getStringLength = String::length;
45-
assertThat(right("Hello").zip(right(getStringLength)), equalTo(right(5)));
46-
assertThat(right("World!").zip(right(getStringLength)), equalTo(right(6)));
47-
// Explicit types on the nothing help the compiler
48-
assertThat(Either.<String, String>left("whoops").zip(right(getStringLength)), equalTo(left("whoops")));
47+
assertThat(right("Hello").zip(right(getStringLength)), equalTo(__));
48+
assertThat(right("World!").zip(right(getStringLength)), equalTo(__));
49+
assertThat(Either.<String, String>left("whoops").zip(right(getStringLength)), equalTo(left(__)));
4950

5051
// Moving on to LambdaIterables, where "zipping" is more obvious
5152
LambdaIterable<Integer> oneThroughThree = LambdaIterable.wrap(asList(1, 2, 3));
@@ -58,7 +59,7 @@ public void applicativesZipEmbeddedValuesWithEmbeddedFunctions() {
5859

5960
Fn1<Integer, Integer> times3 = x -> x * 3;
6061
LambdaIterable<Fn1<? super Integer, ? extends Integer>> allFunctions = LambdaIterable.wrap(asList(inc, dec, times3));
61-
assertThat(oneThroughThree.zip(allFunctions).unwrap(), iterates(2, 0, 3, 3, 1, 6, 4, 2, 9));
62+
assertThat(oneThroughThree.zip(allFunctions).unwrap(), iterates(__()));
6263
}
6364

6465
@Test
@@ -69,7 +70,7 @@ public void lazyApplicatives() {
6970

7071
LambdaIterable<Fn1<? super Integer, ? extends Integer>> wrappedInc = LambdaIterable.wrap(asList(inc));
7172
LambdaIterable<Integer> zippedOnes = infiniteOnes.zip(wrappedInc);
72-
assertThat(take(3, zippedOnes.unwrap()), iterates(2, 2, 2));
73+
assertThat(take(3, zippedOnes.unwrap()), iterates(__()));
7374

7475
// We might lazily get a mapping function...
7576
AtomicInteger computed = new AtomicInteger(0);
@@ -88,13 +89,13 @@ public void lazyApplicatives() {
8889
Maybe<Integer> nothing = nothing();
8990
Lazy<Maybe<String>> lazyNothingToString = nothing.lazyZip(lazyGetToString);
9091

91-
assertThat(lazyNothingToString.value(), equalTo(nothing()));
92-
assertThat(computed.get(), equalTo(0));
92+
assertThat(lazyNothingToString.value(), equalTo(__));
93+
assertThat(computed.get(), equalTo(__));
9394

9495
// zip, however, we've eagerly generated a mapping function
9596
Maybe<String> nothingToString = nothing.zip(expensiveWayToGetMaybeToString.apply(100_000));
96-
assertThat(nothingToString, equalTo(nothing()));
97-
assertThat(computed.get(), equalTo(100_000));
97+
assertThat(nothingToString, equalTo(__));
98+
assertThat(computed.get(), equalTo(__));
9899
}
99100

100101
@Test
@@ -110,15 +111,15 @@ public void functionIsApplicative() {
110111
Fn1<Integer, Integer> div3 = i -> i / 3;
111112

112113
Fn1<Integer, String> showDivision = LiftA2.liftA2((divided, remainder) -> String.format("%d * 3 + %d", divided, remainder), div3, mod3);
113-
assertThat(showDivision.apply(10), equalTo("3 * 3 + 1"));
114+
assertThat(showDivision.apply(10), equalTo(__));
114115

115116

116117
Fn1<String, Integer> findStart = s -> s.indexOf('j');
117118
Fn1<String, Integer> findEnd = s -> s.indexOf(' ');
118119
Fn3<String, Integer, Integer, String> cutString = String::substring;
119120

120121
Fn1<String, String> transformAndCut = LiftA3.liftA3(cutString, toUpper, findStart, findEnd);
121-
assertThat(transformAndCut.apply("hellojava world"), equalTo("JAVA"));
122+
assertThat(transformAndCut.apply("hellojava world"), equalTo(__));
122123
}
123124

124125
@Test
@@ -138,7 +139,7 @@ public void applicativeRepresentsParallelism() throws ExecutionException, Interr
138139
long singleThreadStart = System.currentTimeMillis();
139140

140141
applicativeInIo
141-
.flatMap(result -> IO.io(() -> assertThat(result, equalTo(42))))
142+
.flatMap(result -> IO.io(() -> assertThat(result, equalTo(__))))
142143
.unsafePerformIO();
143144

144145
System.out.printf("Single thread execution took %d seconds%n", (System.currentTimeMillis() - singleThreadStart) / 1000);
@@ -147,10 +148,10 @@ public void applicativeRepresentsParallelism() throws ExecutionException, Interr
147148
long multipleThreadStart = System.currentTimeMillis();
148149

149150
applicativeInIo
150-
.flatMap(result -> IO.io(() -> assertThat(result, equalTo(42))))
151+
.flatMap(result -> IO.io(() -> assertThat(result, equalTo(__))))
151152
.unsafePerformAsyncIO(Executors.newFixedThreadPool(2))
152153
.get();
153154

154-
System.out.printf("Single thread execution took %d seconds%n", (System.currentTimeMillis() - multipleThreadStart) / 1000);
155+
System.out.printf("Multiple thread execution took %d seconds%n", (System.currentTimeMillis() - multipleThreadStart) / 1000);
155156
}
156157
}

src/test/java/com/jnape/palatable/lambdakoans/AboutFunctors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ public void fn1sAreAlsoFunctorsOverTheirOutputType() {
6868
Fn1<Integer, Integer> inc = x -> x + 1;
6969

7070
Fn1<String, Integer> lengthThenInc = length.fmap(inc); // fmap for Fn1 is just left-to-right composition!
71-
assertThat(lengthThenInc.apply("13 characters"), __());
71+
assertThat(lengthThenInc.apply("13 characters"), equalTo(__));
7272
}
7373
}

0 commit comments

Comments
 (0)