@Test public void splitAtIndex() { final String oompaLoompa = "oompaloompa"; Assert.assertEquals(Tuples.twin("oompa", "loompa"), StringIterate.splitAtIndex(oompaLoompa, 5)); Assert.assertEquals(Tuples.twin("", oompaLoompa), StringIterate.splitAtIndex(oompaLoompa, 0)); Assert.assertEquals( Tuples.twin(oompaLoompa, ""), StringIterate.splitAtIndex(oompaLoompa, oompaLoompa.length())); Assert.assertEquals(Tuples.twin("", ""), StringIterate.splitAtIndex("", 0)); Verify.assertThrows( StringIndexOutOfBoundsException.class, new Runnable() { public void run() { StringIterate.splitAtIndex(oompaLoompa, 17); } }); Verify.assertThrows( StringIndexOutOfBoundsException.class, new Runnable() { public void run() { StringIterate.splitAtIndex(oompaLoompa, -8); } }); }
@Test public void forEachInBoth() { final MutableList<Pair<String, String>> list = Lists.mutable.of(); ArrayList<String> list1 = new ArrayList<String>(mList("1", "2")); ArrayList<String> list2 = new ArrayList<String>(mList("a", "b")); ArrayListIterate.forEachInBoth( list1, list2, new Procedure2<String, String>() { public void value(String argument1, String argument2) { list.add(Tuples.twin(argument1, argument2)); } }); Assert.assertEquals(FastList.newListWith(Tuples.twin("1", "a"), Tuples.twin("2", "b")), list); }
@Test public void nonUniqueWith() { Twin<String> twin1 = Tuples.twin("1", "1"); Twin<String> twin2 = Tuples.twin("2", "2"); Twin<String> twin3 = Tuples.twin("3", "3"); Twin<String> twin4 = Tuples.twin("4", "4"); QuadrupletonSet<Twin<String>> set = new QuadrupletonSet<>(twin1, twin2, twin3, twin4); set.with(Tuples.twin("1", "1")); set.with(Tuples.twin("2", "2")); set.with(Tuples.twin("3", "3")); set.with(Tuples.twin("4", "4")); Assert.assertSame(set.getFirst(), twin1); Assert.assertSame(set.getSecond(), twin2); Assert.assertSame(set.getThird(), twin3); Assert.assertSame(set.getLast(), twin4); }