Levente Uzonyi uploaded a new version of CollectionsTests to project The Inbox:
http://source.squeak.org/inbox/CollectionsTests-ul.343.mcz ==================== Summary ==================== Name: CollectionsTests-ul.343 Author: ul Time: 28 September 2020, 1:21:54.222475 am UUID: 4971789d-4093-4368-a7b1-6f0d47c3bb55 Ancestors: CollectionsTests-eem.342 Hashed collections: - updated tests to use #arraySize instead of #capacity - added a few tests for #capacity =============== Diff against CollectionsTests-eem.342 =============== Item was added: + ----- Method: DictionaryTest>>testArraySizeOfNew (in category 'tests - basic') ----- + testArraySizeOfNew + "Test the special cases implemented in HashedCollection class >> #new and #new: using Dictionary as an example because HashedCollection is abstract." + + | goodPrimes | + goodPrimes := HashedCollection goodPrimes. + self assert: (goodPrimes includes: Dictionary new arraySize). + 0 to: 100 do: [ :size | + | dictionary | + dictionary := Dictionary new: size. + self assert: (goodPrimes includes: dictionary arraySize). + self assert: dictionary capacity >= size ]! Item was removed: - ----- Method: DictionaryTest>>testCapcityOfNew (in category 'tests - basic') ----- - testCapcityOfNew - "Test the special cases implemented in HashedCollection class >> #new and #new: using Dictionary as an example because HashedCollection is abstract." - - | goodPrimes | - goodPrimes := HashedCollection goodPrimes. - self assert: (goodPrimes includes: Dictionary new capacity). - 0 to: 100 do: [ :size | - | dictionary | - dictionary := Dictionary new: size. - self assert: (goodPrimes includes: dictionary capacity) ]! Item was added: + ----- Method: HashedCollectionTest>>testArraySize (in category 'tests - integrity') ----- + testArraySize + + | inconsistentCollections | + inconsistentCollections := HashedCollection allSubInstances reject: [ :each | + each class == MethodDictionary "MethodDictionary is the only HashedCollection which doesn't have prime array size" + ifTrue: [ each arraySize isPowerOfTwo ] + ifFalse: [ each arraySize isPrime ] ]. + self assert: inconsistentCollections isEmpty! Item was changed: ----- Method: HashedCollectionTest>>testCapacity (in category 'tests - integrity') ----- testCapacity + self assert: (HashedCollection allSubInstances allSatisfy: [ :each | + each arraySize * 3 // 4 = each capacity ])! - | inconsistentCollections | - inconsistentCollections := HashedCollection allSubInstances reject: [ :each | - each class == MethodDictionary "MethodDictionary is the only HashedCollection which doesn't have prime array size" - ifTrue: [ each capacity isPowerOfTwo ] - ifFalse: [ each capacity isPrime ] ]. - self assert: inconsistentCollections isEmpty! Item was changed: ----- Method: OrderedDictionaryTest>>testGrow (in category 'tests') ----- testGrow self + assert: 11 equals: sut arraySize; "next prime number to 7; see #setUp" + assert: sut capacity >= (sut instVarNamed: #order) size; "save memory" + assert: sut arraySize >(sut instVarNamed: #order) size. - assert: 11 equals: sut capacity; "next prime number to 7; see #setUp" - assert: sut capacity > (sut instVarNamed: #order) size. "save memory" + 1 to: sut arraySize do: [:ea | - 1 to: sut capacity do: [:ea | sut at: ea put: nil]. self + assert: sut arraySize > 11; + assert: sut arraySize > (sut instVarNamed: #order) size. "save memory"! - assert: sut capacity > 11; - assert: sut capacity > (sut instVarNamed: #order) size. "save memory"! Item was added: + ----- Method: SetTest>>testCapacity (in category 'tests') ----- + testCapacity + + | set capacity | + set := Set new. + self assert: set size = 0. + 10 timesRepeat: [ + capacity := set capacity. + self assert: set size < capacity. + set size + 1 to: capacity do: [ :i | + set add: i. + self assert: set capacity = capacity ]. + self assert: set size equals: capacity. + set add: set capacity + 1. + self assert: set capacity > capacity ]! Item was changed: ----- Method: WeakIdentityKeyDictionaryTest>>testFinalizeValuesWhenLastChainContinuesAtFront (in category 'tests') ----- testFinalizeValuesWhenLastChainContinuesAtFront + | objectWithHashModulo dictionary arraySize a b c | - | objectWithHashModulo dictionary capacity a b c | objectWithHashModulo := [ :requestedHash :modulo | | object | [ object := Object new. object hash \\ modulo = requestedHash ] whileFalse. object ]. dictionary := self classToBeTested new. + arraySize := dictionary arraySize. + a := objectWithHashModulo value: arraySize - 2 value: arraySize. - capacity := dictionary capacity. - a := objectWithHashModulo value: capacity - 2 value: capacity. dictionary at: a put: 1. + b := objectWithHashModulo value: arraySize - 1 value: arraySize. - b := objectWithHashModulo value: capacity - 1 value: capacity. dictionary at: b put: 2. + c := objectWithHashModulo value: arraySize - 2 value: arraySize. - c := objectWithHashModulo value: capacity - 2 value: capacity. dictionary at: c put: 3. + self assert: dictionary arraySize = arraySize. + self assert: (dictionary array at: arraySize - 1) key == a. + self assert: (dictionary array at: arraySize) key == b. - self assert: dictionary capacity = capacity. - self assert: (dictionary array at: capacity - 1) key == a. - self assert: (dictionary array at: capacity) key == b. self assert: (dictionary array at: 1) key == c. a := nil. Smalltalk garbageCollect. dictionary finalizeValues. self assert: (dictionary includesKey: b). self assert: (dictionary includesKey: c). + self assert: dictionary slowSize = 2! - self assert: dictionary slowSize = 2. - ! Item was changed: ----- Method: WeakSetTest>>testIncludes (in category 'tests') ----- testIncludes | weakSet transientFakeNilObject | weakSet := WeakSet new. #(true nil 1) do: [ :each | self deny: (weakSet includes: each) ]. weakSet add: true. self assert: (weakSet includes: true). weakSet remove: true. self deny: (weakSet includes: true). + transientFakeNilObject := ((1 to: 1000) detect: [ :each | each asString hash - nil hash \\ weakSet arraySize = 0 ]) asString. "this string will occupy the same slot as nil would" - transientFakeNilObject := ((1 to: 1000) detect: [ :each | each asString hash - nil hash \\ weakSet capacity = 0 ]) asString. "this string will occupy the same slot as nil would" weakSet add: transientFakeNilObject. transientFakeNilObject := transientFakeNilObject copy. Smalltalk garbageCollect. "get rid of transientFakeNilObject" self deny: (weakSet includes: transientFakeNilObject). self deny: (weakSet includes: nil) ! |
Free forum by Nabble | Edit this page |