'From Squeak3.2alpha of 4 October 2001 [latest update: #4441] on 25 October 2001 at 7:52:30 pm'! "Change Set: PrintingTimeTests Date: 14 October 2001 Author: Gerald Leeb UnitTest for the class Time, for the PrintingTime-LEG fix changeset. (To run the test, do 'TestRunner open', select TimeTestCase and run it.)"! TestCase subclass: #TimeTestCase instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Magnitudes-Tests'! !TimeTestCase methodsFor: 'comparing' stamp: 'LEG 10/15/2001 20:50'! comparePrintStreamFor: time hr24: hr24 showSeconds: showSeconds expected: expected | output | output _ String streamContents: [ :aStream | time print24: hr24 showSeconds: showSeconds on: aStream]. self assert: (output = expected)! ! !TimeTestCase methodsFor: 'comparing' stamp: 'LEG 10/15/2001 20:02'! hoursShould: expectedHours for: seconds self assert: ((Time fromSeconds: seconds) hours = expectedHours). ! ! !TimeTestCase methodsFor: 'comparing' stamp: 'LEG 10/15/2001 20:07'! minutesShould: expectedMinutes for: seconds self assert: ((Time fromSeconds: seconds) minutes = expectedMinutes). ! ! !TimeTestCase methodsFor: 'comparing' stamp: 'LEG 10/15/2001 20:11'! secondsShould: expectedSeconds for: seconds self assert: ((Time fromSeconds: seconds) seconds = expectedSeconds). ! ! !TimeTestCase methodsFor: 'testing' stamp: 'LEG 10/15/2001 20:01'! testHours self hoursShould: 0 for: 0. self hoursShould: 0 for: 3599. self hoursShould: 1 for: 3600. self hoursShould: 1 for: 3601. self hoursShould: 23 for: 86399. self hoursShould: 0 for: 86400. self hoursShould: 0 for: 86401. self hoursShould: 23 for: -1. self hoursShould: 23 for: -3599. self hoursShould: 23 for: -3600. self hoursShould: 22 for: -3601. self hoursShould: 0 for: -86399. self hoursShould: 0 for: -86400. self hoursShould: 23 for: -86401. ! ! !TimeTestCase methodsFor: 'testing' stamp: 'LEG 10/15/2001 20:07'! testMinutes self minutesShould: 0 for: 0. self minutesShould: 0 for: 59. self minutesShould: 1 for: 60. self minutesShould: 1 for: 61. self minutesShould: 59 for: 3599. self minutesShould: 0 for: 3600. self minutesShould: 0 for: 3601. self minutesShould: 59 for: -1. "23:59" self minutesShould: 59 for: -59. self minutesShould: 59 for: -60. self minutesShould: 58 for: -61. self minutesShould: 0 for: -3599. self minutesShould: 0 for: -3600. self minutesShould: 59 for: -3601. ! ! !TimeTestCase methodsFor: 'testing' stamp: 'LEG 10/15/2001 20:40'! testPrintNegativeTime "UnitTest for [BUG] Printing Time Description: I'm not sure if this is a bug or 'as designed', but when you do any arithmetic with time objects (especially subtraction) and the seconds go negative (before midnight), when you print out the time you either always get 12 am or something interesting if you are printing 24-hour time. A simple fix in the method print24:showSeconds:on: would be to instead of initializing the local variable h to self hours, initialize h to self hours \\ 24." |time1 time2 timeDiff| time1 _ Time new. time1 hours: 1 minutes: 0 seconds: 0. time2 _ Time new. time2 hours: 4 minutes: 0 seconds: 0. timeDiff _ time1 subtractTime: time2. "time 01:00:00 - 04:00:00 should return 21:00:00 or 09:00:00 pm" self comparePrintStreamFor: timeDiff hr24: false showSeconds: false expected: '9:00 pm'. self comparePrintStreamFor: timeDiff hr24: false showSeconds: true expected: '9:00:00 pm'. self comparePrintStreamFor: timeDiff hr24: true showSeconds: false expected: '21:00'. self comparePrintStreamFor: timeDiff hr24: true showSeconds: true expected: '21:00:00'. ! ! !TimeTestCase methodsFor: 'testing' stamp: 'LEG 10/14/2001 22:48'! testPrintPositiveTime |time1| time1 _ Time new. time1 hours: 1 minutes: 0 seconds: 0. self comparePrintStreamFor: time1 hr24: false showSeconds: false expected: '1:00 am'. self comparePrintStreamFor: time1 hr24: false showSeconds: true expected: '1:00:00 am'. self comparePrintStreamFor: time1 hr24: true showSeconds: false expected: '01:00'. self comparePrintStreamFor: time1 hr24: true showSeconds: true expected: '01:00:00'. ! ! !TimeTestCase methodsFor: 'testing' stamp: 'LEG 10/15/2001 20:10'! testSeconds self secondsShould: 0 for: 0. self secondsShould: 59 for: 59. self secondsShould: 0 for: 60. self secondsShould: 1 for: 61. self secondsShould: 59 for: -1. "23:59" self secondsShould: 1 for: -59. self secondsShould: 0 for: -60. self secondsShould: 59 for: -61. ! ! !TimeTestCase reorganize! ('comparing' comparePrintStreamFor:hr24:showSeconds:expected: hoursShould:for: minutesShould:for: secondsShould:for:) ('testing' testHours testMinutes testPrintNegativeTime testPrintPositiveTime testSeconds) !