The Trunk: CollectionsTests-ul.332.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.332.mcz

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

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

Name: CollectionsTests-ul.332
Author: ul
Time: 21 January 2020, 3:02:12.306127 am
UUID: 676023ec-8314-440b-acab-f6e29848f816
Ancestors: CollectionsTests-nice.331

HashedCollectionTest changes:
- more thorough #testSizeFor
- inlined #testPrimes: into #testGoodPrimes
- added new checks to #testGoodPrimes
- always calculate badPrimes in #testGoodPrimes

=============== Diff against CollectionsTests-nice.331 ===============

Item was changed:
  ----- Method: HashedCollectionTest>>testGoodPrimes (in category 'tests - class - sizing') -----
  testGoodPrimes
 
+ | goodPrimes badPrimes hashMultiplyConstant |
+ goodPrimes := HashedCollection goodPrimes.
+ "Bad primes are less than the hashMultiply constant (1664525) and 1664525 \\ prime is close to 0 (mod prime)."
+ hashMultiplyConstant := 1 hashMultiply.
+ badPrimes := (Integer primesUpTo: hashMultiplyConstant) select: [ :each |
+ | remainder |
+ remainder := hashMultiplyConstant \\ each.
+ remainder <= 1 or: [ remainder + 1 = each ] ].
+ self assert: goodPrimes isArray.
+ goodPrimes do: [ :each |
+ self assert: each isInteger.
+ self assert: each odd.
+ self assert: each isPrime ].
+ self assert: goodPrimes isSorted.
+ "HashedCollection class >> #goodPrimesAtLeast: relies on the following three."
+ self assert: goodPrimes size > 3.
+ self assert: #(3 5 7) equals: (goodPrimes first: 3).
+ self assert: goodPrimes last > 100000.
+ "The below snippet tests that primes past 2069 do not interact badly with 1664525, the hashMultiply constant."
+ goodPrimes
+ select: [ :each | each > 2069 ]
+ thenDo: [ :each |
+ self deny: (badPrimes includes: each).
+ 1 to: 8 do: [ :k |
+ 1 to: 32 do: [ :a |
+ self assert: 1 equals: (each gcd: (256 raisedTo: k) + a).
+ self assert: 1 equals: (each gcd: (256 raisedTo: k) - a) ] ] ]!
- self testPrimes: HashedCollection goodPrimes!

Item was removed:
- ----- Method: HashedCollectionTest>>testPrimes: (in category 'tests - class - sizing') -----
- testPrimes: primes
-
- | badPrimes |
- badPrimes := #(3 5 71 139 479 5861 277421). "These primes are less than the hashMultiply constant (1664525) and 1664525 \\ prime is close to 0 (mod prime). The following snippet reproduces these numbers:
- | hashMultiplyConstant |
- hashMultiplyConstant := 1 hashMultiply.
- (Integer primesUpTo: hashMultiplyConstant) select: [ :each |
- | remainder |
- remainder := hashMultiplyConstant \\ each.
- remainder <= 1 or: [ remainder + 1 = each ] ]."
- self assert: primes isSorted.
- primes do: [ :each |
- self assert: each isPrime.
- self deny: (each > 2069 and: [ badPrimes includes: each ]) ].
- self assert: (
- primes select: [ :p |
- | result |
- result := false.
- p > 2069 ifTrue: [
- 1 to: 8 do: [ :k |
- 1 to: 32 do: [ :a |
- (p gcd: (256 raisedTo: k) + a) = 1 ifFalse: [
- result := true ].
- (p gcd: (256 raisedTo: k) - a) = 1 ifFalse: [
- result := true ] ] ] ].
- result ]) isEmpty.!

Item was changed:
  ----- Method: HashedCollectionTest>>testSizeFor (in category 'tests - class - sizing') -----
  testSizeFor
 
+ (0 to: 10000) asArray,
  #(
- 0 1 5 10 30 57 89 578 1234 1912 2411 2591 5627 7849
  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 |
+ capacity := HashedCollection sizeFor: numberOfElements.
+ capacity <= HashedCollection goodPrimes last ifTrue: [
+ self assert: capacity isPrime ].
+ self assert: capacity odd.
+ self assert: numberOfElements asFloat / capacity <= 0.75 ]!
- 837938371 880614337 989233852 1000473294 1060034095) do: [ :each |
- | size |
- size := HashedCollection sizeFor: each.
- size <= HashedCollection goodPrimes last ifTrue: [
- self assert: size isPrime ].
- self assert: size odd.
- self assert: size * 3 // 4 >= each ]!