Пример #1
0
  public void testStaticOps() {
    Tuple source1, source2, result;

    source1 = new Tuple(1.0f, 2.0f);
    source2 = new Tuple(2.0f, 4.0f);

    result = Tuple.plus(source1, source2);
    assertEquals(3.0f, result.x);
    assertEquals(6.0f, result.y);
    assertNotSame(result, source1);
    assertNotSame(result, source2);

    result = Tuple.minus(source1, source2);
    assertEquals(-1.0f, result.x);
    assertEquals(-2.0f, result.y);
    assertNotSame(result, source1);
    assertNotSame(result, source2);

    result = Tuple.multiply(source1, source2);
    assertEquals(2.0f, result.x);
    assertEquals(8.0f, result.y);
    assertNotSame(result, source1);
    assertNotSame(result, source2);

    result = Tuple.divide(source1, source2);
    assertEquals(0.5f, result.x);
    assertEquals(0.5f, result.y);
    assertNotSame(result, source1);
    assertNotSame(result, source2);
  }
Пример #2
0
  public void testTupleOps() {
    Tuple source1, source2, result;

    source1 = new Tuple(1.0f, 2.0f);
    source2 = new Tuple(2.0f, 4.0f);
    result = new Tuple();

    result.set(source1);
    result.plus(source2);
    assertEquals(3.0f, result.x);
    assertEquals(6.0f, result.y);

    result.set(source1);
    result.minus(source2);
    assertEquals(-1.0f, result.x);
    assertEquals(-2.0f, result.y);

    result.set(source1);
    result.multiply(source2);
    assertEquals(2.0f, result.x);
    assertEquals(8.0f, result.y);

    result.set(source1);
    result.divide(source2);
    assertEquals(0.5f, result.x);
    assertEquals(0.5f, result.y);
  }
Пример #3
0
  public void testScalarOps() {
    Tuple source1, result;

    source1 = new Tuple(1.0f, 2.0f);
    result = new Tuple();

    result.set(source1);
    result.plus(2.0f);
    assertEquals(3.0f, result.x);
    assertEquals(4.0f, result.y);

    result.set(source1);
    result.minus(2.0f);
    assertEquals(-1.0f, result.x);
    assertEquals(0.0f, result.y);

    result.set(source1);
    result.multiply(2.0f);
    assertEquals(2.0f, result.x);
    assertEquals(4.0f, result.y);

    result.set(source1);
    result.divide(2.0f);
    assertEquals(0.5f, result.x);
    assertEquals(1.0f, result.y);
  }