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(10, 5); }
getUnitName() { //Housekeeping - return class name of unit return 'Rectangle'; }
testGetWidth() { this.assertEquals(10, this.unit.getWidth()); }
testGetHeight() { this.assertEquals(5, this.unit.getHeight()); }
testGetArea() { this.assertEquals(10 * 5, this.unit.getArea()); }
testGetPerimeter() { this.assertEquals(10 + 10 + 5 + 5, this.unit.getPerimeter()); }
testGetDiagonal() { this.assertFloatEquals(11.18034, this.unit.getDiagonal(), 0.0001); }
testFlip() { const rec = this.unit; rec.flip(); this.assertEquals(5, this.unit.getWidth()); this.assertEquals(10, this.unit.getHeight()); }
testMultiply() { const rec = this.unit; rec.multiply(2); this.assertEquals(10 * 2, this.unit.getWidth()); this.assertEquals(5 * 2, this.unit.getHeight()); }
//Housekeeping - add name of test class //Note: param must be a string addTestCase("RectangleTestCase"); class RectangleTestCase extends TestCase { //ivars: unit //----------------- //Unit Test Support getUnitName() { //Housekeeping - return class name of unit return 'Rectangle'; } //----------------- //Setup 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(10, 5); } //----------------- //Tests testGetWidth() { this.assertEquals(10, this.unit.getWidth()); } testGetHeight() { this.assertEquals(5, this.unit.getHeight()); } testGetArea() { this.assertEquals(10 * 5, this.unit.getArea()); } testGetPerimeter() { this.assertEquals(10 + 10 + 5 + 5, this.unit.getPerimeter()); } testGetDiagonal() { this.assertFloatEquals(11.18034, this.unit.getDiagonal(), 0.0001); } testFlip() { const rec = this.unit; rec.flip(); this.assertEquals(5, this.unit.getWidth()); this.assertEquals(10, this.unit.getHeight()); } testMultiply() { const rec = this.unit; rec.multiply(2); this.assertEquals(10 * 2, this.unit.getWidth()); this.assertEquals(5 * 2, this.unit.getHeight()); } }