Esempio n. 1
0
 @Test
 public void testRemove() {
   LNGVector<String> v1 = new LNGVector<>();
   Assert.assertTrue(v1.empty());
   for (int i = 0; i < 1000; i++) v1.push("s" + i);
   v1.remove("s500");
   Assert.assertEquals(999, v1.size());
   Assert.assertEquals("s499", v1.get(499));
   Assert.assertEquals("s501", v1.get(500));
   v1.remove("s0");
   Assert.assertEquals(998, v1.size());
   Assert.assertEquals("s1", v1.get(0));
   Assert.assertEquals("s499", v1.get(498));
   Assert.assertEquals("s501", v1.get(499));
   v1.remove("s999");
   Assert.assertEquals(997, v1.size());
   Assert.assertEquals("s1", v1.get(0));
   Assert.assertEquals("s499", v1.get(498));
   Assert.assertEquals("s501", v1.get(499));
   Assert.assertEquals("s998", v1.get(996));
   v1.remove("s1001");
   Assert.assertEquals(997, v1.size());
   Assert.assertEquals("s1", v1.get(0));
   Assert.assertEquals("s499", v1.get(498));
   Assert.assertEquals("s501", v1.get(499));
   Assert.assertEquals("s998", v1.get(996));
   LNGVector<String> v2 = new LNGVector<>("s1", "s1", "s2", "s5", "s8");
   v2.remove("s1");
   Assert.assertEquals(4, v2.size());
   Assert.assertEquals("[s1, s2, s5, s8]", v2.toString());
 }
Esempio n. 2
0
 @Test
 public void testInplaceReplace() {
   LNGVector<String> v1 = new LNGVector<>();
   for (int i = 0; i < 1000; i++) v1.push("s" + i);
   LNGVector<String> v2 = new LNGVector<>();
   for (int i = 0; i < 500; i++) v2.push("str" + i);
   LNGVector<String> v3 = new LNGVector<>();
   for (int i = 0; i < 2000; i++) v3.push("string" + i);
   v1.replaceInplace(v2);
   Assert.assertEquals(500, v1.size());
   for (int i = 0; i < 500; i++) Assert.assertEquals("str" + i, v1.get(i));
   v2.replaceInplace(v3);
   Assert.assertEquals(2000, v2.size());
   for (int i = 0; i < 2000; i++) Assert.assertEquals("string" + i, v2.get(i));
 }
Esempio n. 3
0
 @Test
 public void testRemoveElements() {
   LNGVector<String> v1 = new LNGVector<>();
   Assert.assertTrue(v1.empty());
   for (int i = 0; i < 1000; i++) v1.push("s" + i);
   Assert.assertFalse(v1.empty());
   for (int i = 0; i < 9; i++) {
     v1.removeElements(100);
     Assert.assertEquals(1000 - (i + 1) * 100, v1.size());
     Assert.assertEquals("s" + (1000 - (i + 1) * 100 - 1), v1.back());
   }
   Assert.assertEquals(100, v1.size());
   v1.removeElements(100);
   Assert.assertTrue(v1.empty());
 }
Esempio n. 4
0
 @Test
 public void testGrowToWithPad() {
   LNGVector<String> v1 = new LNGVector<>();
   Assert.assertTrue(v1.empty());
   for (int i = 0; i < 1000; i++) v1.push("s" + i);
   Assert.assertFalse(v1.empty());
   for (int i = 0; i < 1001; i += 10) {
     v1.growTo(1000 + i, "string");
     Assert.assertEquals(1000 + i, v1.size());
     for (int j = 0; j < 1000; j++) Assert.assertEquals("s" + j, v1.get(j));
     for (int j = 1000; j < 1000 + i; j++) Assert.assertEquals("string", v1.get(j));
   }
   Assert.assertEquals(2000, v1.size());
   v1.growTo(100, "string");
   Assert.assertEquals(2000, v1.size());
   for (int i = 0; i < 1000; i++) Assert.assertEquals("s" + i, v1.get(i));
   for (int i = 1000; i < 2000; i++) Assert.assertEquals("string", v1.get(i));
 }
Esempio n. 5
0
 @Test
 public void testGettinSettingAndPopping() {
   LNGVector<String> v1 = new LNGVector<>();
   for (int i = 0; i < 1000; i++) v1.push("s" + i);
   for (int i = 999; i >= 0; i--) {
     v1.set(i, "string");
     Assert.assertEquals("string", v1.get(i));
   }
   for (int i = 999; i >= 0; i--) {
     v1.pop();
     Assert.assertEquals(i, v1.size());
   }
 }
Esempio n. 6
0
 @Test
 public void testRelease() {
   LNGVector<String> v1 = new LNGVector<>();
   Assert.assertTrue(v1.empty());
   for (int i = 0; i < 1000; i++) {
     v1.push("s" + i);
     Assert.assertEquals(i + 1, v1.size());
     Assert.assertEquals("s" + i, v1.back());
     Assert.assertEquals("s" + i, v1.get(i));
   }
   Assert.assertFalse(v1.empty());
   v1.release();
   Assert.assertTrue(v1.empty());
 }
Esempio n. 7
0
 @Test
 public void legalUnsafePush() {
   LNGVector<String> v1 = new LNGVector<>(1000);
   Assert.assertTrue(v1.empty());
   for (int i = 0; i < 1000; i++) {
     v1.unsafePush("s" + i);
     Assert.assertEquals(i + 1, v1.size());
     Assert.assertEquals("s" + i, v1.back());
     Assert.assertEquals("s" + i, v1.get(i));
   }
   Assert.assertFalse(v1.empty());
   v1.clear();
   Assert.assertTrue(v1.empty());
 }
Esempio n. 8
0
 @Test
 public void testVectorCreation() {
   LNGVector<String> v1 = new LNGVector<>();
   Assert.assertEquals(0, v1.size());
   Assert.assertTrue(v1.empty());
   LNGVector<String> v2 = new LNGVector<>(10);
   Assert.assertEquals(0, v2.size());
   Assert.assertTrue(v2.empty());
   LNGVector<String> v3 = new LNGVector<>(10, "string");
   Assert.assertEquals(10, v3.size());
   for (int i = 0; i < v3.size(); i++) Assert.assertEquals("string", v3.get(i));
   Assert.assertFalse(v3.empty());
   LNGVector<String> v4 = new LNGVector<>("s1", "s2", "s3", "s4", "s5");
   Assert.assertEquals(5, v4.size());
   int count = 1;
   for (final String s : v4) Assert.assertEquals("s" + count++, s);
   List<String> list = new LinkedList<>();
   for (int i = 0; i < 1000; i++) list.add("s" + i);
   LNGVector<String> v5 = new LNGVector<>(list);
   Assert.assertEquals(1000, v5.size());
   for (int i = 0; i < 1000; i++) Assert.assertEquals("s" + i, v5.get(i));
 }