Ranides Atterwim 10 rokov pred
rodič
commit
c42a432892

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 507 - 511
assira/src/main/java/net/ranides/assira/collection/lists/IntArrayList.java


+ 83 - 59
assira/src/test/java/net/ranides/assira/collection/lists/IntArrayListTest.java

@@ -1,59 +1,83 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/???
- */
-package net.ranides.assira.collection.lists;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import net.ranides.assira.collection.mockup.CollectionSuite;
-import net.ranides.assira.collection.mockup.TMaps;
-import static net.ranides.assira.junit.NewAssert.*;
-import net.ranides.assira.test.TCollection;
-import org.junit.Test;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public class IntArrayListTest {
-    
-    private final TCollection<Integer> $list = TMaps.MAP_IS.keys();
-
-    @Test
-    public void testSuite() {
-        CollectionSuite.SUITE
-			.param("set!", $list)
-			.param("list!", $list)
-			.run(() -> new IntArrayList());
-    }
-
-    @Test
-    public void testConstruct() {
-        assertNotNull(new IntArrayList(32));
-        assertThrows(IllegalArgumentException.class, ()->{new IntArrayList(-1);});
-    }
-    
-    @Test
-    public void testConstructCopy() {
-        IntRange r = new IntRange(0, 10);
-        List<Integer> exp = Arrays.asList(0,1,2,3,4,5,6,7,8,9);
-        
-        assertEquals(10, new IntArrayList(r).size());
-        assertEquals(exp, new IntArrayList(r));
-        assertEquals(exp, new IntArrayList(new IntArrayList(r)));
-        assertEquals(new IntArrayList(r), new IntArrayList(new IntArrayList(r)));
-        assertEquals(Arrays.asList(1,2,3,8), new IntArrayList(new int[]{1,2,3,8}));
-        assertEquals(Arrays.asList(2,3,8), new IntArrayList(new int[]{1,2,3,8,10,11},1,3));
-        
-        assertEquals(exp, new IntArrayList(r.iterator()));
-        assertEquals(exp, new IntArrayList(new ArrayList<>(r).iterator()));
-        
-//        assertNotNull(new IntArrayList(32));
-//        assertThrows(IllegalArgumentException.class, ()->{new IntArrayList(-1);});
-    }
-    
-}
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/???
+ */
+package net.ranides.assira.collection.lists;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import net.ranides.assira.collection.mockup.CollectionSuite;
+import net.ranides.assira.collection.mockup.TMaps;
+import net.ranides.assira.collection.sets.IntAVLTreeSet;
+import net.ranides.assira.collection.sets.IntSet;
+import static net.ranides.assira.junit.NewAssert.*;
+import net.ranides.assira.test.TCollection;
+import org.junit.Test;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public class IntArrayListTest {
+    
+    private final TCollection<Integer> $list = TMaps.MAP_IS.keys();
+
+    @Test
+    public void testSuite() {
+        CollectionSuite.SUITE
+			.param("set!", $list)
+			.param("list!", $list)
+			.run(() -> new IntArrayList());
+    }
+
+    @Test
+    public void testConstruct() {
+        assertNotNull(new IntArrayList(32));
+        assertThrows(IllegalArgumentException.class, ()->{new IntArrayList(-1);});
+    }
+    
+    @Test
+    public void testConstructCopy() {
+        IntRange r = new IntRange(0, 10);
+        List<Integer> exp = Arrays.asList(0,1,2,3,4,5,6,7,8,9);
+        
+        assertEquals(10, new IntArrayList(r).size());
+        assertEquals(exp, new IntArrayList(r));
+        assertEquals(exp, new IntArrayList(new IntArrayList(r)));
+        assertEquals(new IntArrayList(r), new IntArrayList(new IntArrayList(r)));
+        assertEquals(Arrays.asList(1,2,3,8), new IntArrayList(new int[]{1,2,3,8}));
+        assertEquals(Arrays.asList(2,3,8), new IntArrayList(new int[]{1,2,3,8,10,11},1,3));
+        
+        assertEquals(exp, new IntArrayList(r.iterator()));
+        assertEquals(exp, new IntArrayList(new ArrayList<>(r).iterator()));
+        
+        assertNotNull(new IntArrayList(32));
+        assertThrows(IllegalArgumentException.class, ()->{new IntArrayList(-1);});
+		
+		IntSet set = new IntAVLTreeSet(new int[]{1,3,5,7});
+		assertEquals(Arrays.asList(1,3,5,7), new IntArrayList(set));
+    }
+	
+	@Test
+    public void testWrap() {
+		int[] array = new int[]{1,3,5,7};
+		IntList list = IntArrayList.wrap(array);
+		assertEquals(Arrays.asList(1,3,5,7), list);
+	}
+	
+	@Test
+    public void testWrap_size() {
+		int[] array = new int[]{1,3,5,7,9};
+		IntList list = IntArrayList.wrap(array, 4);
+		assertEquals(Arrays.asList(1,3,5,7), list);
+		
+		assertThrows(IllegalArgumentException.class, ()->{
+			IntArrayList.wrap(array, 9);
+		});
+	}
+	
+    
+}

+ 148 - 35
assira/src/test/java/net/ranides/assira/collection/suite/lists/ListTester.java

@@ -1,35 +1,148 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/???
- */
-package net.ranides.assira.collection.suite.lists;
-
-import java.util.List;
-import javax.annotation.Resource;
-import net.ranides.assira.junit.InterfaceTest;
-import net.ranides.assira.test.TCollection;
-import static net.ranides.assira.junit.NewAssert.*;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public class ListTester<T> {
-    
-    @Resource(name = "list!")
-    private TCollection<T> $list;
-    
-    @InterfaceTest
-    public void basicAdd(List<T> target) {
-        assertEquals(0, target.size());
-        
-        for(TCollection.TItem<T> item : $list.range(32)) {
-            target.add(item.value());
-        }
-        
-        assertEquals(32, target.size());
-        assertEquals($list.item(4).value(), target.get(4));
-    }
-}
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/???
+ */
+package net.ranides.assira.collection.suite.lists;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Resource;
+import net.ranides.assira.junit.InterfaceTest;
+import net.ranides.assira.test.TCollection;
+import static net.ranides.assira.junit.NewAssert.*;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public class ListTester<T> {
+    
+    @Resource(name = "list!")
+    private TCollection<T> $list;
+    
+    @InterfaceTest
+    public void basicAdd(List<T> target) {
+        assertEquals(0, target.size());
+        
+        for(TCollection.TItem<T> item : $list.range(32)) {
+            target.add(item.value());
+        }
+        
+        assertEquals(32, target.size());
+        assertEquals($list.item(4).value(), target.get(4));
+		assertEquals($list.range(32).into(new ArrayList<>()), target);
+    }
+	
+	@InterfaceTest
+    public void basicAddAt(List<T> target) {
+		assertEquals(0, target.size());
+		$list.range(8).into(target);
+		target.add(0, $list.item(71).value());
+		target.add(0, $list.item(72).value());
+		target.add(4, $list.item(73).value());
+		target.add(6, $list.item(74).value());
+		target.add(11, $list.item(75).value());
+		target.add(13, $list.item(76).value());
+
+		assertEquals( $list.list(72, 71, 0, 1, 73, 2, 74, 3, 4, 5, 6, 75, 7, 76).into(new ArrayList<>()), target);
+	}
+	
+	@InterfaceTest
+    public void basicAddAll(List<T> target) {
+        assertEquals(0, target.size());
+        
+		target.addAll($list.range(0,8).into(new ArrayList<>()));
+		target.addAll(4, $list.range(10,18).into(new ArrayList<>()));
+        
+        assertEquals(16, target.size());
+        assertEquals($list.list(0,1,2,3,10,11,12,13,14,15,16,17,4,5,6,7).into(new ArrayList<>()), target);
+    }
+	
+	@InterfaceTest
+    public void basicSet(List<T> target) {
+		$list.range(8).into(target);
+		target.set(0, $list.item(21).value());
+		target.set(2, $list.item(22).value());
+		target.set(7, $list.item(23).value());
+
+		assertThrows(IndexOutOfBoundsException.class, ()->{
+			target.set(8, $list.item(26).value());
+		});
+		assertThrows(IndexOutOfBoundsException.class, ()->{
+			target.set(-1, $list.item(27).value());
+		});
+		assertEquals( $list.list(21,1,22,3,4,5,6,23).into(new ArrayList<>()), target);
+	}
+	
+	@InterfaceTest
+    public void basicIndexOf(List<T> target) {
+		$list.list(1,3,5,7,9,3,3,11).into(target);
+		
+		assertEquals(0, target.indexOf(1));
+		assertEquals(1, target.indexOf(3));
+		assertEquals(2, target.indexOf(5));
+		assertEquals(3, target.indexOf(7));
+		assertEquals(4, target.indexOf(9));
+		assertEquals(7, target.indexOf(11));
+		assertEquals(-1, target.indexOf(0));
+	}
+	
+	@InterfaceTest
+    public void basicLastIndexOf(List<T> target) {
+		$list.list(1,3,5,7,9,3,3,11).into(target);
+		
+		assertEquals(0, target.lastIndexOf(1));
+		assertEquals(6, target.lastIndexOf(3));
+		assertEquals(2, target.lastIndexOf(5));
+		assertEquals(3, target.lastIndexOf(7));
+		assertEquals(4, target.lastIndexOf(9));
+		assertEquals(7, target.lastIndexOf(11));
+		assertEquals(-1, target.lastIndexOf(0));
+	}
+	
+	@InterfaceTest
+    public void basicRemove(List<T> target) {
+		$list.list(1,3,5,7,9,11).into(target);
+		
+		assertTrue(target.remove( $list.item(5).value()));
+		assertEquals( $list.list(1,3,7,9,11).into(new ArrayList<>()), target);
+		
+		assertTrue(target.remove( $list.item(1).value()));
+		assertEquals( $list.list(3,7,9,11).into(new ArrayList<>()), target);
+		
+		assertTrue(target.remove( $list.item(11).value()));
+		assertEquals( $list.list(3,7,9).into(new ArrayList<>()), target);
+		
+		assertFalse(target.remove( $list.item(0).value()));
+		assertEquals( $list.list(3,7,9).into(new ArrayList<>()), target);
+	}
+	
+	@InterfaceTest
+    public void basicRemoveIndex(List<T> target) {
+		$list.list(1,3,5,7,9,11).into(target);
+		
+		assertEquals($list.item(5).value(), target.remove(2));
+		assertEquals( $list.list(1,3,7,9,11).into(new ArrayList<>()), target);
+		
+		assertEquals($list.item(1).value(), target.remove(0));
+		assertEquals( $list.list(3,7,9,11).into(new ArrayList<>()), target);
+		
+		assertEquals($list.item(11).value(), target.remove(3));
+		assertEquals( $list.list(3,7,9).into(new ArrayList<>()), target);
+		
+		assertThrows(IndexOutOfBoundsException.class, ()->{
+			target.remove(20);
+		});
+		assertThrows(IndexOutOfBoundsException.class, ()->{
+			target.remove(-1);
+		});
+		assertEquals( $list.list(3,7,9).into(new ArrayList<>()), target);
+		
+		target.clear();
+		assertThrows(IndexOutOfBoundsException.class, ()->{
+			target.remove(0);
+		});
+	}
+}