From 766114c05bcd0b0388988aaf606e046857e6946a Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 10 May 2016 17:10:31 +0200 Subject: Add lists and maps functions --- test/ch/epfl/xblast/ListsTest.java | 47 ++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/ch/epfl/xblast/ListsTest.java b/test/ch/epfl/xblast/ListsTest.java index b18b05e..e62eede 100644 --- a/test/ch/epfl/xblast/ListsTest.java +++ b/test/ch/epfl/xblast/ListsTest.java @@ -2,10 +2,7 @@ package ch.epfl.xblast; import org.junit.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -63,4 +60,46 @@ public class ListsTest { assertEquals(expected, Lists.permutations(sampleList)); } + @Test + public void areListsMapped() { + final List keyList = Arrays.asList('a', 'b'); + final List valueList = Arrays.asList(0, 1); + + final Map expectedMap = new HashMap<>(); + expectedMap.put('a', 0); + expectedMap.put('b', 1); + + assertEquals(expectedMap, Lists.linearMap(keyList, valueList)); + } + + @Test + public void areMapsTraversed() { + final Map m1 = new HashMap<>(); + m1.put('a', 0); + m1.put('b', 1); + + final Map m2 = new HashMap<>(); + m2.put(0, "Apple"); + m2.put(1, "Banana"); + + final Map expectedMap = new HashMap<>(); + expectedMap.put('a', "Apple"); + expectedMap.put('b', "Banana"); + + assertEquals(expectedMap, Lists.traverseMaps(m1, m2)); + } + + @Test + public void isMapInverted() { + final Map sampleMap = new HashMap<>(); + sampleMap.put('a', 0); + sampleMap.put('b', 1); + + final Map expectedMap = new HashMap<>(); + expectedMap.put(0, 'a'); + expectedMap.put(1, 'b'); + + assertEquals(expectedMap, Lists.invertMap(sampleMap)); + } + } -- cgit v1.2.3