beforeEach() { //Called before each test for test setup (if needed) //Construct a unit model for testing (we use ivar "unit") super.beforeEach(); this.unit = new Rectangle(); }
getUnitName() { //Return class name of unit return 'Rectangle'; }
testGetWidth() { this.assertEquals(0, this.unit.getWidth()); }
testGetHeight() { this.assertEquals(0, this.unit.getHeight()); }
testGetArea() { this.assertEquals(0, this.unit.getArea()); }
testGetPerimeter() { this.assertEquals(0, this.unit.getPerimeter()); }
testGetDiagonal() { this.assertFloatEquals(0, this.unit.getDiagonal(), 0.0001); }
testFlip() { const rec = this.unit; rec.flip(); this.assertEquals(0, this.unit.getWidth()); this.assertEquals(0, this.unit.getHeight()); }
testMultiply() { const rec = this.unit; rec.multiply(2); this.assertEquals(0 * 2, this.unit.getWidth()); this.assertEquals(0 * 2, this.unit.getHeight()); }
/* RectangleEdgeTestCase Similar to RectangleTestCase in format. The only change is we construct a model unit (testee) with "edge case" condtions (use constructor with no params to make sure Rectangle is constructed and operates properly for this case. */ //========================================================= //Housekeeping statement (add name of test class) //Note: param must be a string addTestCase("RectangleEdgeTestCase"); //========================================================= class RectangleEdgeTestCase extends TestCase { //ivars: unit //----------------- //Unit Test Support getUnitName() { //Return class name of unit return 'Rectangle'; } beforeEach() { //Called before each test for test setup (if needed) //Construct a unit model for testing (we use ivar "unit") super.beforeEach(); this.unit = new Rectangle(); } //----------------- //Tests testGetWidth() { this.assertEquals(0, this.unit.getWidth()); } testGetHeight() { this.assertEquals(0, this.unit.getHeight()); } testGetArea() { this.assertEquals(0, this.unit.getArea()); } testGetPerimeter() { this.assertEquals(0, this.unit.getPerimeter()); } testGetDiagonal() { this.assertFloatEquals(0, this.unit.getDiagonal(), 0.0001); } testFlip() { const rec = this.unit; rec.flip(); this.assertEquals(0, this.unit.getWidth()); this.assertEquals(0, this.unit.getHeight()); } testMultiply() { const rec = this.unit; rec.multiply(2); this.assertEquals(0 * 2, this.unit.getWidth()); this.assertEquals(0 * 2, this.unit.getHeight()); } } //---------------------------------------------------