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

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

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

Name: CollectionsTests-ul.249
Author: ul
Time: 6 September 2015, 5:07:02.126 pm
UUID: 1ea5b300-f467-4693-91b6-92bcf967bc54
Ancestors: CollectionsTests-eem.248

Added thorough tests for the integer accessors of ByteArray's platform independent access category.

=============== Diff against CollectionsTests-eem.248 ===============

Item was added:
+ ----- Method: ByteArrayTest>>byteArrayFor:bits:bigEndian: (in category 'testing - platform independent access') -----
+ byteArrayFor: signedValue bits: bits bigEndian: bigEndian
+
+ | unsignedValue size result |
+ unsignedValue := signedValue negative
+ ifTrue: [ signedValue + (1 bitShift: bits) ]
+ ifFalse: [ signedValue ].
+ size := bits // 8.
+ result := ByteArray new: size.
+ 1 to: size do: [ :index |
+ result at: index put: (unsignedValue digitAt: index) ].
+ bigEndian ifTrue: [ result reverseInPlace ].
+ ^result
+ !

Item was removed:
- ----- Method: ByteArrayTest>>testByteArrayLongAtPreservesSign (in category 'as yet unclassified') -----
- testByteArrayLongAtPreservesSign
- | ba value |
- ba := ByteArray new: 4.
- value := -1.
- ba longAt: 1 put: value bigEndian: true.
- self assert: (ba longAt: 1 bigEndian: true) = value.
- ba longAt: 1 put: value bigEndian: false.
- self assert: (ba longAt: 1 bigEndian: false) = value.!

Item was added:
+ ----- Method: ByteArrayTest>>testPlatformIndepentendIntegerAccessorsAtBitBorders (in category 'testing - platform independent access') -----
+ testPlatformIndepentendIntegerAccessorsAtBitBorders
+
+ #(
+ shortAt:put:bigEndian: shortAt:bigEndian: false 16
+ longAt:put:bigEndian: longAt:bigEndian: false 32
+ unsignedShortAt:put:bigEndian: unsignedShortAt:bigEndian: true 16
+ unsignedLongAt:put:bigEndian: unsignedLongAt:bigEndian: true 32
+ unsignedLong64At:put:bigEndian: unsignedLong64At:bigEndian: true 64
+ ) groupsDo: [ :setter :getter :unsigned :storageBits |
+ self
+ verifyPlatformIndepentendIntegerAccessorsAtBitBordersSetter: setter
+ getter: getter
+ unsigned: unsigned
+ storageBits: storageBits ]!

Item was added:
+ ----- Method: ByteArrayTest>>testPlatformIndepentendIntegerAccessorsWithRandomValues (in category 'testing - platform independent access') -----
+ testPlatformIndepentendIntegerAccessorsWithRandomValues
+
+ | random |
+ random := Random seed: 36rSqueak.
+ #(
+ shortAt:put:bigEndian: shortAt:bigEndian: false 16
+ longAt:put:bigEndian: longAt:bigEndian: false 32
+ unsignedShortAt:put:bigEndian: unsignedShortAt:bigEndian: true 16
+ unsignedLongAt:put:bigEndian: unsignedLongAt:bigEndian: true 32
+ unsignedLong64At:put:bigEndian: unsignedLong64At:bigEndian: true 64
+ ) groupsDo: [ :setter :getter :unsigned :storageBits |
+ self
+ verifyPlatformIndepentendIntegerAccessorsWithRandomValuesSetter: setter
+ getter: getter
+ unsigned: unsigned
+ storageBits: storageBits
+ random: random ]!

Item was added:
+ ----- Method: ByteArrayTest>>verifyPlatformIndepentendIntegerAccessorsAtBitBordersSetter:getter:unsigned:storageBits: (in category 'testing - platform independent access') -----
+ verifyPlatformIndepentendIntegerAccessorsAtBitBordersSetter: setter getter: getter unsigned: unsigned storageBits: storageBits
+
+ | byteArray minValue maxValue baseValues |
+ byteArray := ByteArray new: storageBits // 8.
+ unsigned
+ ifTrue: [
+ minValue := 0.
+ maxValue := 1 << storageBits - 1.
+ baseValues := #(0 1) ]
+ ifFalse: [
+ minValue := -1 << (storageBits - 1).
+ maxValue := 1 << (storageBits - 1) - 1.
+ baseValues := #(-1 0 1) ].
+ #(true false) do: [ :bigEndian |
+ 0 to: storageBits - 1 do: [ :bits |
+ baseValues do: [ :baseValue |
+ | centerValue |
+ centerValue := baseValue << bits.
+ centerValue - 1 to: centerValue + 1 do: [ :value |
+ (value between: minValue and: maxValue) ifTrue: [
+ self
+ verifyPlatformIndepentendIntegerAccessorsMatch: byteArray
+ for: value
+ setter: setter
+ getter: getter
+ storageBits: storageBits
+ bigEndian: bigEndian  ] ] ] ] ]
+ !

Item was added:
+ ----- Method: ByteArrayTest>>verifyPlatformIndepentendIntegerAccessorsMatch:for:setter:getter:storageBits:bigEndian: (in category 'testing - platform independent access') -----
+ verifyPlatformIndepentendIntegerAccessorsMatch: byteArray for: value setter: setter getter: getter storageBits: storageBits bigEndian: bigEndian
+
+ | expectedSetterResult getterResult |
+ expectedSetterResult := self byteArrayFor: value bits: storageBits bigEndian: bigEndian.
+ byteArray perform: setter with: 1 with: value with: bigEndian.
+ self assert: expectedSetterResult equals: byteArray.
+ getterResult := byteArray perform: getter with: 1 with: bigEndian.
+ self assert: value equals: getterResult!

Item was added:
+ ----- Method: ByteArrayTest>>verifyPlatformIndepentendIntegerAccessorsWithRandomValuesSetter:getter:unsigned:storageBits:random: (in category 'testing - platform independent access') -----
+ verifyPlatformIndepentendIntegerAccessorsWithRandomValuesSetter: setter getter: getter unsigned: unsigned storageBits: storageBits random: random
+
+ | byteArray randomMax randomOffset |
+ byteArray := ByteArray new: storageBits // 8.
+ randomMax := 1 << storageBits.
+ randomOffset := unsigned
+ ifTrue: [ -1 ]
+ ifFalse: [ -1 << (storageBits - 1) - 1 ].
+ 10000 timesRepeat: [
+ | value |
+ value := (random nextInt: randomMax) + randomOffset.
+ #(true false) do: [ :bigEndian |
+ self
+ verifyPlatformIndepentendIntegerAccessorsMatch: byteArray
+ for: value
+ setter: setter
+ getter: getter
+ storageBits: storageBits
+ bigEndian: bigEndian ] ]!