add *List.range() and *List.rangeClosed()

This commit is contained in:
2018-09-08 08:48:47 +02:00
parent 336905fafe
commit 1d0d3e6d2b
4 changed files with 356 additions and 230 deletions

View File

@@ -45,6 +45,69 @@ public class IntListTest {
}
}
@Test
public void testRange() {
final IntList expected = IntList.of(1, 2, 3, 4, 5);
final IntList list = IntList.range(1, 6);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(5, list.getCapacity());
}
@Test
public void testRangeWithNegativeValues() {
final IntList expected = IntList.of(Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2);
final IntList list = IntList.range(Integer.MIN_VALUE, Integer.MIN_VALUE + 3);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(3, list.getCapacity());
}
@Test
public void testEmptyRange() {
final IntList expected = IntList.of();
final IntList list = IntList.range(1, 1);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(0, list.getCapacity());
}
@Test
public void testNegativeRange() {
final IntList expected = IntList.of();
final IntList list = IntList.range(1, 0);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(0, list.getCapacity());
}
@Test
public void testRangeClosed() {
final IntList expected = IntList.of(1, 2, 3, 4, 5);
final IntList list = IntList.rangeClosed(1, 5);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(5, list.getCapacity());
}
@Test
public void testRangeClosedWithNegativeValues() {
final IntList expected = IntList.of(Integer.MIN_VALUE, Integer.MIN_VALUE + 1, Integer.MIN_VALUE + 2);
final IntList list = IntList.rangeClosed(Integer.MIN_VALUE, Integer.MIN_VALUE + 2);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(3, list.getCapacity());
}
@Test
public void testOneElementRangeClosed() {
final IntList expected = IntList.of(1);
final IntList list = IntList.rangeClosed(1, 1);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(1, list.getCapacity());
}
@Test
public void testEmptyRangeClosed() {
final IntList expected = IntList.of();
final IntList list = IntList.rangeClosed(1, 0);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
}
@Test
public void testAdd() {
// setting initial size to one, so that the first add does not need to resize,

View File

@@ -45,6 +45,77 @@ public class LongListTest {
}
}
@Test
public void testRange() {
final LongList expected = LongList.of(1, 2, 3, 4, 5);
final LongList list = LongList.range(1, 6);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(5, list.getCapacity());
}
@Test
public void testRangeWithNegativeValues() {
final LongList expected = LongList.of(Long.MIN_VALUE, Long.MIN_VALUE + 1, Long.MIN_VALUE + 2);
final LongList list = LongList.range(Long.MIN_VALUE, Long.MIN_VALUE + 3);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(3, list.getCapacity());
}
@Test
public void testEmptyRange() {
final LongList expected = LongList.of();
final LongList list = LongList.range(1, 1);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(0, list.getCapacity());
}
@Test
public void testNegativeRange() {
final LongList expected = LongList.of();
final LongList list = LongList.range(1, 0);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(0, list.getCapacity());
}
@Test
public void testRangeClosed() {
final IntList expected = IntList.of(1, 2, 3, 4, 5);
final IntList list = IntList.rangeClosed(1, 5);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(5, list.getCapacity());
}
@Test
public void testRangeClosedWithNegativeValues() {
final LongList expected = LongList.of(Long.MIN_VALUE, Long.MIN_VALUE + 1, Long.MIN_VALUE + 2);
final LongList list = LongList.rangeClosed(Long.MIN_VALUE, Long.MIN_VALUE + 2);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(3, list.getCapacity());
}
@Test
public void testOneElementRangeClosed() {
final LongList expected = LongList.of(1);
final LongList list = LongList.rangeClosed(1, 1);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(1, list.getCapacity());
}
@Test
public void testEmptyRangeClosed() {
final LongList expected = LongList.of();
final LongList list = LongList.rangeClosed(1, 0);
Assertions.assertArrayEquals(expected.toArray(), list.toArray());
Assertions.assertEquals(0, list.getCapacity());
}
@Test
public void testRangeClosedTooBig() {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
LongList.range(0, Integer.MAX_VALUE + 1L);
});
}
@Test
public void testAdd() {
// setting initial size to one, so that the first add does not need to resize,