|
3 | 3 | import org.junit.Before; |
4 | 4 | import org.junit.Test; |
5 | 5 |
|
6 | | -import static org.junit.Assert.assertFalse; |
7 | | -import static org.junit.Assert.assertTrue; |
| 6 | +import java.util.function.Function; |
| 7 | + |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
8 | 9 |
|
9 | 10 | public class ContainsDuplicatesTest { |
10 | 11 |
|
11 | | - private ContainsDuplicates containsDuplicates; |
| 12 | + private ContainsDuplicates solver; |
12 | 13 |
|
13 | 14 | @Before |
14 | 15 | public void setUp() throws Exception { |
15 | | - containsDuplicates = new ContainsDuplicates(); |
| 16 | + solver = new ContainsDuplicates(); |
16 | 17 | } |
17 | 18 |
|
18 | 19 | @Test |
19 | 20 | public void usingSet() { |
20 | | - assertTrue(containsDuplicates.usingSet(new int[]{2, 1, 3, 1})); |
21 | | - assertFalse(containsDuplicates.usingSet(new int[]{2, 1, 3, 56, 4})); |
22 | | - assertTrue(containsDuplicates.usingSet(new int[]{1, 1, 1, 3, 3, 4, 3, 2, 4, 2})); |
| 21 | + checkAssertions(solver::usingSet); |
23 | 22 | } |
24 | 23 |
|
25 | 24 | @Test |
26 | 25 | public void usingSortWithEarlyReturn() { |
27 | | - assertTrue(containsDuplicates.usingSortWithEarlyReturn(new int[]{2, 1, 3, 1})); |
28 | | - assertFalse(containsDuplicates.usingSortWithEarlyReturn(new int[]{2, 1, 3, 56, 4})); |
29 | | - assertTrue(containsDuplicates.usingSortWithEarlyReturn(new int[]{1, 1, 1, 3, 3, 4, 3, 2, 4, 2})); |
| 26 | + checkAssertions(solver::usingSortWithEarlyReturn); |
| 27 | + } |
| 28 | + |
| 29 | + private void checkAssertions(Function<int[], Boolean> function) { |
| 30 | + assertThat(function.apply(new int[]{2, 1, 3, 1})).isTrue(); |
| 31 | + assertThat(function.apply(new int[]{2, 1, 3, 56, 4})).isFalse(); |
| 32 | + assertThat(function.apply(new int[]{1, 1, 1, 3, 3, 4, 3, 2, 4, 2})).isTrue(); |
30 | 33 | } |
31 | 34 | } |
0 commit comments