From 7c19be7f34b932d696d839a092f05617400589f6 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Mon, 29 Feb 2016 17:25:37 +0100 Subject: Rewrite list mirroring function and add test --- test/ch/epfl/xblast/ListsTest.java | 40 ++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'test/ch/epfl') 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 @@ package ch.epfl.xblast; -import java.util.List; -import java.util.Arrays; -import static org.junit.Assert.*; import org.junit.Test; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import static org.junit.Assert.assertEquals; + /** -* @author Pacien TRAN-GIRARD (261948) -* @author Timothée FLOURE (257420) -*/ + * @author Pacien TRAN-GIRARD (261948) + * @author Timothée FLOURE (257420) + */ public class ListsTest { - @Test(expected=IllegalArgumentException.class) + + @Test(expected = IllegalArgumentException.class) public void isEmptyListThrowingException() { - List sampleList = Arrays.asList(); - Lists.mirrored(sampleList); + List emptyList = new ArrayList<>(); + Lists.mirrored(emptyList); } @Test public void isListMirrored() { - List sampleList = Arrays.asList(1,2,3,4,5); - List expected = Arrays.asList(1,2,3,4,5,4,3,2,1); + List sampleList = Arrays.asList(1, 2, 3, 4, 5); + List expected = Arrays.asList(1, 2, 3, 4, 5, 4, 3, 2, 1); + + assertEquals(expected, Lists.mirrored(sampleList)); + } - assertEquals(expected, Lists.mirrored(sampleList)); + @Test + public void mirrorElementsAreEqual() { + List sampleList = IntStream.range(0, 10).boxed().collect(Collectors.toList()); + List mirrored = Lists.mirrored(sampleList); + + for (int i = 0; i < mirrored.size() / 2; ++i) + assertEquals(mirrored.get(i), mirrored.get(mirrored.size() - 1 - i)); } + } -- cgit v1.2.3