Nicolas Cellier uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-nice.305.mcz ==================== Summary ==================== Name: CollectionsTests-nice.305 Author: nice Time: 7 April 2019, 10:28:19.324177 pm UUID: 62b39b3b-abb9-43d1-aa10-dbf15359c36b Ancestors: CollectionsTests-nice.304 More and Less Interval tests - Part 2 - cleanup the testEquals * remove redundant test vs Array: a single #testEqualsWithArray is enough * make an explicit testEqualsWhenEmpty for empty Interval equality. This is a feature required for Text selection support. An empty Interval is used for marking cursor position when Text selection is empty. - It should be possible to convert an Array with fractional arithmetic progression as Interval (#testAsIntervalWithFractionalProgression), though it's currently not the case at this time of writing - add a case of surprising fuzzy-inclusion behavior (copyWithout:) - document two additional weird behaviors of Interval of Float: * testIntervalOfFloatEqual denies the common sense, and thus currently does not fail. It could as well assert and be an expected failure, but we will probably not resolve it. * testIntervalOfFloatLast fails if last is not corrected. Unlike equal, it seems possible to resolve while preserving other Interval properties =============== Diff against CollectionsTests-nice.304 =============== Item was added: + ----- 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 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 changed: ----- Method: IntervalTest>>testEquals (in category 'tests') ----- testEquals + self assert: (3 to: 5) = (3.0 to: 5.0). + self deny: (3 to: 5) = (3 to: 5 by: 2) description: 'Sharing bounds is not enough to make Interval equals'.! - self deny: (3 to: 5) = #(3 4 5). - self deny: (3 to: 5) = #(3 5). - self deny: (3 to: 5) = #(). - - self deny: #(3 4 5) = (3 to: 5). - self deny: #(3 5) = (3 to: 5). - self deny: #() = (3 to: 5).! Item was removed: - ----- Method: IntervalTest>>testEquals4 (in category 'tests') ----- - testEquals4 - - self deny: (3 to: 5 by: 2) = #(3 5). - self deny: (3 to: 5 by: 2) = #(3 4 5). - self deny: (3 to: 5 by: 2) = #(). - - self deny: #(3 5) = (3 to: 5 by: 2). - self deny: #(3 4 5) = (3 to: 5 by: 2). - self deny: #() = (3 to: 5 by: 2).! Item was added: + ----- Method: IntervalTest>>testEqualsWhenEmpty (in category 'tests') ----- + testEqualsWhenEmpty + self assert: (3 to: 2) = (3 to: 2) copy. + self deny: (3 to: 2) = (2 to: 1) + description: 'Empty intervals are considered different if their bound differs. Text selection rely on this feature'.! Item was added: + ----- Method: IntervalTest>>testEqualsWithArray (in category 'tests') ----- + testEqualsWithArray + "Intervals are not considered equal to Array, even if they share the same sequence of elements." + self deny: (3 to: 5) = #(3 4 5). + self deny: #(3 4 5) = (3 to: 5).! Item was added: + ----- 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 added: + ----- 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 changed: ----- 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) - self assert: ((0.1 to: 0.9 by: 0.1) asArray 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'.! - description: 'If the last index of an object in a SequenceableCollection should be greater or equal to the first index'.! |
Free forum by Nabble | Edit this page |