| import testing.*; |
| import testing.*; class Painting { String painter; String title; double value; boolean forSale; Painting( String painter, String title, double value, boolean forSale ) { this.painter = painter; this.title = title; this.value = value; this.forSale = forSale; } //new Painting("Picasso","Starry Night",1e10, false) -> 4e10 //new Painting("GirlNextDoor","My Dog",4.50,true) -> 4.50 //To report the price to buy this Painting, any owner will sell if the price is high enough double price() { // ... this.painter ... this.title ... this.value ... this.forSale ... if (this.forSale) return this.value; else return this.value * 4; } //new Painting("Opra","Self Portrait",10000,true).mistkenIdentification("Shelly","Opra") -> // new Painting("Shelly","Opra",10000,true) //To produce a new painting, when the painter was misidentified originally Painting mistakenIdentification( String truePainter, String trueTitle ) { return new Painting(truePainter,trueTitle, this.value, this.forSale ); } } |
| class PaintingTest { PaintingTest() { } } |
| class PaintingTest extends Test { PaintingTest() { } } |
| class PaintingTest extends Test { PaintingTest() { } TestResult testPriceNotForSale() { } |
| class PaintingTest extends Test { PaintingTest() { } TestResult testPriceNotForSale() { return this.compareInexacts(new Painting("Picasso","Starry Night",1e10, false).price(), 4e10, 0.01); } } |
| class PaintingTest extends Test { PaintingTest() { } TestResult testPriceNotForSale() { return this.compareInexacts(new Painting("Picasso","Starry Night",1e10, false).price(), 4e10, 0.01); } TestResult testPriceForSale() { return this.compareInexacts(new Painting("GirlNextDoor","My Dog",4.50,true).price(), 4.50, 0.01); } TestResult testMistakenIdentification() { return this.compareObjects(new Painting("Opra","Self Portrait",10000,true).mistakenIdentification("Shelly","Opra") , new Painting("Shelly","Opra",10000,true) ); } } |
| Ran Tests for PaintingTest : 100.0 %
passed : ok! TestSummary( classTested = "PaintingTest", numTests = 3, passedTests = 3, failedTests = 0) |
| Ran Tests for PaintingTest :
33.33333333333333 % passed : The following tests failed: testMistakenIdentification --- expected Painting(painter = "Shelly", title = "Opra", value = 10000, forSale = true) actual Painting(painter = "Shelly", title = "Ora", value = 10000, forSale = true) testPriceForSale --- expected 4.5 actual 4.05 TestSummary( classTested = "PaintingTest", numTests = 3, passedTests = 1, failedTests = 2) |
| Test |
| TestResult compareInexacts(
double actual, double expected, double epsilon) TestResult compareExacts(int actual, int expected) TestResult compareStrings( String actual, String expected) TestResult compareObjects( Object actual, Object expected) TestResult compare( boolean actual, boolean expected) TestSummary run() |