Exemple #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);
  }
Exemple #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);
  }
Exemple #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);
  }
Exemple #4
0
  public void testSet() {
    Tuple input, output;

    input = new Tuple(0.0f, 1.0f);
    output = new Tuple(2.0f, 3.0f);
    output.set(input);
    assertEquals(0.0f, output.x);
    assertEquals(1.0f, output.y);

    output.set(2.5f, 3.5f);
    assertEquals(2.5f, output.x);
    assertEquals(3.5f, output.y);
  }
Exemple #5
0
  public void testStaticExtremes() {
    Tuple min, max, result;

    min = new Tuple(1.0f, 1.5f);
    max = new Tuple(2.0f, 2.5f);

    result = Tuple.min(min, max);
    assertTrue(result.equals(min));
    assertNotSame(result, min);
    assertNotSame(result, max);

    result = Tuple.max(min, max);
    assertTrue(result.equals(max));
    assertNotSame(result, min);
    assertNotSame(result, max);

    Tuple one = new Tuple(2.0f, 4.0f);
    Tuple two = new Tuple(1.0f, 5.0f);

    result = Tuple.min(one, two);
    assertEquals(1.0f, result.x);
    assertEquals(4.0f, result.y);
    assertNotSame(result, min);
    assertNotSame(result, max);

    result = Tuple.max(one, two);
    assertEquals(2.0f, result.x);
    assertEquals(5.0f, result.y);
    assertNotSame(result, min);
    assertNotSame(result, max);
  }
Exemple #6
0
  public void testComparison() {
    Tuple same1, same2, less, greater;

    same1 = new Tuple(0.0f, 1.0f);
    same2 = new Tuple(0.0f, 1.0f);
    less = new Tuple(-1.0f, 1.0f);
    greater = new Tuple(1.0f, 1.0f);
    assertTrue(same1.equals(same2));
    assertFalse(same1.equals(less));
    assertFalse(same1.equals(greater));

    assertTrue(same1.compareTo(same2) == 0);
    assertTrue(same1.compareTo(greater) < 0);
    assertTrue(same1.compareTo(less) > 0);
  }
Exemple #7
0
  public void testTupleExtremes() {
    Tuple min, max, result;

    min = new Tuple(1.0f, 1.5f);
    max = new Tuple(2.0f, 2.5f);
    result = new Tuple();

    result.set(min);
    result.min(max);
    assertTrue(result.equals(min));

    result.set(min);
    result.max(max);
    assertTrue(result.equals(max));

    result.set(max);
    result.min(min);
    assertTrue(result.equals(min));

    result.set(max);
    result.max(min);
    assertTrue(result.equals(max));

    Tuple one = new Tuple(2.0f, 4.0f);
    Tuple two = new Tuple(1.0f, 5.0f);

    result.set(one);
    result.min(two);
    assertEquals(1.0f, result.x);
    assertEquals(4.0f, result.y);

    result.set(one);
    result.max(two);
    assertEquals(2.0f, result.x);
    assertEquals(5.0f, result.y);
  }