'From Squeak3.8alpha of 8 September 2004 [latest update: #6224] on 26 September 2004 at 7:45:18 pm'! "Change Set: fixChronologyTests-brp Date: 26 September 2004 Author: Brent Pinkney Fix the Chronology tests for 3.8. 1. The tests can no longer assume the week start day, not the offset from GMT. 2. Some tests assume DateAndTime now < DateAndTime now, instead of #<=. This may be temporary."! ClassTestCase subclass: #ScheduleTest instanceVariableNames: 'firstEvent aSchedule restoredTimeZone ' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Chronology-Tests'! ClassTestCase subclass: #WeekTest instanceVariableNames: 'week restoredStartDay ' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Chronology-Tests'! TestCase subclass: #YearMonthWeekTest instanceVariableNames: 'restoredStartDay restoredTimeZone ' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Chronology-Tests'! !ScheduleTest methodsFor: 'running' stamp: 'brp 9/26/2004 19:30'! setUp "Schedule is a type of Timespan representing repeated occurences of the same event. The beginning of the schedule is the first occurrence of the event. A schedule maintains an array of Durations. Each durations specify the offset to the next scheduled each. The duration of each occurence of the event is not specified. Nor are any other attributes such as name" restoredTimeZone := DateAndTime localTimeZone. DateAndTime localTimeZone: (TimeZone timeZones detect: [:tz | tz abbreviation = 'GMT']). "Create aSchedule with an event scheduled for 8:30pm every Saturday and Sunday for the year 2003. " "Create the first event occurring on the first Saturday at 8:30 pm: 1/4/03" firstEvent := DateAndTime year: 2003 month: 1 day: 4 hour: 20 minute: 30. "Create a schedule for one year starting with the first event" aSchedule := Schedule starting: firstEvent duration: 52 weeks. "Schedule the recurring events by scheduling the time in between each one. One day for Sat-Sun. 6 days for Sun-Sat" aSchedule schedule: { Duration days: 1. Duration days: 6 }. ! ! !ScheduleTest methodsFor: 'running' stamp: 'brp 9/26/2004 19:30'! tearDown DateAndTime localTimeZone: restoredTimeZone. ! ! !StopwatchTest methodsFor: 'Tests' stamp: 'brp 9/26/2004 19:36'! testStartStop | sw t1 t2 t3 t4 | sw := Stopwatch new. t1 := DateAndTime now. (Delay forMilliseconds: 10) wait. sw activate; activate. (Delay forMilliseconds: 10) wait. t2 := DateAndTime now. self deny: (sw isSuspended); assert: (sw isActive); assert: (sw timespans size = 1); assert: (t1 <= sw start); assert: (sw start <= t2). (Delay forMilliseconds: 10) wait. t3 := DateAndTime now. (Delay forMilliseconds: 10) wait. sw suspend; suspend. (Delay forMilliseconds: 10) wait. t4 := DateAndTime now. self assert: (sw isSuspended); deny: (sw isActive); assert: (sw timespans size = 1); assert: (sw end between: t3 and: t4); assert: (t3 <= sw end); assert: (sw end <= t4). ! ! !StopwatchTest methodsFor: 'testing' stamp: 'brp 9/26/2004 19:32'! testMultipleTimings aStopwatch activate. aDelay wait. aStopwatch suspend. aStopwatch activate. aDelay wait. aStopwatch suspend. self assert: aStopwatch timespans size = 2. self assert: aStopwatch timespans first asDateAndTime <= aStopwatch timespans last asDateAndTime. ! ! !StopwatchTest methodsFor: 'testing' stamp: 'brp 9/26/2004 19:32'! testSingleTiming | timeBefore | timeBefore := DateAndTime now. aStopwatch activate. aDelay wait. aStopwatch suspend. self assert: aStopwatch timespans size = 1. self assert: aStopwatch timespans first asDateAndTime >= timeBefore. self assert: aStopwatch timespans first asDateAndTime <= aStopwatch end. ! ! !TimespanDoSpanAYearTest methodsFor: 'testing' stamp: 'brp 9/26/2004 19:06'! testWeeksDo | weeks weekArray | weeks := aTimespan weeks. self assert: weeks size = ((aDuration days / 7.0) ceiling + 1). weekArray := OrderedCollection new. weekArray addLast: (Week starting: (DateAndTime year: 2004 month: 12 day: 19) duration: 7 days); addLast: (Week starting: (DateAndTime year: 2004 month: 12 day: 26) duration: 7 days). 2 to: 79 by: 7 do: [ :i | weekArray addLast: (Week starting: (DateAndTime year: 2005 day: i) duration: 7 days) ]. weekArray := weekArray asArray. self assert: aTimespan weeks = weekArray ! ! !TimespanDoSpanAYearTest methodsFor: 'running' stamp: 'brp 9/26/2004 18:59'! setUp aDate := DateAndTime year: 2004 month: 12 day: 25 hour: 0 minute: 0 second: 0. aDuration := Duration days: 91 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0. aTimespan := Timespan starting: aDate duration: aDuration! ! !WeekTest methodsFor: 'Tests' stamp: 'brp 9/26/2004 18:55'! testEnumerating | days | days := OrderedCollection new. 0 to: 6 do: [ :i | days add: ('28 June 1998' asDate addDays: i) ]. week do: [ :d | days remove: d ]. self assert: days isEmpty. ! ! !WeekTest methodsFor: 'Tests' stamp: 'brp 9/26/2004 18:54'! testInquiries self assert: week firstDate = '28 June 1998' asDate; assert: week lastDate = '4 July 1998' asDate; assert: week index = 5; assert: week duration = (7 days). ! ! !WeekTest methodsFor: 'Running' stamp: 'brp 9/26/2004 18:52'! setUp "June 1998, 5th week" super setUp. restoredStartDay := Week startDay. Week startDay: #Sunday. week := Week starting: '4 July 1998' asDate! ! !WeekTest methodsFor: 'Running' stamp: 'brp 9/26/2004 18:53'! tearDown super tearDown. Week startDay: restoredStartDay. week _ nil. ! ! !YearMonthWeekTest methodsFor: 'testing' stamp: 'brp 9/26/2004 18:31'! testMonthPrintOn | aMonth cs rw | aMonth _ Month starting: DateAndTime new duration: 31 days. cs _ ReadStream on: 'January 1901'. rw _ ReadWriteStream on: ''. aMonth printOn: rw. self assert: rw contents = cs contents.! ! !YearMonthWeekTest methodsFor: 'testing' stamp: 'brp 9/26/2004 18:49'! testWeekPrintOn | aWeek cs rw | aWeek := Week starting: (DateAndTime year: 1900 month: 12 day: 31). cs := 'a Week starting: 1900-12-30T00:00:00+00:00'. rw := WriteStream on: ''. aWeek printOn: rw. self assert: rw contents = cs! ! !YearMonthWeekTest methodsFor: 'testing' stamp: 'brp 9/26/2004 18:32'! testYearPrintOn | aYear cs rw | aYear _ Year starting: DateAndTime new duration: 365 days. cs _ ReadStream on: 'a Year (1901)'. rw _ ReadWriteStream on: ''. aYear printOn: rw. self assert: rw contents = cs contents.! ! !YearMonthWeekTest methodsFor: 'running' stamp: 'brp 9/26/2004 19:26'! setUp restoredStartDay _ Week startDay. restoredTimeZone _ DateAndTime localTimeZone. Week startDay: #Sunday. DateAndTime localTimeZone: (TimeZone timeZones detect: [:tz | tz abbreviation = 'GMT']).! ! !YearMonthWeekTest methodsFor: 'running' stamp: 'brp 9/26/2004 19:27'! tearDown Week startDay: restoredStartDay. DateAndTime localTimeZone: restoredTimeZone.! ! TestCase subclass: #YearMonthWeekTest instanceVariableNames: 'restoredStartDay restoredTimeZone' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Chronology-Tests'! ClassTestCase subclass: #WeekTest instanceVariableNames: 'week restoredStartDay' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Chronology-Tests'! ClassTestCase subclass: #ScheduleTest instanceVariableNames: 'firstEvent aSchedule restoredTimeZone' classVariableNames: '' poolDictionaries: '' category: 'Kernel-Chronology-Tests'!