The Trunk: CollectionsTests-nice.285.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: CollectionsTests-nice.285.mcz

commits-2
Nicolas Cellier uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-nice.285.mcz

==================== Summary ====================

Name: CollectionsTests-nice.285
Author: nice
Time: 30 November 2017, 9:25:14.59936 pm
UUID: e50f181d-41a8-428f-ba63-b370998aac7d
Ancestors: CollectionsTests-nice.284

Tests for (Wide)CharacterSet(Complement)

- add tests for intersection: and union:
- don't (ab)use should: when assert: could do it
- add tests for awfully broken complement select:/reject:

=============== Diff against CollectionsTests-nice.284 ===============

Item was added:
+ ----- Method: CharacterSetComplementTest>>testIncludes (in category 'testing') -----
+ testIncludes
+ | set complement |
+ set := 'abc' as: CharacterSet.
+ complement := set complement.
+ self assert: (set noneSatisfy: [:e | complement includes: e]).
+ self assert: (($d to: $z) allSatisfy: [:e | complement includes: e]).!

Item was added:
+ ----- Method: CharacterSetComplementTest>>testReject (in category 'testing') -----
+ testReject
+ | set complement subset |
+ set := 'abc' as: CharacterSet.
+ complement := set complement.
+ subset := complement reject: [:c | c isVowel].
+ self assert: (subset includes: $z). "Not a vowel, it is in the subset"
+ self deny: (subset includes: $e). "a vowel should be rejected"
+ self deny: (subset includes: $b). "Not a vowel, but not in the original set"!

Item was added:
+ ----- Method: CharacterSetComplementTest>>testSelect (in category 'testing') -----
+ testSelect
+ | set complement digits |
+ set := 'abc012' as: CharacterSet.
+ complement := set complement.
+ digits := complement select: [:c | c isDigit].
+ self assert: (digits includes: $9).
+ self deny: (digits includes: $1).
+ self deny: (digits includes: $z).!

Item was added:
+ ----- Method: CharacterSetTest>>testComplement (in category 'testing') -----
+ testComplement
+ | set complement |
+ set := 'abc' as: CharacterSet.
+ complement := set complement.
+ self assert: (set noneSatisfy: [:e | complement includes: e]).
+ self assert: (($d to: $z) allSatisfy: [:e | complement includes: e]).!

Item was changed:
  ----- Method: CharacterSetTest>>testCopy (in category 'testing') -----
  testCopy
      | theOriginal theCopy |
      theOriginal := CharacterSet newFrom: 'abc'.
      theCopy := theOriginal copy.
      theCopy remove: $a.
+     ^self assert: (theOriginal includes: $a) description: 'Changing the copy should not change the original'.!
-     ^self should: [theOriginal includes: $a] description: 'Changing the copy should not change the original'.!

Item was added:
+ ----- Method: CharacterSetTest>>testIncludes (in category 'testing') -----
+ testIncludes
+ | set |
+ set := 'abc' as: CharacterSet.
+ self assert: (($a to: $c) allSatisfy: [:e | set includes: e]).
+ self assert: (($d to: $z) noneSatisfy: [:e | set includes: e]).!

Item was added:
+ ----- Method: CharacterSetTest>>testIntersection (in category 'testing') -----
+ testIntersection
+ | intersection |
+ intersection := ('abc' as: CharacterSet) intersection: ('bcde' as: CharacterSet).
+ self assert: intersection = ('bc' as: CharacterSet)!

Item was added:
+ ----- Method: CharacterSetTest>>testIntersectionWithComplement (in category 'testing') -----
+ testIntersectionWithComplement
+ | intersection intersection2 |
+ intersection := ('abcd' as: CharacterSet) intersection: ('cdef' as: CharacterSet) complement.
+ self assert: intersection = ('ab' as: CharacterSet).
+ intersection2 := ('cdef' as: CharacterSet) complement intersection: ('abcd' as: CharacterSet).
+ self assert: intersection2 = intersection. "Intersection is symmetric"!

Item was added:
+ ----- Method: CharacterSetTest>>testUnion (in category 'testing') -----
+ testUnion
+ | union |
+ union := ('abc' as: CharacterSet) union: ('bcde' as: CharacterSet).
+ self assert: union = ('abcde' as: CharacterSet)!

Item was added:
+ ----- Method: CharacterSetTest>>testUnionWithComplement (in category 'testing') -----
+ testUnionWithComplement
+ | union union2 |
+ union := ('abc' as: CharacterSet) union: ('bcde' as: CharacterSet) complement.
+ self assert: union = ('de' as: CharacterSet) complement.
+ union2 := ('bcde' as: CharacterSet) complement union: ('abc' as: CharacterSet).
+ self assert: union2 = union. "union is symmetric"!

Item was changed:
  ----- Method: WideCharacterSetTest>>testAddingToCharacterSet (in category 'testing') -----
  testAddingToCharacterSet
 
  | cs wcs wc |
  cs := CharacterSet newFrom: 'aeiouy'.
  wcs := cs copy.
  wc := 4452 asCharacter.
 
  self shouldnt: [wcs add: wc] raise: Error description: 'adding a WideCharacter to an ordinary CharacterSet should turn it into a WideCharacterSet'.
 
+ self assert: (wcs size = (cs size + 1)) description: 'We just added a Character, size should be increased by one'.
+ self deny: (wcs = cs) description: 'We just added a Character, sets should not be equal'.
+ self deny: (cs = wcs) description: 'We just added a Character, sets should not be equal'.
+ self assert: (cs allSatisfy: [:char | wcs includes: char]) description: 'Each character of the original CharacterSet should be included in the WideCharacterSet'.
+ self assert: (wcs hasWideCharacters) description: 'We just added a WideCharacter, so this WideCharacterSet definitely has one'.
+ self assert: (wcs includes: wc) description: 'We just added this WideCharacter, so this WideCharacterSet should include it'.
- self should: [wcs size = (cs size + 1)] description: 'We just added a Character, size should be increased by one'.
- self shouldnt: [wcs = cs] description: 'We just added a Character, sets should not be equal'.
- self shouldnt: [cs = wcs] description: 'We just added a Character, sets should not be equal'.
- self should: [cs allSatisfy: [:char | wcs includes: char]] description: 'Each character of the original CharacterSet should be included in the WideCharacterSet'.
- self should: [wcs hasWideCharacters] description: 'We just added a WideCharacter, so this WideCharacterSet definitely has one'.
- self should: [wcs includes: wc] description: 'We just added this WideCharacter, so this WideCharacterSet should include it'.
 
  wcs add: wc.
+ self assert: (wcs size = (cs size + 1)) description: 'We just added a Character already included in the set, size should be unchanged'.
- self should: [wcs size = (cs size + 1)] description: 'We just added a Character already included in the set, size should be unchanged'.
 
  wcs remove: wc.
+ self assert: (wcs size = cs size) description: 'We added then removed a Character, now size should be equal to original'.
+ self deny: (wcs hasWideCharacters) description: 'We just removed the only WideCharacter, so this WideCharacterSet definitely has no WideCharacter'.
- self should: [wcs size = cs size] description: 'We added then removed a Character, now size should be equal to original'.
- self shouldnt: [wcs hasWideCharacters] description: 'We just removed the only WideCharacter, so this WideCharacterSet definitely has no WideCharacter'.
 
+ self assert: (wcs = cs) description: 'A WideCharacterSet can be equal to an Ordinary CharacterSet'.
+ self assert: (cs = wcs) description: 'An ordinary CharacterSet can be equal to a WideCharacterSet'.
+ self assert: (cs hash = wcs hash) description: 'If some objects are equal, then they should have same hash code'.
- self should: [wcs = cs] description: 'A WideCharacterSet can be equal to an Ordinary CharacterSet'.
- self should: [cs = wcs] description: 'An ordinary CharacterSet can be equal to a WideCharacterSet'.
- self should: [cs hash = wcs hash] description: 'If some objects are equal, then they should have same hash code'.
 
  !

Item was changed:
  ----- Method: WideCharacterSetTest>>testCreation (in category 'testing') -----
  testCreation
  "By now, only creation method is newFrom:"
 
  | cs1 wcs1 cs2 wcs2 byteString wideString |
  byteString := 'aeiouy'.
  wideString := 'aeiouy' copyWith: 340 asCharacter.
 
  cs1 := CharacterSet newFrom: byteString.
  wcs1 := WideCharacterSet newFrom: byteString.
+ self assert: (wcs1 = cs1).
+ self assert: (wcs1 size = byteString "asSet" size).
- self should: [wcs1 = cs1].
- self should: [wcs1 size = byteString "asSet" size].
 
  cs2 := CharacterSet newFrom: wideString.
  wcs2 := WideCharacterSet newFrom: wideString.
+ self assert: (wcs2 = cs2).
+ self assert: (wcs2 size = wideString "asSet" size).
- self should: [wcs2 = cs2].
- self should: [wcs2 size = wideString "asSet" size].
 
+ self assert: ((byteString indexOfAnyOf: wcs1) = 1) description: 'This should used optimized byteArrayMap method'.
+ self assert: ((byteString indexOfAnyOf: wcs2) = 1) description: 'This should used optimized byteArrayMap method'.
- self should: [(byteString indexOfAnyOf: wcs1) = 1] description: 'This should used optimized byteArrayMap method'.
- self should: [(byteString indexOfAnyOf: wcs2) = 1] description: 'This should used optimized byteArrayMap method'.
 
+ self assert: (('bcd' indexOfAnyOf: wcs1) = 0) description: 'This should used optimized byteArrayMap method'.
+ self assert: (('bcd' indexOfAnyOf: wcs2) = 0) description: 'This should used optimized byteArrayMap method'.!
- self should: [('bcd' indexOfAnyOf: wcs1) = 0] description: 'This should used optimized byteArrayMap method'.
- self should: [('bcd' indexOfAnyOf: wcs2) = 0] description: 'This should used optimized byteArrayMap method'.!


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: CollectionsTests-nice.285.mcz

Tobias Pape
Hey,


> On 30.11.2017, at 21:25, [hidden email] wrote:
>
> Nicolas Cellier uploaded a new version of CollectionsTests to project The Trunk:
> http://source.squeak.org/trunk/CollectionsTests-nice.285.mcz
>
> ==================== Summary ====================
>
> Name: CollectionsTests-nice.285
> Author: nice
> Time: 30 November 2017, 9:25:14.59936 pm
> UUID: e50f181d-41a8-428f-ba63-b370998aac7d
> Ancestors: CollectionsTests-nice.284
>
> Tests for (Wide)CharacterSet(Complement)
>
> - add tests for intersection: and union:
> - don't (ab)use should: when assert: could do it

Can you explain that for me?

Best regards
        -Tobias

Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: CollectionsTests-nice.285.mcz

Nicolas Cellier


2017-11-30 22:02 GMT+01:00 Tobias Pape <[hidden email]>:
Hey,


> On 30.11.2017, at 21:25, [hidden email] wrote:
>
> Nicolas Cellier uploaded a new version of CollectionsTests to project The Trunk:
> http://source.squeak.org/trunk/CollectionsTests-nice.285.mcz
>
> ==================== Summary ====================
>
> Name: CollectionsTests-nice.285
> Author: nice
> Time: 30 November 2017, 9:25:14.59936 pm
> UUID: e50f181d-41a8-428f-ba63-b370998aac7d
> Ancestors: CollectionsTests-nice.284
>
> Tests for (Wide)CharacterSet(Complement)
>
> - add tests for intersection: and union:
> - don't (ab)use should: when assert: could do it

Can you explain that for me?

Best regards
        -Tobias

Hi Tobias,
certainly: a block shall be used to differ evaluation for various purposes like:
- evaluate an expression conditionnally
- evaluate an expression iteratively
- evaluate preconditions/postconditions like in showWhile: , ensure: , exception protection (ifError: , on:do:), interruption protection (critical:) etc...

If we do not need to differ evaluation, then we should not use a Block.
In SUnit TestCase, a Block is usefull for catching exception (should:raise: shouldnt:raise:).

But (aTestCase should: [self doSomething]) is an un-necessary usage of Block, because there's absolutely no interest in differing evaluation.
It does not bring anything compared to (aTestCase assert: self doSomething).

I think that I used should: because I did like the name better than assert:

Also since you ask, I see that I left a (self shouldnt: [self doSomething] raise: Error) which can also be considered a Bad Style (TM), because catching too wide!
This is already covered by (self assert: self doSomething).



Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: CollectionsTests-nice.285.mcz

Tobias Pape
Hi Nicolas,

> On 30.11.2017, at 22:21, Nicolas Cellier <[hidden email]> wrote:
>
>
>
> 2017-11-30 22:02 GMT+01:00 Tobias Pape <[hidden email]>:
> Hey,
>
>
> > On 30.11.2017, at 21:25, [hidden email] wrote:
> >
> > Nicolas Cellier uploaded a new version of CollectionsTests to project The Trunk:
> > http://source.squeak.org/trunk/CollectionsTests-nice.285.mcz
> >
> > ==================== Summary ====================
> >
> > Name: CollectionsTests-nice.285
> > Author: nice
> > Time: 30 November 2017, 9:25:14.59936 pm
> > UUID: e50f181d-41a8-428f-ba63-b370998aac7d
> > Ancestors: CollectionsTests-nice.284
> >
> > Tests for (Wide)CharacterSet(Complement)
> >
> > - add tests for intersection: and union:
> > - don't (ab)use should: when assert: could do it
>
> Can you explain that for me?
>
> Best regards
>         -Tobias
>
> Hi Tobias,
> certainly: a block shall be used to differ evaluation for various purposes like:
> - evaluate an expression conditionnally
> - evaluate an expression iteratively
> - evaluate preconditions/postconditions like in showWhile: , ensure: , exception protection (ifError: , on:do:), interruption protection (critical:) etc...
>
> If we do not need to differ evaluation, then we should not use a Block.
> In SUnit TestCase, a Block is usefull for catching exception (should:raise: shouldnt:raise:).
>
> But (aTestCase should: [self doSomething]) is an un-necessary usage of Block, because there's absolutely no interest in differing evaluation.
> It does not bring anything compared to (aTestCase assert: self doSomething).
>
> I think that I used should: because I did like the name better than assert:
>
> Also since you ask, I see that I left a (self shouldnt: [self doSomething] raise: Error) which can also be considered a Bad Style (TM), because catching too wide!
> This is already covered by (self assert: self doSomething).
>

Thanks for that comprehensive explanation!
I now understand what you mean and mostly agree :)

Best regards
        -Tobias