Package purrpackagedemo

Source Code of purrpackagedemo.TestTransformation

package purrpackagedemo;

import junit.framework.TestCase;

import org.junit.Test;

import purrpackagedemo.Point;
import purrpackagedemo.Region;
import purrpackagedemo.Transformation.Expansion;
import purrpackagedemo.Transformation.Rotation;
import purrpackagedemo.Transformation.Translation;
import purrpackagedemo.round.Circle;

public class TestTransformation extends TestCase {

  void assertPointEquals( Point a, Point b ) {
    assertEquals( a +"," + b, a.x, b.x, .000001 );
    assertEquals( a + "," + b, a.y, b.y, .000001 );
  }
 
  @Test
  public void testTransformationsOnPoints() {
    Translation t = new Translation( 3, -2.5 );
    assertPointEquals( new Point( 3, -2.5 ), t.apply( Point.ORIGIN ));
    assertPointEquals( new Point( 4, -1.5 ), t.apply( new Point( 1, 1 ) ) );
   
    Rotation r = new Rotation( Math.PI / 2.0 );
    assertPointEquals( new Point( 0, 1 ), r.apply( new Point( 1, 0 )) );
    assertPointEquals( new Point( -2, 0 ), r.apply( r.apply( new Point( 2, 0 ))) );
   
    Expansion z = new Expansion( -2 );
    assertPointEquals( new Point( 14, -16 ), z.apply( new Point( -7, 8 )) );
  }

  @Test
  public void testTransformationsOnRegions() {
    Point[] ps = new Point[] { Point.ORIGIN, new Point( 0.5, -0.5 ), new Point( 1, 1 ) };
    Transformation[] ts = new Transformation[] { new Transformation.Expansion( 2.0 ),
        new Transformation.Rotation( 1 ), new Translation( 7, -8 ) };
    for( Transformation t : ts ) {
      Region tr = t.apply( Circle.UNIT );
      for ( Point p : ps ) {
        assertEquals( Circle.UNIT.contains( p ), tr.contains( t.apply( p )) );
      }
    }
   
   
  }

 
}
TOP

Related Classes of purrpackagedemo.TestTransformation

TOP
Copyright © 2018 www.massapi.com. 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.