import static org.junit.Assert.*; import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.TreeSet; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; public class Test2CTest { @Rule public ExpectedException exception = ExpectedException.none(); @Test public void testFirst() { assertEquals('m', Test2C.first("m")); assertEquals('t', Test2C.first("test")); assertEquals('v', Test2C.first("video")); } @Test public void testSecond() { assertEquals('m', Test2C.second("am")); assertEquals('t', Test2C.second("xtest")); assertEquals('v', Test2C.second("yvideo")); } @Test public void testSecondThrows1() { exception.expect(IllegalArgumentException.class); Test2C.second(""); } @Test public void testSecondThrows2() { exception.expect(IllegalArgumentException.class); Test2C.second("d"); } @Test public void testLongest() { final String LONGEST = "Machiavellianism"; final String S[] = {"A", "BC", "DEF", "GHIJ", LONGEST, "xyz"}; final String EXP[] = {"A", "BC", "DEF", "GHIJ", LONGEST, LONGEST}; Set t = new TreeSet(); assertEquals("", Test2C.longest(t)); for (int i = 0; i < S.length; i++) { t.add(S[i]); assertEquals(EXP[i], Test2C.longest(t)); } } @Test public void testMostFrequent() { final String S[][] = { {"a"}, {"c", "b"}, {"a", "x", "b", "b", "x"}, {"a", "b", "q", "q", "q", "b", "x", "y"} }; final String EXP[] = {"a", "b", "b", "q"}; for (int i = 0; i < S.length; i++) { List t = Arrays.asList(S[i]); assertEquals(EXP[i], Test2C.mostFrequent(t)); } } }