[squeak-dev] The Trunk: CollectionsTests-dtl.100.mcz

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

[squeak-dev] The Trunk: CollectionsTests-dtl.100.mcz

commits-2
David T. Lewis uploaded a new version of CollectionsTests to project The Trunk:
http://source.squeak.org/trunk/CollectionsTests-dtl.100.mcz

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

Name: CollectionsTests-dtl.100
Author: dtl
Time: 3 October 2009, 4:55:52 am
UUID: 0d66fd09-98a2-4f73-ba7e-bb6e65be712b
Ancestors: CollectionsTests-nice.99

Add IntegerArrayTest.

Verify storage of integer values in an IntegerArray. An IntegerArray stores 32-bit signed integer values. Lack of range check in primitive fallback code leads to arithmetic overflow errors, so attempts to store out of range values should raise errors.

Reference Mantis 7309

=============== Diff against CollectionsTests-nice.99 ===============

Item was added:
+ ----- Method: IntegerArrayTest>>testStoreSmallInteger (in category 'tests') -----
+ testStoreSmallInteger
+ "Any SmallInteger may be stored in an IntegerArray."
+
+ | ia val |
+ ia := IntegerArray new: 1.
+ val := SmallInteger maxVal.
+ ia at: 1 put: val.
+ self assert: ((ia at: 1) = val).
+
+ val := SmallInteger minVal.
+ ia at: 1 put: val.
+ self assert: ((ia at: 1) = val)
+ !

Item was added:
+ ----- Method: IntegerArrayTest>>testStoreNegativeOutOfRange (in category 'tests') -----
+ testStoreNegativeOutOfRange
+ "A value too small for a 32-bit signed integer should raise an error."
+
+ | ia val storedValue |
+ ia := IntegerArray new: 1.
+ val := (2 raisedTo: 31) negated - 1. " -16r80000001 of range for 32-bit twos complement integer"
+ self should: [ia at: 1 put: val. "should raise error here"
+ storedValue := ia at: 1. "lack of range check leads to value of 16r7FFFFFFF"
+ self assert: val = storedValue "fail here"]
+ raise: Error
+ !

Item was added:
+ ----- Method: IntegerArrayTest>>testStorePositiveOutOfRange (in category 'tests') -----
+ testStorePositiveOutOfRange
+ "A value too large for a 32-bit signed integer should raise an error."
+
+ | ia val storedValue |
+ ia := IntegerArray new: 1.
+ val := 2 raisedTo: 31. "16r80000000 is out of range for 32-bit twos complement"
+ self should: [ia at: 1 put: val. "should raise error here"
+ storedValue := ia at: 1. "lack of range check leads to value of 16r-80000000"
+ self assert: val = storedValue "fail here"]
+ raise: Error
+ !

Item was added:
+ ----- Method: IntegerArrayTest>>testStoreLargeNegativeInteger (in category 'tests') -----
+ testStoreLargeNegativeInteger
+ "A LargeNegativeInteger that does not exceed the range of a 32-bit twos
+ complement integer may be stored."
+
+ | ia val |
+ ia := IntegerArray new: 1.
+ val := (2 raisedTo: 31) negated. "smallest negative 32-bit integer, a LargeNegativeInteger"
+ ia at: 1 put: val.
+ self assert: ((ia at: 1) = val)
+ !

Item was added:
+ ----- Method: IntegerArrayTest>>testStoreLargePositiveInteger (in category 'tests') -----
+ testStoreLargePositiveInteger
+ "A LargePositiveInteger that does not exceed the range of a 32-bit twos
+ complement integer may be stored."
+
+ | ia val |
+ ia := IntegerArray new: 1.
+ val := (2 raisedTo: 31) - 1. "largest positive 32-bit integer, a LargePositiveInteger"
+ ia at: 1 put: val.
+ self assert: ((ia at: 1) = val)
+ !

Item was added:
+ ClassTestCase subclass: #IntegerArrayTest
+ instanceVariableNames: ''
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'CollectionsTests-Arrayed'!
+
+ !IntegerArrayTest commentStamp: 'dtl 10/3/2009 16:37' prior: 0!
+ Verify storage of integer values in an IntegerArray. An IntegerArray stores 32-bit signed integer values. Lack of range check in primitive fallback code leads to arithmetic overflow errors, so attempts to store out of range values should raise errors.!