The Inbox: CollectionsTests-ul.344.mcz

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

The Inbox: CollectionsTests-ul.344.mcz

commits-2
Levente Uzonyi uploaded a new version of CollectionsTests to project The Inbox:
http://source.squeak.org/inbox/CollectionsTests-ul.344.mcz

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

Name: CollectionsTests-ul.344
Author: ul
Time: 28 September 2020, 11:52:49.129468 pm
UUID: 82e7d021-2a4e-4e58-8758-c4e8838805cf
Ancestors: CollectionsTests-eem.342

Hashed collections:
- updated tests to send #array and #size 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 array size).
+ 0 to: 100 do: [ :size |
+ | dictionary |
+ dictionary := Dictionary new: size.
+ self assert: (goodPrimes includes: dictionary array size).
+ 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 array size isPowerOfTwo ]
+ ifFalse: [ each array size isPrime ] ].
+ self assert: inconsistentCollections isEmpty!

Item was changed:
  ----- Method: HashedCollectionTest>>testCapacity (in category 'tests - integrity') -----
  testCapacity
 
+ self assert: (HashedCollection allSubInstances allSatisfy: [ :each |
+ each array size * 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 array size; "next prime number to 7; see #setUp"
+ assert: sut capacity = (sut instVarNamed: #order) size;
+ assert: sut array size >(sut instVarNamed: #order) size. "save memory"
- assert: 11 equals: sut capacity; "next prime number to 7; see #setUp"
- assert: sut capacity > (sut instVarNamed: #order) size. "save memory"
 
+ 1 to: sut array size do: [:ea |
- 1 to: sut capacity do: [:ea |
  sut at: ea put: nil].
 
  self
+ assert: sut array size > 11;
+ assert: sut capacity = (sut instVarNamed: #order) size;
+ assert: sut array size > (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 array size.
+ 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 array size = 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 array size = 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)
 
 
  !