The Trunk: CollectionsTests-ul.333.mcz

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

The Trunk: CollectionsTests-ul.333.mcz

commits-2
Levente Uzonyi uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-ul.333.mcz

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

Name: CollectionsTests-ul.333
Author: ul
Time: 5 February 2020, 5:56:55.801188 pm
UUID: 270aac80-51aa-4655-af72-9b7b15d3c959
Ancestors: CollectionsTests-ul.332

- added DictionaryTest>>testCapcityOfNew to test the hardcoded capacity values in #new and optionally #new:
- improved HashedCollectionTest >> #testSizeFor by adding CI-friendly descriptions and checking the returned values more thoroughly

=============== Diff against CollectionsTests-ul.332 ===============

Item was added:
+ ----- 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 changed:
  ----- Method: HashedCollectionTest>>testSizeFor (in category 'tests - class - sizing') -----
  testSizeFor
 
+ | goodPrimes |
+ goodPrimes := HashedCollection goodPrimes.
  (0 to: 10000) asArray,
  #(
  10999 61356 68602 73189 79868 86789 239984 239985 501175 661865 841558
  9669391 15207345 19827345 23469817 27858432 65223175 106650047
  157687845 190892299 234947087 264782114 269617510 270995400
  392236508 456647275 468699153 606865011 606997796 617927086
  837938371 880614337 989233852 1000473294 1060034095 1073741833 1073741834) do: [ :numberOfElements |
+ | capacity capacityIndex |
- | capacity |
  capacity := HashedCollection sizeFor: numberOfElements.
+ self
+ assert: capacity isInteger
+ description: '#sizeFor: must return an integer';
+ assert: capacity odd
+ description: '#sizeFor: must return an odd integer';
+ assert: capacity > 0
+ description: '#sizeFor: must return a positive integer'.
+ capacity <= goodPrimes last ifTrue: [
+ self
+ assert: capacity isPrime
+ description: '#sizeFor: must return a prime when the returned capacity is smaller than the largest good prime' ].
+ self
+ assert: numberOfElements asFloat / capacity <= 0.75
+ description: '#sizeFor: must return a capacity for which the load factor does not exceed 75%'.
+ capacityIndex := goodPrimes indexOf: capacity ifAbsent: [ goodPrimes size + 1 ].
+ capacityIndex > 1 ifTrue: [
+ | nextSmallerCapacity |
+ nextSmallerCapacity := goodPrimes at: capacityIndex - 1.
+ self
+ assert: numberOfElements asFloat / nextSmallerCapacity > 0.75
+ description: '#sizeFor: should return the smallest possible capacity' ] ]!
- capacity <= HashedCollection goodPrimes last ifTrue: [
- self assert: capacity isPrime ].
- self assert: capacity odd.
- self assert: numberOfElements asFloat / capacity <= 0.75 ]!