Discussion:
The Inbox: CollectionsTests-ul.297.mcz
(too old to reply)
c***@source.squeak.org
0000-12-06 18:12:22 UTC
Permalink
Levente Uzonyi uploaded a new version of CollectionsTests to project The Inbox:
http://source.squeak.org/inbox/CollectionsTests-ul.297.mcz

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

Name: CollectionsTests-ul.297
Author: ul
Time: 5 December 2018, 7:09:15.652659 pm
UUID: d9e8623a-138b-48b5-becd-a18225a4eb4d
Ancestors: CollectionsTests-cbc.296

Added tests for OrderedSet forged from SetTest and OrderedDictionaryTest.

=============== Diff against CollectionsTests-cbc.296 ===============

Item was added:
+ ClassTestCase subclass: #OrderedSetTest
+ instanceVariableNames: 'full empty'
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'CollectionsTests-Unordered'!
+
+ !OrderedSetTest commentStamp: '<historical>' prior: 0!
+ This is the unit test for the class Set. Unit tests are a good way to exercise the functionality of your system in a repeatable and automatic manner. They are therefore recommended if you plan to release anything. For more information, see:
+ - http://www.c2.com/cgi/wiki?UnitTest
+ - http://minnow.cc.gatech.edu/squeak/1547
+ - the sunit class category!

Item was added:
+ ----- Method: OrderedSetTest>>setUp (in category 'running') -----
+ setUp
+ empty := OrderedSet new.
+ full := OrderedSet with: 5 with: #abc!

Item was added:
+ ----- Method: OrderedSetTest>>tearDown (in category 'running') -----
+ tearDown
+ "I am called whenever your test ends.
+ I am the place where you release the ressources"!

Item was added:
+ ----- Method: OrderedSetTest>>testAdd (in category 'Sunit original tests') -----
+ testAdd
+ empty add: 5.
+ self assert: (empty includes: 5).!

Item was added:
+ ----- Method: OrderedSetTest>>testAddWithOccurences (in category 'tests') -----
+ testAddWithOccurences
+
+ empty add: 2 withOccurrences: 3.
+ self assert: (empty includes: 2).
+ self assert: ((empty occurrencesOf: 2) = 1).!

Item was added:
+ ----- Method: OrderedSetTest>>testAsSet (in category 'tests') -----
+ testAsSet
+ "could be moved in Array or Collection"
+
+ | newFull |
+ newFull := #(#abc 5) as: OrderedSet.
+ newFull add: 5.
+ self assert: (newFull = full).!

Item was added:
+ ----- Method: OrderedSetTest>>testAtIndex (in category 'tests - accessing') -----
+ testAtIndex
+
+ 1 to: 10 do: [:ea |
+ empty add: ea].
+
+ 1 to: 10 do: [:index |
+ self assert: index equals: (empty atIndex: index)].!

Item was added:
+ ----- Method: OrderedSetTest>>testAtRandom (in category 'tests') -----
+ testAtRandom
+ | rand |
+ rand := Random new.
+ full add: 3.
+ full add: 2.
+ full add: 4.
+ full add: 1.
+ self assert: (full includes: (full atRandom: rand)).
+ !

Item was added:
+ ----- Method: OrderedSetTest>>testCollectAs (in category 'tests') -----
+ testCollectAs
+ | newFull result |
+ newFull := OrderedSet withAll: (1 to: 10).
+ result := newFull collect: [:each | each >= 1 ifTrue: [each] ifFalse: ['no']] as: OrderedSet.
+ self assert: (result = newFull).
+ result := newFull collect: [:each | each >= 5 ifTrue: [each] ifFalse: ['no']] as: OrderedSet.
+ self assert: (result = ((OrderedSet withAll: (5 to: 10)) add: 'no'; yourself)).!

Item was added:
+ ----- Method: OrderedSetTest>>testCompact (in category 'tests') -----
+ testCompact
+ "Eager compacting on removal."
+
+ 1 to: 3 do: [:ea | empty add: ea].
+ empty remove: 2.
+ self assert: 2 equals: (empty instVarNamed: #order) size.!

Item was added:
+ ----- Method: OrderedSetTest>>testCopy (in category 'tests - copying') -----
+ testCopy
+ | newFull |
+ full add: 3.
+ full add: 2.
+ newFull := full copy.
+ self assert: (full size = newFull size).
+ self assert: ((full select: [:each | (newFull includes: each) not]) isEmpty).
+ self assert: ((newFull select: [:each | (full includes: each) not]) isEmpty).!

Item was added:
+ ----- Method: OrderedSetTest>>testCopy2 (in category 'tests - copying') -----
+ testCopy2
+
+ empty
+ add: 1;
+ add: 2;
+ add: 3.
+
+ empty copy in: [:copy |
+ self assert: empty equals: copy.
+ copy add: 4.
+ self assert: empty size < copy size]!

Item was added:
+ ----- Method: OrderedSetTest>>testCopyFirst (in category 'tests - accessing') -----
+ testCopyFirst
+
+ 1 to: 10 do: [:ea |
+ empty add: ea].
+
+ self assert: (1 to: 5) asArray equals: (empty first: 5) asArray.!

Item was added:
+ ----- Method: OrderedSetTest>>testCopyFromTo (in category 'tests - copying') -----
+ testCopyFromTo
+
+ 1 to: 10 do: [:index |
+ empty add: index].
+
+ (empty copyFrom: 3 to: 5) in: [:copy |
+ self assert: (3 to: 5) asArray equals: copy asArray.
+ self assert: 3 equals: copy removeFirst.
+ self
+ deny: (copy includes: 3);
+ assert: (empty includes: 3) ]!

Item was added:
+ ----- Method: OrderedSetTest>>testCopyLast (in category 'tests - accessing') -----
+ testCopyLast
+
+ 1 to: 10 do: [:ea |
+ empty add: ea].
+
+ self assert: (6 to: 10) asArray equals: (empty last: 5) asArray.!

Item was added:
+ ----- Method: OrderedSetTest>>testCopyWithout (in category 'tests') -----
+ testCopyWithout
+ | newFull |
+ full add: 3.
+ full add: 2.
+ newFull := full copyWithout: 3.
+ self assert: (newFull size = (full size - 1)).
+ self deny: (newFull includes: 3).
+ self assert: ((newFull select: [:each | (full includes: each) not]) isEmpty).
+ self assert: ((full select: [:each | (newFull includes: each) not]) = (OrderedSet with: 3)).
+ !

Item was added:
+ ----- Method: OrderedSetTest>>testDo (in category 'tests') -----
+ testDo
+ | newFull result |
+ newFull := OrderedSet withAll: (1 to: 5).
+ result := 0.
+ newFull do: [:each | result := (result + each)].
+ self assert: (result = 15).!

Item was added:
+ ----- Method: OrderedSetTest>>testFirst (in category 'tests - accessing') -----
+ testFirst
+
+ 1 to: 10 do: [:ea |
+ empty add: ea].
+
+ #(first second third fourth fifth sixth seventh eighth ninth last) withIndexDo: [:selector :index |
+ self assert: index equals: (empty perform: selector) ].!

Item was added:
+ ----- Method: OrderedSetTest>>testGrow (in category 'Sunit original tests') -----
+ testGrow
+ empty addAll: (1 to: 100).
+ self assert: (empty size = 100).
+ !

Item was added:
+ ----- Method: OrderedSetTest>>testIfAbsentAdd (in category 'Sunit original tests') -----
+ testIfAbsentAdd
+ | it |
+ it := 5.
+ self deny: (empty includes: it).
+ self assert: (empty ifAbsentAdd: it).
+ self assert: (empty includes: it).
+ self deny: (empty ifAbsentAdd: it).
+ self assert: (empty includes: it)!

Item was added:
+ ----- Method: OrderedSetTest>>testIllegal (in category 'Sunit original tests') -----
+ testIllegal
+ self
+ should: [empty at: 5] raise: TestResult error.
+ self
+ should: [empty at: 5 put: #abc] raise: TestResult error.
+ !

Item was added:
+ ----- Method: OrderedSetTest>>testIncludes (in category 'Sunit original tests') -----
+ testIncludes
+ self assert: (full includes: 5).
+ self assert: (full includes: #abc).
+ self deny: (full includes: 3).
+ !

Item was added:
+ ----- Method: OrderedSetTest>>testIntersection (in category 'tests') -----
+ testIntersection
+ | newFull col |
+ full add: 3; add: 2.
+ col := full intersection: full.
+ self assert: (full = col).
+
+ newFull := OrderedSet with: 8 with: 9 with: #z.
+ col := newFull intersection: full.
+ self assert: (col isEmpty).
+
+ newFull add: 5; add: #abc; add: 7.
+ col := newFull intersection: full.
+ self assert: ((full select: [:each | (newFull includes: each)]) = col).
+
+
+ !

Item was added:
+ ----- Method: OrderedSetTest>>testIsSorted (in category 'tests - sorting') -----
+ testIsSorted
+
+ 10 to: 1 by: -1 do: [:ea |
+ empty add: ea].
+
+ self deny: empty isSorted.
+ empty sort.
+ self assert: empty isSorted!

Item was added:
+ ----- Method: OrderedSetTest>>testLike (in category 'tests') -----
+ testLike
+ self assert: ((full like: 5) = 5).
+ self assert: ((full like: 8) isNil).!

Item was added:
+ ----- Method: OrderedSetTest>>testOccurrences (in category 'Sunit original tests') -----
+ testOccurrences
+ self assert: ((empty occurrencesOf: 0) = 0).
+ self assert: ((full occurrencesOf: 5) = 1).
+ full add: 5.
+ self assert: ((full occurrencesOf: 5) = 1).!

Item was added:
+ ----- Method: OrderedSetTest>>testOrder (in category 'tests') -----
+ testOrder
+ "We use integers as keys to match hash values."
+
+ | set |
+ set := Set new.
+
+ 1 to: 10 do: [:ea |
+ set add: ea.
+ empty add: ea].
+
+ self assert: set asArray = empty asArray.
+
+ set remove: 5.
+ empty remove: 5.
+
+ self assert: set asArray = empty asArray.
+
+ set add: 5.
+ empty add: 5.
+
+ self
+ assert: set asArray ~= empty asArray;
+ assert: #(1 2 3 4 6 7 8 9 10 5) equals: empty asArray;
+ assert: #(1 2 3 4 5 6 7 8 9 10) equals: set asArray.!

Item was added:
+ ----- Method: OrderedSetTest>>testOverflow (in category 'tests') -----
+ testOverflow
+ "Check whether repeated additions of the same alternating keys causes an error."
+
+ self
+ shouldnt: [20 timesRepeat: [empty add: 1; remove: 1]]
+ raise: Error. !

Item was added:
+ ----- Method: OrderedSetTest>>testOverwriteValue (in category 'tests') -----
+ testOverwriteValue
+ "First write wins wrt. order in the dictionary."
+
+ 1 to: 5 do: [:ea |
+ empty add: ea].
+
+ empty add: 3.
+
+ self assert: #(1 2 3 4 5) equals: empty asArray!

Item was added:
+ ----- Method: OrderedSetTest>>testRemove (in category 'Sunit original tests') -----
+ testRemove
+ full remove: 5.
+ self assert: (full includes: #abc).
+ self deny: (full includes: 5).!

Item was added:
+ ----- Method: OrderedSetTest>>testRemoveAll (in category 'tests') -----
+ testRemoveAll
+ "Allows one to remove all elements of a collection"
+
+ | c1 c2 s2 |
+ c1 := full.
+ c2 := c1 copy.
+ s2 := c2 size.
+
+ c1 removeAll.
+
+ self assert: c1 size = 0.
+ self assert: c2 size = s2 description: 'the copy has not been modified'.!

Item was added:
+ ----- Method: OrderedSetTest>>testRemoveIfAbsent (in category 'tests') -----
+ testRemoveIfAbsent
+ | result1 result2 |
+ result1 := true.
+ result2 := true.
+ full remove: 8 ifAbsent: [ result1 := false ].
+ self assert: (result1 = false).
+ full remove: 5 ifAbsent: [ result2 := false ].
+ self assert: (result2 = true).
+
+
+ !

Item was added:
+ ----- Method: OrderedSetTest>>testSize (in category 'tests') -----
+ testSize
+ self assert: (empty size = 0).
+ self assert: (full size = 2).
+ empty add: 2.
+ empty add: 1.
+ full add: 2.
+ self assert: (empty size = 2).
+ self assert: (full size = 3).
+ empty remove: 2.
+ self assert: (empty size = 1).!

Item was added:
+ ----- Method: OrderedSetTest>>testSort (in category 'tests - sorting') -----
+ testSort
+
+ 10 to: 1 by: -1 do: [:ea |
+ empty add: ea].
+
+ self assert: (10 to: 1 by: -1) asArray equals: empty asArray.
+ empty sort.
+ self assert: (1 to: 10) asArray equals: empty asArray.!

Item was added:
+ ----- Method: OrderedSetTest>>testSortCustom (in category 'tests - sorting') -----
+ testSortCustom
+
+ | values |
+ values := #(The quick brown fox jumps over the lazy dog).
+ 1 to: 9 do: [:ea |
+ empty add: (values at: ea)].
+ empty sort: [:a1 :a2 | a1 value <= a2 value].
+ self assert: values sorted equals: empty asArray!

Item was added:
+ ----- Method: OrderedSetTest>>testSorted (in category 'tests - sorting') -----
+ testSorted
+
+ 10 to: 1 by: -1 do: [:ea |
+ empty add: ea].
+
+ empty sorted in: [:copy |
+ self
+ assert: copy ~~ empty;
+ assert: copy asArray = empty asArray reversed].!

Item was added:
+ ----- Method: OrderedSetTest>>testUnion (in category 'tests') -----
+ testUnion
+ | newFull col newCol |
+ full add: 3.
+ full add: 2.
+ col := full union: full.
+ self assert: (full = col).
+
+ newFull := OrderedSet with: 8 with: 9 with: #z.
+ col := newFull union: full.
+ self assert: (col size = (full size + newFull size)).
+ self assert: ((col select: [:each | (full includes: each) not]) = newFull).
+ self assert: ((col select: [:each | (newFull includes: each) not]) = full).
+
+ full add: 9.
+ col := newFull union: full.
+ newCol := newFull copy.
+ newCol remove: 9.
+ self assert: (col size = (full size + newFull size - 1)).
+ self assert: ((col select: [:each | (full includes: each) not]) = newCol).
+ newCol := full copy.
+ newCol remove: 9.
+ self assert: ((col select: [:each | (newFull includes: each) not]) = newCol).
+
+
+ !

Item was added:
+ ----- Method: SetWithNilTest>>testOrderedSetWithNil (in category 'tests') -----
+ testOrderedSetWithNil

Loading...