self.assertTrue(dayNumber.isLeapYear(2004))
# Can have assertEqual(expected, actual)
self.assertEquals(2, 13 // 5)
# assertTrue(bool)
self.assertFalse('a' < 'A')
First, a few example assertions:
def testIsLeapYear(self):
# assertFalse(bool)
What follows is output from running Rick's tests from CalendarTests.py over all three programs. Comments written like this were added after running the tests in IDLE
>>> ================================ RESTART ================================
>>>
F.FFF # 5 test methods Rick's test module ran, only one passed, others Failed
======================================================================
FAIL: testDayNumber (__main__.CalendarTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/mercer/Desktop/Tests/CalendarTests.py", line 91, in testDayNumber
self.assertEqual(60, dayNumber.dayNumber('02/29/2012'))
# See line 91 for the first failing assertion in def testDayNumber(self):
# Other assertions may occur in this same test function after one is fixed
AssertionError: 60 != 61 # Expected 60, but got back 61. Either could be wrong
======================================================================
FAIL: testIsLeapYear (__main__.CalendarTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/mercer/Desktop/Tests/CalendarTests.py", line 83, in testIsLeapYear
self.assertFalse(dayNumber.isLeapYear(2100))
AssertionError: True is not false # No kidding. Expected True, got back False
======================================================================
FAIL: testTDate (__main__.CalendarTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/mercer/Desktop/Tests/CalendarTests.py", line 29, in testTDate
self.assertEqual(28, tDate.tDate('FR'))
AssertionError: 28 != 27 # Check line 29 Notice the line numbers are not in order.
======================================================================
FAIL: testValidDate (__main__.CalendarTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/mercer/Desktop/Tests/CalendarTests.py", line 70, in testValidDate
self.assertFalse(dayNumber.isValidDate('06/31/2012'))
AssertionError: True is not false # Assertion failed on line 70
----------------------------------------------------------------------
Ran 5 tests in 0.067s
FAILED (failures=4) # There were 5 tests, 4 of which had at least one failing assertion
>>>
When you see this feedback, you should get 60/60 for getting all assertions passing:
>>> ================================ RESTART ================================
>>>
.....
----------------------------------------------------------------------
Ran 5 tests in 0.063s
OK
>>>