Package edu.umd.cloud9.util.array

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


    assertEquals(c, c2);  
  }
 
  @Test
  public void testSubList() {
    ArrayListOfFloats a = new ArrayListOfFloats(new float[] {1, 2, 3, 4, 5, 6, 7});
    ArrayListOfFloats c = a.subList(1, 5);
    assertEquals(5, c.size());
    assertTrue(Math.abs(2 - c.get(0)) < 0.0001);
    assertTrue(Math.abs(3 - c.get(1)) < 0.0001);
    assertTrue(Math.abs(4 - c.get(2)) < 0.0001);
    assertTrue(Math.abs(5 - c.get(3)) < 0.0001);
    assertTrue(Math.abs(6 - c.get(4)) < 0.0001);
   
    a.clear();
    // Make sure b is a new object.
    assertEquals(5, c.size());
    assertTrue(Math.abs(2 - c.get(0)) < 0.0001);
    assertTrue(Math.abs(3 - c.get(1)) < 0.0001);
    assertTrue(Math.abs(4 - c.get(2)) < 0.0001);
    assertTrue(Math.abs(5 - c.get(3)) < 0.0001);
    assertTrue(Math.abs(6 - c.get(4)) < 0.0001);  
  }
View Full Code Here


    assertTrue(Math.abs(6 - c.get(4)) < 0.0001);  
  }

  @Test
  public void testAddUnique() {
    ArrayListOfFloats a = new ArrayListOfFloats(new float[] {1, 2, 3, 4, 5, 6, 7});
    a.addUnique(new int[] {8, 0, 2, 5, -1, 11, 9});
   
    assertEquals(12, a.size());
    assertTrue(Math.abs(0 - a.get(8)) < 0.0001);
    assertTrue(Math.abs(-1 - a.get(9)) < 0.0001);
    assertTrue(Math.abs(11 - a.get(10)) < 0.0001);
    assertTrue(Math.abs(9 - a.get(11)) < 0.0001);
  }
View Full Code Here

  @Test
  public void testShift() {
    int size = 100;
    int shift = 10;

    ArrayListOfFloats list = new ArrayListOfFloats();
    for (int i = 0; i < size; i++)
      list.add(i);
    list.shiftLastNToTop(shift);

    for (int i = 0; i < list.size(); i++) {
      assertTrue(Math.abs(size - shift + i - list.get(i)) < 0.001);
    }
    list.add(size);
    assertEquals(shift + 1, list.size());
    assertTrue(Math.abs(size - list.get(shift)) < 0.001);

  }
View Full Code Here

public class ArrayListOfFloatsTest {
  float 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(){
    ArrayListOfFloats a = new ArrayListOfFloats();
    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(){
    ArrayListOfFloats a = new ArrayListOfFloats();
    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(){
    ArrayListOfFloats a = new ArrayListOfFloats();
    a.add(neg_one);
    a.remove(-1);
  }
View Full Code Here

  public void testBasic1() {
    int size = 100000;
    Random r = new Random();
    float[] floats = new float[size];

    ArrayListOfFloats list = new ArrayListOfFloats();
    for (int i = 0; i < size; i++) {
      float k = r.nextFloat();
      list.add(k);
      floats[i] = k;
    }

    for (int i = 0; i < size; i++) {
      assertEquals(floats[i], list.get(i), 10e-5);
    }
  }
View Full Code Here

  @Test
  public void testArrayConstructor() {
    float[] arr = new float[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f };
    assertEquals(5, arr.length);

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

    // Make sure the original array remains untouched.
    assertEquals(1.0f, arr[0], 10e-6);
    assertEquals(2.0f, arr[1], 10e-6);
    assertEquals(3.0f, arr[2], 10e-6);
View Full Code Here

    assertEquals(5.0f, arr[4], 10e-6);
  }

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

    list.remove(list.indexOf(5.0f));
    assertEquals(9, list.size());
    assertEquals(0.0f, list.get(0), 10e-6);
    assertEquals(1.0f, list.get(1), 10e-6);
    assertEquals(2.0f, list.get(2), 10e-6);
    assertEquals(3.0f, list.get(3), 10e-6);
    assertEquals(4.0f, list.get(4), 10e-6);
    assertEquals(6.0f, list.get(5), 10e-6);
    assertEquals(7.0f, list.get(6), 10e-6);
    assertEquals(8.0f, list.get(7), 10e-6);
    assertEquals(9.0f, list.get(8), 10e-6);

    list.remove(list.indexOf((short) 9));
    assertEquals(8, list.size);
    assertEquals(0.0f, list.get(0), 10e-6);
    assertEquals(1.0f, list.get(1), 10e-6);
    assertEquals(2.0f, list.get(2), 10e-6);
    assertEquals(3.0f, list.get(3), 10e-6);
    assertEquals(4.0f, list.get(4), 10e-6);
    assertEquals(6.0f, list.get(5), 10e-6);
    assertEquals(7.0f, list.get(6), 10e-6);
    assertEquals(8.0f, list.get(7), 10e-6);
  }
View Full Code Here

  public void testUpdate() {
    int size = 100000;
    Random r = new Random();
    float[] floats = new float[size];

    ArrayListOfFloats list = new ArrayListOfFloats();
    for (int i = 0; i < size; i++) {
      float k = r.nextFloat();
      list.add(k);
      floats[i] = k;
    }

    assertEquals(size, list.size());

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

    assertEquals(size, list.size());

    for (int i = 0; i < size; i++) {
      assertEquals(floats[i] + 1, list.get(i), 10e-5);
    }

  }
View Full Code Here

TOP

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

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.