Title: Unit 5 - Developing Static Tests
Download Unit Project Files
public class BoxOfCrayonsCase {
[Test]
public function shouldHaveTwelveCrayons():void {}
[Test]
public function shouldHaveUniqueColors():void {}
}
public class CrayonCase {
[Test]
public function shouldBeWax():void {}
[Test]
public function shouldHaveColor():void {}
[Test]
public function shouldBeWrapped():void {}
}
public class WrapperCase {
[Test]
public function shouldHaveColorName():void {}
[Test]
public function shouldMatchWrappedCrayon():void {}
}
[Ignore] [Test] public function ignoreTest() :void
[Ignore]
[Test]
public function shouldGetBottomPointOnCircle():void {
...
}
[Ignore]
[Test]
public function shouldThrowRangeError():void {
}
[Ignore(description="Phase II Requirement",category="Required"]
[Test]
public function shouldGetPointsOnCircle():void
{
...
}
assertTrue( num1 > num2 && num1 < num3 );
"Expected <true> but was <false>."
public function assertThat( value, matcher );
assertTrue( num2 < num1 && num1 < num3);
assertThat( num1, is( between( num2, num3 ) ) );
"Expected a number between <num2> and <num3> but was <num1>."
"Expected <true> but was <false>."
[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( 0 );
assertEquals( 5, point.x );
assertEquals( 0, point.y );
}
[Test]
public function shouldGetBottomPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( Math.PI );
assertEquals( -5, point.x );
assertEquals( 0, point.y );
}
public class BasicCircleTest {
private static const TOLERANCE:Number = .0001;
...
}
assertEquals( 5, point.x );
assertThat( point.x, closeTo( 5, TOLERANCE ) );
import org.flexunit.assertThat;<br />import org.hamcrest.number.closeTo;
[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
point = circle.getPointOnCircle( 0 );
assertThat( point.x, closeTo( 5, TOLERANCE ) );
assertThat( point.y, closeTo( 0, TOLERANCE ) );
}
[Test]
public function shouldGetBottomPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
point = circle.getPointOnCircle( Math.PI );
assertThat( point.x, closeTo( -5, TOLERANCE ) );
assertThat( point.y, closeTo( 0, TOLERANCE ) );
}
[Test]
public function shouldGetRightPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
point = circle.getPointOnCircle( Math.PI/2 );
assertThat( point.x, closeTo( 0, TOLERANCE ) );
assertThat( point.y, closeTo( 5, TOLERANCE ) );
}
[Test]
public function shouldGetLeftPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point;
point = circle.getPointOnCircle( (3*Math.PI)/2 );
assertThat( point.x, closeTo( 0, TOLERANCE ) );
assertThat( point.y, closeTo( -5, TOLERANCE ) );
}
assertThat( point.x, closeTo( -5, TOLERANCE ) ); assertThat( point.y, closeTo( 0, TOLERANCE ) );
assertThat( point, closeToPoint( otherPoint, TOLERANCE ) );
private var point:Point; private var tolerance:Number;
public function CloseToPointMatcher( point:Point, tolerance:Number ) {
super(Point);
this.point = point;
this.tolerance = tolerance;
}
override public function matchesSafely(item:Object):Boolean {
}
override public function matchesSafely(item:Object):Boolean {
var distance:Number = Point.distance( item as Point, point );
}
override public function matchesSafely(item:Object):Boolean {
var distance:Number = Point.distance( item as Point, point );
return( Math.abs( distance ) - tolerance < 0 );
}
override public function describeTo(description:Description):void {
description.appendText( "point " ).appendText( point.toString() );
}
[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( 0 );
assertThat( point, new CloseToPointMatcher( new Point( 5, 0 ), TOLERANCE ) );
}
import matcher.CloseToPointMatcher;
[Test]
public function shouldGetTopPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( 0 );
assertThat( point, new CloseToPointMatcher( new Point( 5, 0 ), TOLERANCE ) );
}
[Test]
public function shouldGetBottomPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( Math.PI );
assertThat( point, new CloseToPointMatcher( new Point( -5, 0 ), TOLERANCE ) );
}
[Test]
public function shouldGetRightPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( Math.PI/2 );
assertThat( point, new CloseToPointMatcher( new Point( 0, 5 ), TOLERANCE ) );
}
[Test]
public function shouldGetLeftPointOnCircle():void {
var circle:Circle = new Circle( new Point( 0, 0 ), 5 );
var point:Point = circle.getPointOnCircle( (3*Math.PI)/2 );
assertThat( point, new CloseToPointMatcher( new Point( 0, -5 ), TOLERANCE ) );
}
[Test (expects="full.package.ThrownError")]
public function testError():void {}
[Test]
public function shouldThrowRangeError():void {
var someCircle:Circle = new Circle( new Point( 10, 10 ), -5 );
}
[Test(expects="RangeError")]
public function shouldThrowRangeError():void {
var someCircle:Circle = new Circle( new Point( 10, 10 ), -5 );
}