Nicolas Cellier uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-nice.352.mcz ==================== Summary ==================== Name: CollectionsTests-nice.352 Author: nice Time: 3 March 2021, 10:34:45.83962 am UUID: 8666dc7b-f181-6340-97d4-be3d5a50166d Ancestors: CollectionsTests-nice.351 Separate the Interval of Float tests into LimitedPrecisionIntervalTest. Document a few more invalid expectations related to inexact nature of arithmetic on LimitedPrecisionInterval. =============== Diff against CollectionsTests-nice.351 =============== Item was removed: - ----- Method: IntervalTest>>expectedFailures (in category 'failures') ----- - expectedFailures - - ^ #(testIntervalOfFloatEqual)! Item was changed: ----- Method: IntervalTest>>testAsIntervalWithFractionalProgression (in category 'tests') ----- testAsIntervalWithFractionalProgression self assert: (1 to: 2 by: 1/2) equals: ({1. 3/2. 2} as: Interval). + self assert: (1 to: 2 by: 0.2s) equals: ({1. 1.2s. 1.4s. 1.6s. 1.8s. 2} as: Interval).! - self assert: (1 to: 2 by: 0.2s) equals: ({1. 1.2s. 1.4s. 1.6s. 1.8s. 2} as: Interval). - - self should: [#(0.1 0.2 0.3 0.4) as: Interval] - raise: Error - description: 'There is no guaranty that Interval of Float can be constructed from individual Float'. - "Even though, by chance there might be a Float Interval with same elements" - #(0.1 0.2 0.3 0.4) hasEqualElements: (0.1 to: 0.4 by: 0.1 predecessor)! Item was added: + ----- Method: IntervalTest>>testCollect (in category 'tests') ----- + testCollect + | s i | + i := (10 to: 20). + s := i collect: [:e | e]. + self assert: (s hasEqualElements: i)! Item was removed: - ----- Method: IntervalTest>>testElementOutOfBound (in category 'tests') ----- - testElementOutOfBound - self deny: ((1/5 to: 1.2 by: 1) anySatisfy: [:e | e > 1.2]).! Item was removed: - ----- Method: IntervalTest>>testIncludesBound (in category 'tests') ----- - testIncludesBound - "This interval is crafted for including 1.2 - but a careless definition of size might exclude this bound" - self assert: (((0.3 to: 1.2 by: 0.1) includes: 1.2) ==> [(0.3 to: 1.2 by: 0.1) anySatisfy: [:each | each = 1.2]]).! Item was removed: - ----- Method: IntervalTest>>testInclusion (in category 'tests') ----- - testInclusion - "Non regression test for another bug of fuzzy inclusion" - - self deny: ((1.0 to: 3.0 by: 1.0 successor) includes: 3.0) description: 'The last element of this Interval is closed to 2'! Item was removed: - ----- Method: IntervalTest>>testInclusionBug6455 (in category 'tests') ----- - testInclusionBug6455 - "This test is about mantis bug http://bugs.squeak.org/view.php?id=6455. - Well it's not a bug, and not a good feature. - See testSurprisingFuzzyInclusion for why this feature is not a good idea" - - self deny: ((0.2 to: 0.6 by: 0.1) includes: 0.3) description: 'Strict Float equality expecation is too high'. - self assert: ((0.2 to: 0.6 by: 0.1) includes: 0.3 successor) description: 'it includes a slightly different number'! Item was removed: - ----- Method: IntervalTest>>testIndexOfBug6455 (in category 'tests') ----- - testIndexOfBug6455 - "This test is about mantis bug http://bugs.squeak.org/view.php?id=6455 - Well it's not a bug, and not a good feature. - See testSurprisingFuzzyInclusion for why this feature is not a good idea" - - self deny: ((0.2 to: 0.6 by: 0.1) indexOf: 0.3) = 2 description: 'Strict Float equality expecation is too high'. - self assert: ((0.2 to: 0.6 by: 0.1) indexOf: 0.3 successor) = 2 description: 'it includes a slightly different number'! Item was removed: - ----- Method: IntervalTest>>testInfiniteLoopBug6456 (in category 'tests') ----- - testInfiniteLoopBug6456 - "This is a non regression test against mantis bug #6456. - Some Float interval size was not consistent with do: loop. - Some Float Interval used to do: infinite loops" - - | x interval counter size | - x := (1.0 timesTwoPower: Float precision). "Note: x+1 = x due to inexact arithmetic" - interval := x to: x+4. - size := interval size. - counter := 0. - interval do: [:each | self assert: (counter := counter + 1) <= size].! Item was removed: - ----- Method: IntervalTest>>testIntervalOfFloatEqual (in category 'tests') ----- - testIntervalOfFloatEqual - "Interval with Float are weirdos" - - | interval1 interval2 interval3 interval4 | - interval1 := (0 to: 1 by: 1/10). - interval2 := (0.0 to: 1 by: 1/10). - self deny: (interval1 = interval2) ==> (interval1 hasEqualElements: interval2) - description: 'Interval of Float may have different elements from another Interval, even if they pretend to be equal.'. - - interval3 := (0.3 to: 0.6 by: 1/10). - interval4 := (0.3 to: 0.6 by: 0.1). - self deny: (interval3 hasEqualElements: interval4) ==> (interval3 = interval4) - description: 'Interval of Float may pretend they differ from another Interval even if they have same elements.'.! Item was removed: - ----- Method: IntervalTest>>testIntervalOfFloatLast (in category 'tests') ----- - testIntervalOfFloatLast - "Some definition of last were problematic for Interval of Float" - - | increment upperBound interval | - self assert: (0.2 to: 0.9 by: 0.1) last = (0.2 to: 0.9 by: 0.1) asArray last - description: 'the last element cannot reasonably change when converting asArray'. - - upperBound := 1.7. - increment := 0.1. - self deny: (0 to: upperBound by: increment) last > upperBound - description: 'the last element cannot reasonably exceed upper bound'. - - interval := -0.9999999999999994 to: 1 by: 2. - self assert: interval last < interval first - ==> (interval isEmpty or: [interval increment < 0]) - description: 'the last element cannot reasonably deceed(*) lower bound (* be inferior to)'! Item was removed: - ----- Method: IntervalTest>>testIntervalOfFloatReversed (in category 'tests') ----- - testIntervalOfFloatReversed - self assert: (-16.3 to: 20.1 by: 1.3) reversed size - equals: (-16.3 to: 20.1 by: 1.3) size - description: 'reversed should preserve the size of a collection'. - self assert: (0.1 to: 0.9 by: 0.1) reversed asArray - equals: (0.1 to: 0.9 by: 0.1) asArray reversed - description: 'reversed should preserve the elements of a collection'.! Item was changed: ----- Method: IntervalTest>>testPermutationsDo (in category 'tests') ----- testPermutationsDo | i oc | + i := (4 to: 13 by: 3). - i := (1.234 to: 4.234). oc := OrderedCollection new. + i permutationsDo: [:e | oc add: e copy]. + self assert: oc size = i size factorial. + self assert: oc asSet size = oc size. + self assert: (oc allSatisfy: [:e | e sorted hasEqualElements: i]). - i permutationsDo: [:e | oc add: e]. - self assert: (oc size = i size factorial). ^ oc! Item was changed: ----- Method: IntervalTest>>testRangeIncludes (in category 'tests') ----- testRangeIncludes + self assert: ((1 to: 10) rangeIncludes: 4) description: '4 is within this range'. + self assert: ((1 to: 10 by: 2) rangeIncludes: 4) description: 'even if the interval does not include 4'. + self deny: ((1 to: 10 by: -1) rangeIncludes: 4) description: 'this range is empty'. + self assert: ((10 to: 1 by: -4) rangeIncludes: 4) description: 'the range can be retrograde'. + self assert: ((1 to: 10) rangeIncludes: 10) description: 'the range includes the bounds'. + self assert: ((1 to: 10 by: 2) rangeIncludes: 10) description: 'even when bound lies past the last element'. + #(0 11) do: [:outOfBound | + #(-2 -1 2 2) do: [:step | + self deny: ((1 to: 10 by: step) includes: outOfBound)]]! - self - assert: ((1 to: 10) - rangeIncludes: 3). - self - assert: ((1 to: 10 by: 2) - rangeIncludes: 3). - self - deny: ((1 to: 10) - rangeIncludes: 0). - self - deny: ((1 to: 10) - rangeIncludes: 11). - self - deny: ((1 to: 10 by: 2) - rangeIncludes: 0). - self - deny: ((1 to: 10 by: 2) - rangeIncludes: 11)! Item was removed: - ----- Method: IntervalTest>>testSurprisingFuzzyInclusionBehavior (in category 'tests') ----- - testSurprisingFuzzyInclusionBehavior - "If ever Interval implement fuzzy inclusion, then we can expect weird logic..." - self assert: ((0.1 to: 0.9 by: 0.1) includes: 0.3) - ==> (((0.1 to: 0.9 by: 0.1) occurrencesOf: 0.3) > 0) - description: 'A Collection that includes something has at least one occurrence of something'. - self assert: ((0.1 to: 0.9 by: 0.1) lastIndexOf: 0.3) - >= ((0.1 to: 0.9 by: 0.1) indexOf: 0.3) - description: 'The last index of an object in a SequenceableCollection should be greater than or equal to the first index'. - self assert: ((0.1 to: 0.9 by: 0.1) includes: 0.3) - ==> (((0.1 to: 0.9 by: 0.1) copyWithout: 0.3) size < (0.1 to: 0.9 by: 0.1) size) - description: 'A Collection should be able to shrink by stripping own elements'.! Item was added: + ClassTestCase subclass: #LimitedPrecisionIntervalTest + instanceVariableNames: '' + classVariableNames: '' + poolDictionaries: '' + category: 'CollectionsTests-Sequenceable'! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>assert:is:withinUlp: (in category 'asserting - extensions') ----- + assert: aFloat is: anotherFloat withinUlp: anInteger + ^self assert: (aFloat - anotherFloat) abs <= (aFloat ulp * anInteger)! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>expectedFailures (in category 'failures') ----- + expectedFailures + + ^ #(testIntervalOfFloatEqual)! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testAdd (in category 'tests') ----- + testAdd + | floatInterval | + floatInterval := (0.3 to: 0.6 by: 0.1). + self deny: floatInterval size = (floatInterval + 1) size description: 'there is no guaranty that size is preserved by arithmetic operation'! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testAsIntervalWithFractionalProgression (in category 'tests') ----- + testAsIntervalWithFractionalProgression + self should: [#(0.1 0.2 0.3 0.4) as: Interval] + raise: Error + description: 'There is no guaranty that Interval of Float can be constructed from individual Float'. + "Even though, by chance there might be a Float Interval with same elements" + #(0.1 0.2 0.3 0.4) hasEqualElements: (0.1 to: 0.4 by: 0.1 predecessor)! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testCollect (in category 'tests') ----- + testCollect + | s i | + i := (0.1 to: 1.0 by: 0.1). + s := i collect: [:e | e]. + self assert: (s hasEqualElements: i)! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testDo (in category 'tests') ----- + testDo + | s i | + s := OrderedCollection new. + i := (0.1 to: 1.0 by: 0.1). + i do: [ :each | s addLast: each]. + self assert: (s hasEqualElements: i)! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testElementOutOfBound (in category 'tests') ----- + testElementOutOfBound + "Note: this is a test for correct implementation of size. + With super definition of size, an element past the bound could be included" + + self deny: ((1/5 to: 1.2 by: 1) anySatisfy: [:e | e > 1.2]).! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testIncludesBound (in category 'tests') ----- + testIncludesBound + "This interval is crafted for including 1.2 + but a careless definition of size might exclude this bound" + self assert: (((0.3 to: 1.2 by: 0.1) includes: 1.2) ==> [(0.3 to: 1.2 by: 0.1) anySatisfy: [:each | each = 1.2]]).! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testInclusion (in category 'tests') ----- + testInclusion + "Non regression test for another bug of fuzzy inclusion" + + self deny: ((1.0 to: 3.0 by: 1.0 successor) includes: 3.0) description: 'The last element of this Interval is closed to 2'! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testInclusionBug6455 (in category 'tests') ----- + testInclusionBug6455 + "This test is about mantis bug http://bugs.squeak.org/view.php?id=6455. + Well it's not a bug, and not a good feature. + See testSurprisingFuzzyInclusion for why this feature is not a good idea" + + self deny: ((0.2 to: 0.6 by: 0.1) includes: 0.3) description: 'Strict Float equality expecation is too high'. + self assert: ((0.2 to: 0.6 by: 0.1) includes: 0.3 successor) description: 'it includes a slightly different number'! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testIndexOfBug6455 (in category 'tests') ----- + testIndexOfBug6455 + "This test is about mantis bug http://bugs.squeak.org/view.php?id=6455 + Well it's not a bug, and not a good feature. + See testSurprisingFuzzyInclusion for why this feature is not a good idea" + + self deny: ((0.2 to: 0.6 by: 0.1) indexOf: 0.3) = 2 description: 'Strict Float equality expecation is too high'. + self assert: ((0.2 to: 0.6 by: 0.1) indexOf: 0.3 successor) = 2 description: 'it includes a slightly different number'! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testInfiniteLoopBug6456 (in category 'tests') ----- + testInfiniteLoopBug6456 + "This is a non regression test against mantis bug #6456. + Some Float interval size was not consistent with do: loop. + Some Float Interval used to do: infinite loops" + + | x interval counter size | + x := (1.0 timesTwoPower: Float precision). "Note: x+1 = x due to inexact arithmetic" + interval := x to: x+4. + size := interval size. + counter := 0. + interval do: [:each | self assert: (counter := counter + 1) <= size].! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testIntervalOfFloatEqual (in category 'tests') ----- + testIntervalOfFloatEqual + "Interval with Float are weirdos" + + | interval1 interval2 interval3 interval4 | + interval1 := (0 to: 1 by: 1/10). + interval2 := (0.0 to: 1 by: 1/10). + self deny: (interval1 = interval2) ==> (interval1 hasEqualElements: interval2) + description: 'Interval of Float may have different elements from another Interval, even if they pretend to be equal.'. + + interval3 := (0.3 to: 0.6 by: 1/10). + interval4 := (0.3 to: 0.6 by: 0.1). + self deny: (interval3 hasEqualElements: interval4) ==> (interval3 = interval4) + description: 'Interval of Float may pretend they differ from another Interval even if they have same elements.'.! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testLast (in category 'tests') ----- + testLast + "Some definition of last were problematic for Interval of Float" + + | increment upperBound interval | + self assert: (0.2 to: 0.9 by: 0.1) last = (0.2 to: 0.9 by: 0.1) asArray last + description: 'the last element cannot reasonably change when converting asArray'. + + upperBound := 1.7. + increment := 0.1. + self deny: (0 to: upperBound by: increment) last > upperBound + description: 'the last element cannot reasonably exceed upper bound'. + + interval := -0.9999999999999994 to: 1 by: 2. + self assert: interval last < interval first + ==> (interval isEmpty or: [interval increment < 0]) + description: 'the last element cannot reasonably deceed(*) lower bound (* be inferior to)'! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testReversed (in category 'tests') ----- + testReversed + self assert: (-16.3 to: 20.1 by: 1.3) reversed size + equals: (-16.3 to: 20.1 by: 1.3) size + description: 'reversed should preserve the size of a collection'. + self assert: (0.1 to: 0.9 by: 0.1) reversed asArray + equals: (0.1 to: 0.9 by: 0.1) asArray reversed + description: 'reversed should preserve the elements of a collection'.! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testSum (in category 'tests') ----- + testSum + | floatInterval | + floatInterval := 0.1 to: 1.0 by: 0.1. + self deny: floatInterval sum = floatInterval asArray sum description: 'do not expect strict Float equality after arithmetic operations'. + self assert: floatInterval sum is: floatInterval asArray sum withinUlp: floatInterval size / 2! Item was added: + ----- Method: LimitedPrecisionIntervalTest>>testSurprisingFuzzyInclusionBehavior (in category 'tests') ----- + testSurprisingFuzzyInclusionBehavior + "If ever Interval implement fuzzy inclusion, then we can expect weird logic..." + self assert: ((0.1 to: 0.9 by: 0.1) includes: 0.3) + ==> (((0.1 to: 0.9 by: 0.1) occurrencesOf: 0.3) > 0) + description: 'A Collection that includes something has at least one occurrence of something'. + self assert: ((0.1 to: 0.9 by: 0.1) lastIndexOf: 0.3) + >= ((0.1 to: 0.9 by: 0.1) indexOf: 0.3) + description: 'The last index of an object in a SequenceableCollection should be greater than or equal to the first index'. + self assert: ((0.1 to: 0.9 by: 0.1) includes: 0.3) + ==> (((0.1 to: 0.9 by: 0.1) copyWithout: 0.3) size < (0.1 to: 0.9 by: 0.1) size) + description: 'A Collection should be able to shrink by stripping own elements'.! |
Free forum by Nabble | Edit this page |