@Test public void testFirst() throws Exception { List<String> mList = new ArrayList<>(); mList.add("x"); mList.add("y"); mList.add("z"); mList.add("w"); ImmutableList<String> l = new ArrayBackedImmutableList<String>(mList); Assert.assertEquals("x", l.first()); Assert.assertEquals("y", l.tail(1).first()); Assert.assertEquals("z", l.subList(2, 1).first()); }
@Test public void testSublist() throws Exception { List<String> mList = new ArrayList<>(); mList.add("x"); mList.add("y"); mList.add("z"); mList.add("w"); ImmutableList<String> l = new ArrayBackedImmutableList<String>(mList); Assert.assertEquals("[]", l.subList(0, 0).toString()); Assert.assertEquals("[x]", l.subList(0, 1).toString()); Assert.assertEquals("[x, y]", l.subList(0, 2).toString()); Assert.assertEquals("[x, y, z]", l.subList(0, 3).toString()); Assert.assertEquals("[x, y, z, w]", l.subList(0, 4).toString()); Assert.assertEquals("[y, z, w]", l.subList(1, 3).toString()); Assert.assertEquals("[y, z]", l.subList(1, 2).toString()); Assert.assertEquals("[y, z]", l.subList(1, 2).toString()); Assert.assertEquals("[y]", l.subList(1, 1).toString()); Assert.assertEquals("[z]", l.subList(2, 1).toString()); }