Package edu.umd.cloud9.util.array

Examples of edu.umd.cloud9.util.array.ArrayListOfShorts


public class ArrayListOfShortsTest {
  short neg_one=-1, zero=0, one=1, two=2, three=3, four=4, five=5, six=6, seven=7, nine=9;

  @Test
  public void testRemoveWithinBounds(){
    ArrayListOfShorts a = new ArrayListOfShorts();
    a.add(one).add(three).add(five).add(seven);
   
    assertTrue(one == a.remove(0));

    assertTrue(three == a.get(0));
    assertTrue(five == a.get(1));
   
    assertTrue(five == a.remove(1));
    assertTrue(seven == a.get(2));
  }
View Full Code Here


    assertTrue(seven == a.get(2));
  }
 
  @Test (expected=ArrayIndexOutOfBoundsException.class)
  public void testRemoveOutOfBounds(){
    ArrayListOfShorts a = new ArrayListOfShorts();
    a.add(one).add(three).add(five).add(seven);

    a.remove(4);
  }
View Full Code Here

    a.remove(4);
  }

  @Test (expected=ArrayIndexOutOfBoundsException.class)
  public void testRemoveOutOfBounds2(){
    ArrayListOfShorts a = new ArrayListOfShorts();
    a.add(neg_one);
    a.remove(-1);
  }
View Full Code Here

  public void testBasic1() {
    int size = 10000;
    Random r = new Random();
    short[] shorts = new short[size];

    ArrayListOfShorts list = new ArrayListOfShorts();
    for (int i = 0; i < size; i++) {
      short k = (short) r.nextInt(size);
      list.add(k);
      shorts[i] = k;
    }

    for (int i = 0; i < size; i++) {
      int v = list.get(i);

      assertEquals(shorts[i], v);
    }
  }
View Full Code Here

  @Test
  public void testArrayConstructor() {
    short[] arr = new short[] { 1, 2, 3, 4, 5 };
    assertEquals(5, arr.length);

    ArrayListOfShorts list = new ArrayListOfShorts(arr);
    list.remove(2);

    // Make sure the original array remains untouched.
    assertEquals(1, arr[0]);
    assertEquals(2, arr[1]);
    assertEquals(3, arr[2]);
View Full Code Here

    assertEquals(5, arr[4]);
  }

  @Test
  public void testRemove() {
    ArrayListOfShorts list = new ArrayListOfShorts();
    for ( int i=0; i<10; i++) {
      list.add((short) i);
    }

    list.remove(list.indexOf((short) 5));
    assertEquals(9, list.size());
    assertEquals(0, list.get(0));
    assertEquals(1, list.get(1));
    assertEquals(2, list.get(2));
    assertEquals(3, list.get(3));
    assertEquals(4, list.get(4));
    assertEquals(6, list.get(5));
    assertEquals(7, list.get(6));
    assertEquals(8, list.get(7));
    assertEquals(9, list.get(8));

    list.remove(list.indexOf((short) 9));
    assertEquals(8, list.size);
    assertEquals(0, list.get(0));
    assertEquals(1, list.get(1));
    assertEquals(2, list.get(2));
    assertEquals(3, list.get(3));
    assertEquals(4, list.get(4));
    assertEquals(6, list.get(5));
    assertEquals(7, list.get(6));
    assertEquals(8, list.get(7));
  }
View Full Code Here

  public void testUpdate() {
    int size = 10000;
    Random r = new Random();
    short[] shorts = new short[size];

    ArrayListOfShorts list = new ArrayListOfShorts();
    for (int i = 0; i < size; i++) {
      short k = (short) r.nextInt(size);
      list.add(k);
      shorts[i] = k;
    }

    assertEquals(size, list.size());

    for (int i = 0; i < size; i++) {
      list.set(i, (short) (shorts[i] + 1));
    }

    assertEquals(size, list.size());

    for (int i = 0; i < size; i++) {
      int v = list.get(i);

      assertEquals(shorts[i] + 1, v);
    }

  }
View Full Code Here

  public void testTrim1() {
    int size = 89;
    Random r = new Random();
    short[] shorts = new short[size];

    ArrayListOfShorts list = new ArrayListOfShorts();
    for (int i = 0; i < size; i++) {
      short k = (short) r.nextInt(size);
      list.add(k);
      shorts[i] = k;
    }

    for (int i = 0; i < size; i++) {
      int v = list.get(i);

      assertEquals(shorts[i], v);
    }

    short[] rawArray = list.getArray();
    int lenBefore = rawArray.length;

    list.trimToSize();
    short[] rawArrayAfter = list.getArray();
    int lenAfter = rawArrayAfter.length;

    assertEquals(89, lenAfter);
    assertTrue(lenBefore > lenAfter);
  }
View Full Code Here

  public void testClone() {
    int size = 10000;
    Random r = new Random();
    int[] shorts = new int[size];

    ArrayListOfShorts list1 = new ArrayListOfShorts();
    for (int i = 0; i < size; i++) {
      short k = (short) r.nextInt(size);
      list1.add(k);
      shorts[i] = k;
    }

    ArrayListOfShorts list2 = list1.clone();

    assertEquals(size, list1.size());
    assertEquals(size, list2.size());

    for (int i = 0; i < size; i++) {
      list2.set(i, (short) (shorts[i] + 1));
    }

    // values in old list should not have changed
    assertEquals(size, list1.size());
    for (int i = 0; i < size; i++) {
      assertEquals(shorts[i], list1.get(i));
    }

    // however, values in new list should have changed
    assertEquals(size, list1.size());
    for (int i = 0; i < size; i++) {
      assertEquals(shorts[i] + 1, list2.get(i));
    }
  }
View Full Code Here

  }

  @Test
  public void testToString1() {
    assertEquals("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]",
        new ArrayListOfShorts((short) 1, (short) 11).toString());
    assertEquals("[1, 2, 3, 4, 5 ... (5 more) ]",
        new ArrayListOfShorts((short) 1, (short) 11).toString(5));

    assertEquals("[1, 2, 3, 4, 5]",
        new ArrayListOfShorts((short) 1, (short) 6).toString());
    assertEquals("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]",
        new ArrayListOfShorts((short) 1, (short) 12).toString(11));

    assertEquals("[]", new ArrayListOfShorts().toString());
  }
View Full Code Here

TOP

Related Classes of edu.umd.cloud9.util.array.ArrayListOfShorts

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.