Uploaded by bmd81

Test doc

advertisement
Here the constructor is being tested, along with all the getters and setters.
The values are initalized as "bob's" in the constructor, but then set to "john's" one at a time.
> Contractor c = new Contractor("bob", "123 bob lane", "b@bob.com")
> c.getName()
"bob"
> c.setName("john")
> c.getName()
"john"
> c.getAddress()
"123 bob lane"
> c.setAddress("456 john ave")
> c.getAddress()
"456 john ave"
> c.getContact()
"b@bob.com"
> c.setContact("j@john.org")
> c.getContact()
"j@john.org"
Here the get getAmountPaid and pay methods are tests.
The pay method adds the current amount as expected.
> Contractor c = new Contractor("bob", "123 bob lane", "b@bob.com")
> c.getAmountPaid()
0.0
> c.pay(50.0)
> c.getAmountPaid()
50.0
> c.pay(100.0)
> c.getAmountPaid()
150.0
Here a few different instances of contractors are made to test the toString and equals methods.
Made sure to test different objects of the same values.
> Contractor c1 = new Contractor("bob", "123 bob lane", "b@bob.com")
> Contractor c2 = new Contractor("john", "456 john ave", "j@john.org")
> Contractor c3 = new Contractor("bob", "456 bob street", "b@bob.org")
> c2.toString()
"john, 456 john ave, j@john.org"
> c1.toString()
"bob, 123 bob lane, b@bob.com"
> c2.toString()
"john, 456 john ave, j@john.org"
> Contractor.equals(c1, c2)
false
> Contractor.equals(c1, c1)
true
// This is correct as c1 and c3 are set to have the same name, "bob"
> Contractor.equals(c1, c3)
true
Here the constructor and getters for the Date class are tested.
> Date d = new Date(26, 7, 2004)
> d.getDate()
26
> d.getMonth()
7
> d.getYear()
2004
Here the formatting and string representation methods are tested.
> Date d = new Date(26, 7, 2004)
> d.isUsFormat()
false
> d.toString()
"26 July 2004"
> d.setUSFormat(true)
> d.isUsFormat()
true
> d.toString()
"July 26, 2004"
Here the daysFromJan1 method is tested. The last two test is the leap year detection works, and 2004 was a leap year
but 2022 is not.
> Date p = new Date(1, 1, 2000)
> p.daysFromJan1()
0
> Date d = new Date(26, 7, 2004)
> d.daysFromJan1()
207
> Date d = new Date(18, 9, 2004)
> d.daysFromJan1()
261
> Date d = new Date(18, 9, 2022)
> d.daysFromJan1()
260
Here the difference method is tested with date objects
> Date d = new Date(18, 9, 2022)
> Date p = new Date(26, 7, 2024)
> Date.difference(d, p)
677
> Date.difference(d, d)
0
> Date.difference(p, d)
-677
Here the equals method is tested, made sure to test different objects of the same values.
> Date d = new Date(18, 9, 2022)
> Date p = new Date(26, 7, 2024)
> Date.equals(p, d)
false
> Date.equals(p, p)
true
> Date p = new Date(18, 9, 2022)
> Date.equals(p, d)
false
Here the constructor and getters/setters are tested for the contract object
> Date d = new Date(26, 7, 2004)
> Contract c = new Contract("contract1", 0.0, 200.0, 1.0, 2.0, d)
> c.getID()
"contract1"
> c.getMinValue()
0.0
> c.setMinValue(1.0)
> c.getMinValue()
1.0
> c.getMaxValue()
200.0
> c.setMaxValue(300.0)
> c.getMaxValue()
300.0
> c.getBonus()
1.0
> c.setBonus(3.0)
> c.getBonus()
3.0
> c.getPenalty()
2.0
> c.setPenalty(9.0)
> c.getPenalty()
9.0
> c.getDeadline()
26 July 2004
> Date p = new Date(1, 1, 2000)
> c.setDeadline(p)
> c.getDeadline()
1 January 2000
This should be the final test of the contract system, which brings all of the other objects together
> Date d = new Date(26, 7, 2004)
> Contract c = new Contract("contract1", 0.0, 200.0, 1.0, 2.0, d)
> Contractor contractor = new Contractor("bob", "123 bob lane", "b@bob.com")
> c.isAcceptingBids()
true
> c.getBestBid()
null
> c.isComplete()
false
> c.completeDate()
null
> Bid b = new Bid(c, contractor, 150.0)
> b.contract()
Contract@9863c2c
> b.getContractor()
bob, 123 bob lane, b@bob.com
> b.value()
150.0
> Bid bid = new Bid(c, contractor, 100.0)
> c.makeBid(b)
true
> c.makeBid(b)
false
> c.makeBid(bid)
true
> c.makeBid(b)
false
> c.awardContract()
> c.makeBid(new Bid(c, contractor, 40.0))
false
> c.setComplete(new Date(20, 7, 2004))
> c.isAcceptingBids()
false
> c.getBestBid()
Bid@51397c09
> c.isComplete()
true
> c.completeDate()
20 July 2004
> c.getBestBid().getContractor().getAmountPaid()
106.0
// Checks the penalty feature
> Date d = new Date(26, 7, 2004)
> Contract c = new Contract("contract1", 0.0, 200.0, 1.0, 2.0, d)
> Contractor contractor = new Contractor("bob", "123 bob lane", "b@bob.com")
> Bid bid = new Bid(c, contractor, 100.0)
> c.makeBid(bid)
true
> c.awardContract()
> c.setComplete(new Date(1, 8, 2004))
> c.getBestBid().getContractor().getAmountPaid()
88.0
// Completed on the deadline
> Date d = new Date(26, 7, 2004)
> Contract c = new Contract("contract1", 0.0, 200.0, 1.0, 2.0, d)
> Contractor contractor = new Contractor("bob", "123 bob lane", "b@bob.com")
> Bid bid = new Bid(c, contractor, 100.0)
> c.makeBid(bid)
true
> c.awardContract()
> c.setComplete(new Date(26, 7, 2004))
> c.getBestBid().getContractor().getAmountPaid()
100.0
// Date so far it is outside the range of min/max value
> Date d = new Date(26, 7, 2004)
> Contract c = new Contract("contract1", 0.0, 200.0, 1.0, 2.0, d)
> Contractor contractor = new Contractor("bob", "123 bob lane", "b@bob.com")
> Bid bid = new Bid(c, contractor, 100.0)
> c.makeBid(bid)
true
> c.awardContract()
> c.setComplete(new Date(26, 7, 2005))
> c.getBestBid().getContractor().getAmountPaid()
0.0
Here is the testing of the extra credit with months stored as enums
> Date d = new Date(20, Date.Month.JAN, 2004)
> d
20 January 2004
> Date d = new Date(20, Date.Month.DEC, 2004)
> d
20 December 2004
> d.getMonth()
DEC
> Date d = new Date(1, Date.Month.JAN, 2021)
> d.daysFromJan1()
0
> Date d = new Date(20, Date.Month.DEC, 2021)
> d.daysFromJan1()
353
> Date d = new Date(20, Date.Month.DEC, 2004)
> d.daysFromJan1()
354
> Date d = new Date(1, Date.Month.JAN, 2004)
> d.daysFromJan1()
(nothing changed about the difference() method, as it just used daysFromJan1() already, so that does not need retested
Thanks!
Download