예제 #1
0
 /** Test of deleteElement method, of class Vector. */
 @Test
 public void testDeleteElement() {
   System.out.println("deleteElement");
   // Arrange
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] mass1 = {5.0, -2.9, 0.0, -50000};
   double[] mass2 = {5.0, -2.9, -50000, 9};
   double[] mass3 = {-2.9, 0.0, -50000, 9};
   int index1 = 4;
   int index2 = 2;
   int index3 = 0;
   VectorImpl instance1 = new VectorImpl(5);
   instance1.setData(mass);
   VectorImpl instance2 = new VectorImpl(5);
   instance2.setData(mass);
   VectorImpl instance3 = new VectorImpl(5);
   instance3.setData(mass);
   // Act
   instance1.deleteElement(index1);
   instance2.deleteElement(index2);
   instance3.deleteElement(index3);
   // Assert
   assertArrayEquals(mass1, instance1.getData(), 0.0);
   assertArrayEquals(mass2, instance2.getData(), 0.0);
   assertArrayEquals(mass3, instance3.getData(), 0.0);
 }
예제 #2
0
  /** Test of equals method, of class Vector. */
  @Test
  public void testEquals() {
    System.out.println("equal");
    // Arrange
    double[] original = {5.0, -2.9, 0.0, -50000, 9};
    double[] originalCopy = {5.0, -2.9, 0.0, -50000, 9};
    double[] mass1 = {0.0, 0.9, -6.4, 8, -0.4};
    double[] mass2 = {5.0, -2.9};
    double[] mass3 = {5.0, -2.9, 0.0, -50000, 9, 5.0, -2.9};

    VectorImpl instance = new VectorImpl(5);
    instance.setData(original);
    VectorImpl vector0 = new VectorImpl(5);
    vector0.setData(originalCopy);
    VectorImpl vector1 = new VectorImpl(5);
    vector1.setData(mass1);
    VectorImpl vector2 = new VectorImpl(2);
    vector2.setData(mass2);
    VectorImpl vector3 = new VectorImpl(7);
    vector3.setData(mass3);
    java.util.Vector vector4 = new java.util.Vector(5);
    // Act
    boolean result0 = instance.equals(vector0);
    boolean result1 = instance.equals(vector1);
    boolean result2 = instance.equals(vector2);
    boolean result3 = instance.equals(vector3);
    boolean result4 = instance.equals(vector4);
    // Assert
    assertTrue(result0);
    assertFalse(result1);
    assertFalse(result2);
    assertFalse(result3);
    assertFalse(result4);
  }
예제 #3
0
 /** Test of insertElement method, of class Vector. */
 @Test
 public void testInsertElement() {
   System.out.println("insertElement");
   // Arrange
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] mass1 = {5.0, -2.9, 0.0, -50000, 9, 7.7};
   double[] mass2 = {5.0, -2.9, 7.7, 0.0, -50000, 9};
   double[] mass3 = {7.7, 5.0, -2.9, 0.0, -50000, 9};
   double element = 7.7;
   int index1 = 5;
   int index2 = 2;
   int index3 = 0;
   VectorImpl instance1 = new VectorImpl(5);
   instance1.setData(mass);
   VectorImpl instance2 = new VectorImpl(5);
   instance2.setData(mass);
   VectorImpl instance3 = new VectorImpl(5);
   instance3.setData(mass);
   // Act
   instance1.insertElement(index1, element);
   instance2.insertElement(index2, element);
   instance3.insertElement(index3, element);
   // Assert
   assertArrayEquals(mass1, instance1.getData(), 0.0);
   assertArrayEquals(mass2, instance2.getData(), 0.0);
   assertArrayEquals(mass3, instance3.getData(), 0.0);
 }
예제 #4
0
 @Test(expected = IncompatibleVectorSizesException.class)
 public void testSumException2() throws IncompatibleVectorSizesException {
   System.out.println("sumException (vector sizes < new vector sizes)");
   // Arrange
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] newMass = {1.1, 0.9, -6.4, 100, -9.4, 99};
   VectorImpl instance = new VectorImpl(5);
   instance.setData(mass);
   VectorImpl vector = new VectorImpl(6);
   vector.setData(newMass);
   // Act
   instance.sum(vector);
   // Assert
 }
예제 #5
0
 /** Test of clone method, of class Vector. */
 @Test
 public void testClone() throws Exception {
   System.out.println("clone");
   // Arrange
   double[] original = {5.0, -2.9, 0.0, -50000, 9};
   VectorImpl instance = new VectorImpl(5);
   instance.setData(original);
   // Act
   Object result1 = instance.clone();
   Object result2 = instance.clone();
   ((VectorImpl) result2).setData(new double[0]);
   // Assert
   assertNotNull(result1);
   assertTrue(instance.getClass() == result1.getClass());
   assertArrayEquals(original, ((VectorImpl) result1).getData(), 0.0);
 }
예제 #6
0
 /** Test of sum method, of class Vector. */
 @Test
 public void testSum() {
   System.out.println("sum");
   // Arrange
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] newMass = {1.1, 0.9, -6.4, 100, -9.4};
   double[] resultMass = {6.1, -2.0, -6.4, -49900, -0.4};
   VectorImpl instance = new VectorImpl(5);
   instance.setData(mass);
   VectorImpl vector = new VectorImpl(5);
   vector.setData(newMass);
   // Act
   try {
     instance.sum(vector);
   } catch (IncompatibleVectorSizesException e) {
     e.printStackTrace();
   }
   // Assert
   assertArrayEquals(resultMass, instance.getData(), 0.00000000001);
 }
예제 #7
0
 /** Test of fillFromVector method, of class Vector. */
 @Test
 public void testFillFromVector() {
   System.out.println("fillFromVector");
   // Arrange
   double[] mass0 = {0.0, 0.9, -6.4, 8, -0.4};
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] mass2 = {5.0, -2.9, 0.0};
   double[] mass3 = {5.0, -2.9, 0.0, -50000, 9, 0.6};
   VectorImpl instance = new VectorImpl(5);
   instance.setData(mass0);
   VectorImpl vector = new VectorImpl(5);
   vector.setData(mass);
   VectorImpl instance2 = new VectorImpl(5);
   instance2.setData(mass0);
   VectorImpl vector2 = new VectorImpl(3);
   vector2.setData(mass2);
   VectorImpl instance3 = new VectorImpl(5);
   instance3.setData(mass0);
   VectorImpl vector3 = new VectorImpl(6);
   vector3.setData(mass3);
   // Act
   instance.fillFromVector(vector);
   instance2.fillFromVector(vector2);
   instance3.fillFromVector(vector3);
   // Assert
   assertArrayEquals(mass, instance.getData(), 0.0);
   assertArrayEquals(mass2, instance2.getData(), 0.0);
   assertArrayEquals(mass3, instance3.getData(), 0.0);
 }
예제 #8
0
  @Test(expected = VectorIndexOutOfBoundsException.class)
  public void testDeleteElementException2() {
    System.out.println("insertDeleteException (index > size");
    // Arrange
    double[] mass = {5.0, -2.9, 0.0, -50000, 9};
    int index1 = 10;
    VectorImpl instance1 = new VectorImpl(5);
    instance1.setData(mass);
    // Act
    instance1.deleteElement(index1);
    // Assert

  }
예제 #9
0
  @Test(expected = VectorIndexOutOfBoundsException.class)
  public void testInsertElementException1() {
    System.out.println("insertElementException (index < 0)");
    // Arrange
    double[] mass = {5.0, -2.9, 0.0, -50000, 9};
    double element = 7.7;
    int index1 = -5;
    VectorImpl instance1 = new VectorImpl(5);
    instance1.setData(mass);
    // Act
    instance1.insertElement(index1, element);
    // Assert

  }
예제 #10
0
 /** Test of addElement method, of class Vector. */
 @Test
 public void testAddElement() {
   System.out.println("addElement");
   // Arrange
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] newMass = {5.0, -2.9, 0.0, -50000, 9, 7.7};
   double element = 7.7;
   VectorImpl instance = new VectorImpl(5);
   instance.setData(mass);
   // Act
   instance.addElement(element);
   // Assert
   assertArrayEquals(newMass, instance.getData(), 0.0);
 }
예제 #11
0
 /** Test of mult method, of class Vector. */
 @Test
 public void testMult() {
   System.out.println("mult");
   // Arrange
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   double[] resultMass = {10.0, -5.8, 0.0, -100000, 18};
   VectorImpl instance = new VectorImpl(5);
   instance.setData(mass);
   double number = 2;
   // Act
   instance.mult(number);
   // Assert
   assertArrayEquals(resultMass, instance.getData(), 0.00000000001);
 }
예제 #12
0
 /** Test of getElement method, of class Vector. */
 @Test
 public void testGetElement() {
   System.out.println("getElement");
   // Arrange
   int index = 3;
   VectorImpl instance = new VectorImpl(5);
   double expResult = 0.7;
   double[] buff = instance.getData();
   buff[index] = expResult;
   instance.setData(buff);
   // Act
   double result = instance.getElement(index);
   // Assert
   assertEquals(expResult, result, 0.0);
 }
예제 #13
0
 /** Test of toString method, of class Vector. */
 @Test
 public void testToString() {
   System.out.println("toString");
   // Arrange
   double[] mass = {5.0, -2.9, 0.0, -50000, 9};
   VectorImpl instance = new VectorImpl(5);
   instance.setData(mass);
   String expResult = "5.0 -2.9 0.0 -50000.0 9.0";
   // Act
   String result = instance.toString();
   // Assert
   System.out.println(expResult);
   System.out.println(result);
   assertEquals(expResult, result);
 }