[squeak-dev] The Trunk: Chronology-Tests-pre.16.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Jan 23 15:07:33 UTC 2019
Patrick Rein uploaded a new version of Chronology-Tests to project The Trunk:
http://source.squeak.org/trunk/Chronology-Tests-pre.16.mcz
==================== Summary ====================
Name: Chronology-Tests-pre.16
Author: pre
Time: 23 January 2019, 4:07:30.393474 pm
UUID: 0802f65d-2dc0-6e44-b8ec-b8b6428edacb
Ancestors: Chronology-Tests-ul.15, Chronology-Tests-dtl.15
- adds the DateAndTimeTest>>#testGetSeconds test from dtl
- adds a test for Duration>>#wait
- updates an old test to match the new API #testNew
- recategorizes the tests into the tests category
=============== Diff against Chronology-Tests-ul.15 ===============
Item was added:
+ ----- Method: DateAndTimeTest>>testGetSeconds (in category 'Tests') -----
+ testGetSeconds
+ "Verify that getSeconds represents whole seconds in the local time zone. For
+ a given instance of DateAndTime, changing the time zone offset changes the
+ local representation, but does not affect magnitude (time since a defiined
+ epoch). Therefore, if time zone offset changes, the asSeconds value should
+ not change, and the getSeconds value should change to reflect local timezone."
+
+ | dt s1 id stSeconds seconds1 seconds2 |
+ s1 := '2019-01-12T10:07:05.18743-05:00'.
+ dt := s1 asDateAndTime.
+ self assert: 18000 seconds negated equals: dt offset.
+ seconds1 := dt getSeconds.
+ self assert: 36425 equals: seconds1.
+ id := dt identityHash.
+ stSeconds := dt asSeconds.
+ dt makeUTC. "make the receiver's timezone GMT, do not change magnitude"
+ self assert: id equals: dt identityHash. "same object, not a copy"
+ self assert: '2019-01-12T15:07:05.18743+00:00' equals: dt asString.
+ self assert: stSeconds equals: dt asSeconds. "magnitude unchanged"
+ self assert: '2019-01-12T10:07:05.18743-05:00' asDateAndTime equals: dt. "still equal"
+ seconds2 := dt getSeconds.
+ self deny: seconds1 equals: seconds2.
+ self assert: 54425 equals: seconds2.
+
+ !
Item was changed:
+ ----- Method: DurationTest>>classToBeTested (in category 'coverage') -----
- ----- Method: DurationTest>>classToBeTested (in category 'Coverage') -----
classToBeTested
^ Duration
!
Item was changed:
+ ----- Method: DurationTest>>selectorsToBeIgnored (in category 'coverage') -----
- ----- Method: DurationTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored
| private |
private := #( #printOn: ).
^ super selectorsToBeIgnored, private
!
Item was changed:
+ ----- Method: DurationTest>>testAbs (in category 'tests') -----
- ----- Method: DurationTest>>testAbs (in category 'testing') -----
testAbs
self assert: aDuration abs = aDuration.
self assert: (Duration nanoSeconds: -5) abs = (Duration nanoSeconds: 5).
!
Item was changed:
+ ----- Method: DurationTest>>testAgo (in category 'tests') -----
- ----- Method: DurationTest>>testAgo (in category 'testing') -----
testAgo
self assert: ((10 minutes ago) isMemberOf: DateAndTime).
self assert: ((10 weeks ago) < DateAndTime now).
self assert: ((-50 seconds ago) > DateAndTime now).
self assert: ((10 hours ago) < DateAndTime now).
self assert: (0 seconds ago - DateAndTime now < 1 second).!
Item was changed:
+ ----- Method: DurationTest>>testAsDelay (in category 'tests') -----
- ----- Method: DurationTest>>testAsDelay (in category 'testing') -----
testAsDelay
self deny: aDuration asDelay = aDuration.
"want to come up with a more meaningful test"
!
Item was changed:
+ ----- Method: DurationTest>>testAsDuration (in category 'tests') -----
- ----- Method: DurationTest>>testAsDuration (in category 'testing') -----
testAsDuration
self assert: aDuration asDuration = aDuration
!
Item was changed:
+ ----- Method: DurationTest>>testAsMilliSeconds (in category 'tests') -----
- ----- Method: DurationTest>>testAsMilliSeconds (in category 'testing') -----
testAsMilliSeconds
self assert: (Duration nanoSeconds: 1000000) asMilliSeconds = 1.
self assert: (Duration seconds: 1) asMilliSeconds = 1000.
self assert: (Duration nanoSeconds: 1000000) asMilliSeconds = 1.
self assert: (Duration nanoSeconds: 1000000) asMilliSeconds = 1.
self assert: aDuration asMilliSeconds = 93784000.
self assert: (Duration milliSeconds: 3775) asSeconds = 3.
self assert: (Duration milliSeconds: 3775) nanoSeconds = 775000000!
Item was changed:
+ ----- Method: DurationTest>>testAsNanoSeconds (in category 'tests') -----
- ----- Method: DurationTest>>testAsNanoSeconds (in category 'testing') -----
testAsNanoSeconds
self assert: (Duration nanoSeconds: 1) asNanoSeconds = 1.
self assert: (Duration seconds: 1) asNanoSeconds = 1000000000.
self assert: aDuration asNanoSeconds = 93784000000005.!
Item was changed:
+ ----- Method: DurationTest>>testAsSeconds (in category 'tests') -----
- ----- Method: DurationTest>>testAsSeconds (in category 'testing') -----
testAsSeconds
self assert: (Duration nanoSeconds: 1000000000) asSeconds = 1.
self assert: (Duration seconds: 1) asSeconds = 1.
self assert: aDuration asSeconds = 93784.!
Item was changed:
+ ----- Method: DurationTest>>testComparing (in category 'tests') -----
- ----- Method: DurationTest>>testComparing (in category 'Tests') -----
testComparing
| d1 d2 d3 |
d1 := Duration seconds: 10 nanoSeconds: 1.
d2 := Duration seconds: 10 nanoSeconds: 1.
d3 := Duration seconds: 10 nanoSeconds: 2.
self
assert: (d1 = d1);
assert: (d1 = d2);
deny: (d1 = d3);
assert: (d1 < d3)
!
Item was changed:
+ ----- Method: DurationTest>>testDays (in category 'tests') -----
- ----- Method: DurationTest>>testDays (in category 'testing') -----
testDays
self assert: aDuration days = 1.
self assert: (Duration days: 1) days= 1. !
Item was changed:
+ ----- Method: DurationTest>>testDivide (in category 'tests') -----
- ----- Method: DurationTest>>testDivide (in category 'testing') -----
testDivide
self assert: aDuration / aDuration = 1.
self assert: aDuration / 2 = (Duration days: 0 hours: 13 minutes: 1 seconds: 32 nanoSeconds: 2).
self assert: aDuration / (1/2) = (Duration days: 2 hours: 4 minutes: 6 seconds: 8 nanoSeconds: 10).
!
Item was changed:
+ ----- Method: DurationTest>>testFromNow (in category 'tests') -----
- ----- Method: DurationTest>>testFromNow (in category 'testing') -----
testFromNow
self assert: ((10 seconds fromNow) > DateAndTime now).
self assert: ((0 days fromNow - DateAndTime now) < 1 second).
self assert: ((-1 weeks fromNow) < DateAndTime now).
self assert: ((1000 milliSeconds fromNow) isMemberOf: DateAndTime).
self assert: ((250 hours fromNow) > DateAndTime now).
self assert: ((-50 minutes fromNow) < DateAndTime now).!
Item was changed:
+ ----- Method: DurationTest>>testFromString (in category 'tests') -----
- ----- Method: DurationTest>>testFromString (in category 'testing') -----
testFromString
self assert: aDuration = (Duration fromString: '1:02:03:04.000000005').
!
Item was changed:
+ ----- Method: DurationTest>>testHash (in category 'tests') -----
- ----- Method: DurationTest>>testHash (in category 'testing') -----
testHash
self assert: aDuration hash = (Duration days: 1 hours: 2 minutes: 3 seconds: 4 nanoSeconds: 5) hash.
self assert: aDuration hash = 93789
"must be a more meaningful test?"!
Item was changed:
+ ----- Method: DurationTest>>testHours (in category 'tests') -----
- ----- Method: DurationTest>>testHours (in category 'testing') -----
testHours
self assert: aDuration hours = 2.
self assert: (Duration hours: 2) hours = 2. !
Item was changed:
+ ----- Method: DurationTest>>testIntegerDivision (in category 'tests') -----
- ----- Method: DurationTest>>testIntegerDivision (in category 'testing') -----
testIntegerDivision
self assert: aDuration // aDuration = 1.
self assert: aDuration // 2 = (aDuration / 2).
"is there ever a case where this is not true, since precision is always to the nano second?"!
Item was changed:
+ ----- Method: DurationTest>>testLessThan (in category 'tests') -----
- ----- Method: DurationTest>>testLessThan (in category 'testing') -----
testLessThan
self assert: aDuration < (aDuration + 1 day ).
self deny: aDuration < aDuration.
!
Item was changed:
+ ----- Method: DurationTest>>testMilliSeconds (in category 'tests') -----
- ----- Method: DurationTest>>testMilliSeconds (in category 'testing') -----
testMilliSeconds
#(
"argument (milliseconds) seconds nanoseconds"
(5 0 5000000)
(1005 1 5000000)
(-5 0 -5000000)
(-1005 -1 -5000000)
(1234567 1234 567000000)
(-1234567 -1234 -567000000)
) do: [ :each |
| duration |
duration := Duration milliSeconds: each first.
self assert: duration asSeconds = each second.
self assert: duration nanoSeconds = each third ]!
Item was changed:
+ ----- Method: DurationTest>>testMinus (in category 'tests') -----
- ----- Method: DurationTest>>testMinus (in category 'testing') -----
testMinus
self assert: aDuration - aDuration = (Duration seconds: 0).
self assert: aDuration - (Duration days: -1 hours: -2 minutes: -3 seconds: -4 nanoSeconds: -5) =
(Duration days: 2 hours: 4 minutes: 6 seconds: 8 nanoSeconds: 10).
self assert: aDuration - (Duration days: 0 hours: 1 minutes: 2 seconds: 3 nanoSeconds: 4) =
(Duration days: 1 hours: 1 minutes: 1 seconds: 1 nanoSeconds: 1).
self assert: aDuration - (Duration days: 0 hours: 3 minutes: 0 seconds: 5 nanoSeconds: 0) =
(Duration days: 0 hours: 23 minutes: 2 seconds: 59 nanoSeconds: 5). !
Item was changed:
+ ----- Method: DurationTest>>testMinutes (in category 'tests') -----
- ----- Method: DurationTest>>testMinutes (in category 'testing') -----
testMinutes
self assert: aDuration minutes = 3.
self assert: (Duration minutes: 3) minutes = 3. !
Item was changed:
+ ----- Method: DurationTest>>testModulo (in category 'tests') -----
- ----- Method: DurationTest>>testModulo (in category 'Tests') -----
testModulo
| d1 d2 d3 |
d1 := 11.5 seconds.
d2 := d1 \\ 3.
self assert: d2 = (Duration nanoSeconds: 1).
d3 := d1 \\ (3 seconds).
self assert: d3 = (Duration seconds: 2 nanoSeconds: 500000000).
self assert: aDuration \\ aDuration =
(Duration days: 0 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0).
self assert: aDuration \\ 2 =
(Duration days: 0 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 1).
!
Item was changed:
+ ----- Method: DurationTest>>testMonthDurations (in category 'tests') -----
- ----- Method: DurationTest>>testMonthDurations (in category 'Tests') -----
testMonthDurations
| jan feb dec |
jan := Duration month: #January.
feb := Duration month: #February.
dec := Duration month: #December.
self
assert: jan = (Year current months first duration);
assert: feb = (Year current months second duration);
assert: dec = (Year current months last duration)
!
Item was changed:
+ ----- Method: DurationTest>>testMultiply (in category 'tests') -----
- ----- Method: DurationTest>>testMultiply (in category 'testing') -----
testMultiply
self assert: aDuration * 2 = (Duration days: 2 hours: 4 minutes: 6 seconds: 8 nanoSeconds: 10). !
Item was changed:
+ ----- Method: DurationTest>>testNanoSeconds (in category 'tests') -----
- ----- Method: DurationTest>>testNanoSeconds (in category 'testing') -----
testNanoSeconds
self assert: aDuration nanoSeconds = 5.
self assert: (Duration nanoSeconds: 5) nanoSeconds = 5. !
Item was changed:
+ ----- Method: DurationTest>>testNegated (in category 'tests') -----
- ----- Method: DurationTest>>testNegated (in category 'testing') -----
testNegated
self assert: aDuration + aDuration negated = (Duration seconds: 0).
!
Item was changed:
+ ----- Method: DurationTest>>testNegative (in category 'tests') -----
- ----- Method: DurationTest>>testNegative (in category 'testing') -----
testNegative
self deny: aDuration negative.
self assert: aDuration negated negative
!
Item was changed:
+ ----- Method: DurationTest>>testNew (in category 'tests') -----
- ----- Method: DurationTest>>testNew (in category 'testing') -----
testNew
+
+ self assert: Duration new = (Duration seconds: 0)!
- "self assert: Duration new = (Duration seconds: 0)."
- "new is not valid as a creation method: MessageNotUnderstood: UndefinedObject>>quo:, where Duration seconds is nil"!
Item was changed:
+ ----- Method: DurationTest>>testNormalizeNanoSeconds (in category 'tests') -----
- ----- Method: DurationTest>>testNormalizeNanoSeconds (in category 'testing') -----
testNormalizeNanoSeconds
"Subtraction of two DateAndTime values may result in a request to
create a Duration with negative nanoseconds and positive seconds.
The resulting Duration should be normalized, otherwise its printString
will be invalid."
| d t1 t2 |
t1 := '2004-01-07T11:55:01+00:00' asDateAndTime.
t2 := '2004-01-07T11:55:00.9+00:00' asDateAndTime.
d := t1 - t2. "100 millisecond difference"
self assert: d nanoSeconds > 0.
self assert: d seconds = 0.
self assert: d nanoSeconds = 100000000.
self assert: d asString = '0:00:00:00.1'.
"Verify that other combinations produces reasonable printString values"
self assert: (Duration seconds: 1 nanoSeconds: 100000000) printString = '0:00:00:01.1'.
self assert: (Duration seconds: -1 nanoSeconds: -100000000) printString = '-0:00:00:01.1'.
self assert: (Duration seconds: 1 nanoSeconds: -100000000) printString = '0:00:00:00.9'.
self assert: (Duration seconds: -1 nanoSeconds: 100000000) printString = '-0:00:00:00.9'
!
Item was changed:
+ ----- Method: DurationTest>>testNumberConvenienceMethods (in category 'tests') -----
- ----- Method: DurationTest>>testNumberConvenienceMethods (in category 'Tests') -----
testNumberConvenienceMethods
self
assert: 1 week = (Duration days: 7);
assert: -1 week = (Duration days: -7);
assert: 1 day = (Duration days: 1);
assert: -1 day = (Duration days: -1);
assert: 1 hours = (Duration hours: 1);
assert: -1 hour = (Duration hours: -1);
assert: 1 minute = (Duration seconds: 60);
assert: -1 minute = (Duration seconds: -60);
assert: 1 second = (Duration seconds: 1);
assert: -1 second = (Duration seconds: -1);
assert: 1 milliSecond = (Duration milliSeconds: 1);
assert: -1 milliSecond = (Duration milliSeconds: -1);
assert: 1 nanoSecond = (Duration nanoSeconds: 1);
assert: -1 nanoSecond = (Duration nanoSeconds: -1)
!
Item was changed:
+ ----- Method: DurationTest>>testPlus (in category 'tests') -----
- ----- Method: DurationTest>>testPlus (in category 'testing') -----
testPlus
self assert: (aDuration + 0 hours) = aDuration.
self assert: (aDuration + aDuration) = (Duration days: 2 hours: 4 minutes: 6 seconds: 8 nanoSeconds: 10). !
Item was changed:
+ ----- Method: DurationTest>>testPositive (in category 'tests') -----
- ----- Method: DurationTest>>testPositive (in category 'testing') -----
testPositive
self assert: (Duration nanoSeconds: 0) positive.
self assert: aDuration positive.
self deny: aDuration negated positive
!
Item was changed:
+ ----- Method: DurationTest>>testPrintOn (in category 'tests') -----
- ----- Method: DurationTest>>testPrintOn (in category 'testing') -----
testPrintOn
| ref ws |
ref := '1:02:03:04.000000005'.
ws := '' writeStream.
aDuration printOn: ws.
self assert: ws contents = ref!
Item was changed:
+ ----- Method: DurationTest>>testQuotient (in category 'tests') -----
- ----- Method: DurationTest>>testQuotient (in category 'Tests') -----
testQuotient
| d1 d2 q |
d1 := 11.5 seconds.
d2 := d1 // 3.
self assert: d2 = (Duration seconds: 3 nanoSeconds: 833333333).
q := d1 // (3 seconds).
self assert: q = 3.
!
Item was changed:
+ ----- Method: DurationTest>>testReadFrom (in category 'tests') -----
- ----- Method: DurationTest>>testReadFrom (in category 'testing') -----
testReadFrom
self assert: aDuration = (Duration readFrom: (ReadStream on: '1:02:03:04.000000005'))
!
Item was changed:
+ ----- Method: DurationTest>>testReadFromTrailingDigits (in category 'tests') -----
- ----- Method: DurationTest>>testReadFromTrailingDigits (in category 'Tests') -----
testReadFromTrailingDigits
"http://bugs.squeak.org/view.php?id=6764"
self should: (Duration readFrom: '0:00:00:00.001 ' readStream) nanoSeconds = 1000000.!
Item was changed:
+ ----- Method: DurationTest>>testRoundTo (in category 'tests') -----
- ----- Method: DurationTest>>testRoundTo (in category 'Tests') -----
testRoundTo
self assert: ((5 minutes + 37 seconds) roundTo: (2 minutes)) = (6 minutes).
self assert: (aDuration roundTo: (Duration days: 1)) =
(Duration days: 1 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0).
self assert: (aDuration roundTo: (Duration hours: 1)) =
(Duration days: 1 hours: 2 minutes: 0 seconds: 0 nanoSeconds: 0).
self assert: (aDuration roundTo: (Duration minutes: 1)) =
(Duration days: 1 hours: 2 minutes: 3 seconds: 0 nanoSeconds: 0).!
Item was changed:
+ ----- Method: DurationTest>>testSeconds (in category 'tests') -----
- ----- Method: DurationTest>>testSeconds (in category 'testing') -----
testSeconds
self assert: aDuration seconds = 4.
self assert: (Duration nanoSeconds: 2) seconds = 0.
self assert: (Duration nanoSeconds: 999999999) seconds = 0.
self assert: (Duration nanoSeconds: 1000000001) seconds = 1.
self assert: (Duration seconds: 2) seconds = 2.
self assert: (Duration days: 1 hours: 2 minutes: 3 seconds:4) seconds = 4.
self deny: (Duration days: 1 hours: 2 minutes: 3 seconds:4) seconds = (1*24*60*60+(2*60*60)+(3*60)+4). !
Item was changed:
+ ----- Method: DurationTest>>testSecondsNanoSeconds (in category 'tests') -----
- ----- Method: DurationTest>>testSecondsNanoSeconds (in category 'testing') -----
testSecondsNanoSeconds
self assert: (Duration seconds: 0 nanoSeconds: 5) = (Duration nanoSeconds: 5).
"not sure I should include in sunit since its Private "
self assert: (aDuration seconds: 0 nanoSeconds: 1) = (Duration nanoSeconds: 1).
!
Item was changed:
+ ----- Method: DurationTest>>testStoreOn (in category 'tests') -----
- ----- Method: DurationTest>>testStoreOn (in category 'testing') -----
testStoreOn
self assert: (aDuration storeOn: (WriteStream on:'')) asString ='1:02:03:04.000000005'.
"storeOn: returns a duration (self) not a stream"!
Item was changed:
+ ----- Method: DurationTest>>testTicks (in category 'tests') -----
- ----- Method: DurationTest>>testTicks (in category 'testing') -----
testTicks
self assert: aDuration ticks = #(1 7384 5)!
Item was changed:
+ ----- Method: DurationTest>>testTruncateTo (in category 'tests') -----
- ----- Method: DurationTest>>testTruncateTo (in category 'Tests') -----
testTruncateTo
self assert: ((5 minutes + 37 seconds) truncateTo: (2 minutes)) = (4 minutes).
self assert: (aDuration truncateTo: (Duration days: 1)) =
(Duration days: 1 hours: 0 minutes: 0 seconds: 0 nanoSeconds: 0).
self assert: (aDuration truncateTo: (Duration hours: 1)) =
(Duration days: 1 hours: 2 minutes: 0 seconds: 0 nanoSeconds: 0).
self assert: (aDuration truncateTo: (Duration minutes: 1)) =
(Duration days: 1 hours: 2 minutes: 3 seconds: 0 nanoSeconds: 0).!
Item was added:
+ ----- Method: DurationTest>>testWait (in category 'tests') -----
+ testWait
+
+ | start |
+ start := DateAndTime new.
+ (Duration milliseconds: 500) wait.
+ self assert: DateAndTime now - start > (Duration milliseconds: 500). !
Item was changed:
+ ----- Method: DurationTest>>testWeeks (in category 'tests') -----
- ----- Method: DurationTest>>testWeeks (in category 'testing') -----
testWeeks
self assert: (Duration weeks: 1) days= 7. !
Item was changed:
+ ----- Method: DurationTest>>testZero (in category 'tests') -----
- ----- Method: DurationTest>>testZero (in category 'testing') -----
testZero
self assert: (Duration zero) = (Duration seconds: 0). !
More information about the Squeak-dev
mailing list
|