Esempio n. 1
0
 @Test
 public void testEmpty() {
   try {
     PackedArray a = packedArray();
     Element t = new Element();
     a.at(0, t);
     assertTrue(false);
   } catch (IndexOutOfBoundsException e) {
     // expected
   }
 }
Esempio n. 2
0
 @Test
 public void testNonEmpty() {
   final int N = 2000;
   PackedArray a = packedArray();
   for (int size = 1; size <= N; size++) {
     Element e = new Element(size);
     a.append(e);
   }
   for (int size = 1; size <= N; size++) {
     Element e = new Element();
     a.at(size - 1, e);
     assertEquals(size, e.size());
   }
 }
Esempio n. 3
0
 @Test
 public void testRandom() {
   final int N = 10000;
   Random random = new Random();
   for (int t = 0; t < 100; t++) {
     PackedArray a = packedArray();
     int[] sizes = new int[N];
     for (int i = 0; i < N; i++) {
       int size = 10 + random.nextInt(500);
       Element e = new Element(size);
       a.append(e);
       sizes[i] = size;
     }
     for (int i = 0; i < N; i++) {
       int size = sizes[i];
       Element e = new Element();
       a.at(i, e);
       assertEquals(size, e.size());
     }
   }
 }