forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEqualTest.java
More file actions
26 lines (20 loc) · 885 Bytes
/
EqualTest.java
File metadata and controls
26 lines (20 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package fj;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
public class EqualTest {
@Test
public void contramapShouldWork() {
Equal<String> equalByLength = Equal.contramap(String::length, Equal.intEqual);
assertThat(equalByLength.eq("str1", "str2"), is(true));
assertThat(equalByLength.eq("str1", "str11"), is(false));
}
@Test
public void thenShouldWork() {
Equal<String> equalByLengthThenLastDigit = Equal.on(String::length, Equal.intEqual)
.then(s -> s.charAt(s.length() - 1), Equal.charEqual).equal();
assertThat(equalByLengthThenLastDigit.eq("str1", "spr1"), is(true));
assertThat(equalByLengthThenLastDigit.eq("str1", "str2"), is(false));
assertThat(equalByLengthThenLastDigit.eq("str1", "strr1"), is(false));
}
}