diff options
author | Pacien TRAN-GIRARD | 2016-02-29 17:25:37 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2016-02-29 17:25:37 +0100 |
commit | 7c19be7f34b932d696d839a092f05617400589f6 (patch) | |
tree | 0b4f89ef40794b75c302fa808cd364176efc0fdf /test | |
parent | ee00d0bfbfa5ea253559038c27a23da33c528d0e (diff) | |
download | xblast-7c19be7f34b932d696d839a092f05617400589f6.tar.gz |
Rewrite list mirroring function and add test
Diffstat (limited to 'test')
-rw-r--r-- | test/ch/epfl/xblast/ListsTest.java | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java index 42b317f..0a2f5f9 100644 --- a/test/ch/epfl/xblast/ListsTest.java +++ b/test/ch/epfl/xblast/ListsTest.java | |||
@@ -1,26 +1,42 @@ | |||
1 | package ch.epfl.xblast; | 1 | package ch.epfl.xblast; |
2 | 2 | ||
3 | import java.util.List; | ||
4 | import java.util.Arrays; | ||
5 | import static org.junit.Assert.*; | ||
6 | import org.junit.Test; | 3 | import org.junit.Test; |
7 | 4 | ||
5 | import java.util.ArrayList; | ||
6 | import java.util.Arrays; | ||
7 | import java.util.List; | ||
8 | import java.util.stream.Collectors; | ||
9 | import java.util.stream.IntStream; | ||
10 | |||
11 | import static org.junit.Assert.assertEquals; | ||
12 | |||
8 | /** | 13 | /** |
9 | * @author Pacien TRAN-GIRARD (261948) | 14 | * @author Pacien TRAN-GIRARD (261948) |
10 | * @author Timothée FLOURE (257420) | 15 | * @author Timothée FLOURE (257420) |
11 | */ | 16 | */ |
12 | public class ListsTest { | 17 | public class ListsTest { |
13 | @Test(expected=IllegalArgumentException.class) | 18 | |
19 | @Test(expected = IllegalArgumentException.class) | ||
14 | public void isEmptyListThrowingException() { | 20 | public void isEmptyListThrowingException() { |
15 | List<Integer> sampleList = Arrays.asList(); | 21 | List<Integer> emptyList = new ArrayList<>(); |
16 | Lists.<Integer>mirrored(sampleList); | 22 | Lists.mirrored(emptyList); |
17 | } | 23 | } |
18 | 24 | ||
19 | @Test | 25 | @Test |
20 | public void isListMirrored() { | 26 | public void isListMirrored() { |
21 | List<Integer> sampleList = Arrays.asList(1,2,3,4,5); | 27 | List<Integer> sampleList = Arrays.asList(1, 2, 3, 4, 5); |
22 | List<Integer> expected = Arrays.asList(1,2,3,4,5,4,3,2,1); | 28 | List<Integer> expected = Arrays.asList(1, 2, 3, 4, 5, 4, 3, 2, 1); |
29 | |||
30 | assertEquals(expected, Lists.mirrored(sampleList)); | ||
31 | } | ||
23 | 32 | ||
24 | assertEquals(expected, Lists.<Integer>mirrored(sampleList)); | 33 | @Test |
34 | public void mirrorElementsAreEqual() { | ||
35 | List<Integer> sampleList = IntStream.range(0, 10).boxed().collect(Collectors.toList()); | ||
36 | List<Integer> mirrored = Lists.mirrored(sampleList); | ||
37 | |||
38 | for (int i = 0; i < mirrored.size() / 2; ++i) | ||
39 | assertEquals(mirrored.get(i), mirrored.get(mirrored.size() - 1 - i)); | ||
25 | } | 40 | } |
41 | |||
26 | } | 42 | } |