@Override @Test public void subList() { super.subList(); MutableList<String> list = this.newWith("A", "B", "C", "D"); MutableList<String> sublist = list.subList(1, 3); Verify.assertPostSerializedEqualsAndHashCode(sublist); Verify.assertSize(2, sublist); Verify.assertContainsAll(sublist, "B", "C"); sublist.add("X"); Verify.assertSize(3, sublist); Verify.assertContainsAll(sublist, "B", "C", "X"); Verify.assertSize(5, list); Verify.assertContainsAll(list, "A", "B", "C", "X", "D"); sublist.remove("X"); Verify.assertContainsAll(sublist, "B", "C"); Verify.assertContainsAll(list, "A", "B", "C", "D"); Assert.assertEquals("C", sublist.set(1, "R")); Verify.assertContainsAll(sublist, "B", "R"); Verify.assertContainsAll(list, "A", "B", "R", "D"); sublist.addAll(Arrays.asList("W", "G")); Verify.assertContainsAll(sublist, "B", "R", "W", "G"); Verify.assertContainsAll(list, "A", "B", "R", "W", "G", "D"); sublist.clear(); Verify.assertEmpty(sublist); Verify.assertContainsAll(list, "A", "D"); }
@Test public void equalsAndHashCode() { Interval interval1 = Interval.oneTo(5); Interval interval2 = Interval.oneTo(5); Interval interval3 = Interval.zeroTo(5); Verify.assertPostSerializedEqualsAndHashCode(interval1); Verify.assertEqualsAndHashCode(interval1, interval2); Assert.assertNotEquals(interval1, interval3); Assert.assertNotEquals(interval3, interval1); Verify.assertEqualsAndHashCode(Interval.fromToBy(1, 5, 2), Interval.fromToBy(1, 6, 2)); Verify.assertEqualsAndHashCode(FastList.newListWith(1, 2, 3), Interval.fromTo(1, 3)); Verify.assertEqualsAndHashCode(FastList.newListWith(3, 2, 1), Interval.fromTo(3, 1)); Assert.assertNotEquals(FastList.newListWith(1, 2, 3, 4), Interval.fromTo(1, 3)); Assert.assertNotEquals(FastList.newListWith(1, 2, 4), Interval.fromTo(1, 3)); Assert.assertNotEquals(FastList.newListWith(3, 2, 0), Interval.fromTo(3, 1)); Verify.assertEqualsAndHashCode(FastList.newListWith(-1, -2, -3), Interval.fromTo(-1, -3)); }
@Override @Test public void equalsAndHashCode() { MutableList<Integer> integers = this.newWith(1, 2, 3); MutableList<Integer> integers2 = this.newWith(1, 2, 3); MutableList<Integer> integers3 = this.newWith(1, null, 3, 4, 5); MutableList<Integer> integers4 = this.newWith(1, null, 3, 4, 5); MutableList<Integer> integers5 = this.newWith(1, null, 3); MutableList<Integer> randomAccessList = Lists.fixedSize.of(1, 2, 3); MutableList<Integer> randomAccessList2 = Lists.fixedSize.of(2, 3, 4); Verify.assertEqualsAndHashCode(integers, integers); Verify.assertPostSerializedEqualsAndHashCode(integers); Verify.assertEqualsAndHashCode(integers, integers2); Verify.assertEqualsAndHashCode(integers, randomAccessList); Assert.assertNotEquals(integers, integers3); Assert.assertNotEquals(integers, integers5); Assert.assertNotEquals(integers, randomAccessList2); Assert.assertNotEquals(integers, Sets.fixedSize.of()); Verify.assertEqualsAndHashCode(integers3, integers4); Verify.assertEqualsAndHashCode(integers3, ArrayAdapter.newArrayWith(1, null, 3, 4, 5)); Assert.assertEquals(integers, integers2); Assert.assertNotEquals(integers, integers3); }
@Test public void serializationOfEmpty() { MutableList<Integer> collection = MultiReaderFastList.newList(); Verify.assertPostSerializedEqualsAndHashCode(collection); }
@Test public void equalsAndHashCode() { Verify.assertEqualsAndHashCode(this.list, FastList.newList(this.list)); Verify.assertPostSerializedEqualsAndHashCode(this.list); }