Levente Uzonyi uploaded a new version of Tests to project The Trunk:
http://source.squeak.org/trunk/Tests-ul.318.mcz ==================== Summary ==================== Name: Tests-ul.318 Author: ul Time: 11 April 2015, 5:00:50.13 am UUID: 2fee61e2-b0cb-4035-ba7b-1513cb1ab885 Ancestors: Tests-topa.317 Added some tests for ThirtyTwoBitRegister. =============== Diff against Tests-topa.317 =============== Item was changed: SystemOrganization addCategory: #'Tests-Bugs'! SystemOrganization addCategory: #'Tests-Compiler'! SystemOrganization addCategory: #'Tests-Dependencies'! SystemOrganization addCategory: #'Tests-Digital Signatures'! SystemOrganization addCategory: #'Tests-Environments'! SystemOrganization addCategory: #'Tests-Exceptions'! SystemOrganization addCategory: #'Tests-FilePackage'! SystemOrganization addCategory: #'Tests-Files'! SystemOrganization addCategory: #'Tests-Finalization'! SystemOrganization addCategory: #'Tests-Hex'! SystemOrganization addCategory: #'Tests-Installer-Core'! SystemOrganization addCategory: #'Tests-Localization'! SystemOrganization addCategory: #'Tests-Monticello'! SystemOrganization addCategory: #'Tests-Monticello-Mocks'! SystemOrganization addCategory: #'Tests-Monticello-Utils'! SystemOrganization addCategory: #'Tests-Object Events'! SystemOrganization addCategory: #'Tests-ObjectsAsMethods'! SystemOrganization addCategory: #'Tests-PrimCallController'! SystemOrganization addCategory: #'Tests-Release'! SystemOrganization addCategory: #'Tests-System-Object Storage'! SystemOrganization addCategory: #'Tests-System-Support'! SystemOrganization addCategory: #'Tests-Utilities'! SystemOrganization addCategory: #'Tests-VM'! + SystemOrganization addCategory: #'Tests-System-Digital Signatures'! Item was added: + TestCase subclass: #ThirtyTwoBitRegisterTest + instanceVariableNames: 'random' + classVariableNames: '' + poolDictionaries: '' + category: 'Tests-System-Digital Signatures'! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>assertBinaryRegisterOperation:gives:times: (in category 'helpers') ----- + assertBinaryRegisterOperation: registerOperationBlock gives: integerOperationBlock times: n + + | rx ry | + rx := ThirtyTwoBitRegister new. + ry := rx copy. + n timesRepeat: [ + | x y expectedResult | + x := self nextRandom. + y := self nextRandom. + expectedResult := integerOperationBlock value: x value: y . + rx load: x. + ry load: y. + registerOperationBlock value: rx value: ry. + self assert: expectedResult equals: rx asInteger ]! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>assertComparisonRegisterOperation:gives:times: (in category 'helpers') ----- + assertComparisonRegisterOperation: registerOperationBlock gives: integerOperationBlock times: n + + | rx ry | + rx := ThirtyTwoBitRegister new. + ry := rx copy. + n timesRepeat: [ + | x y expectedResult actualResult | + x := self nextRandom. + y := self nextRandom. + expectedResult := integerOperationBlock value: x value: y . + rx load: x. + ry load: y. + actualResult := registerOperationBlock value: rx value: ry. + self assert: expectedResult equals: actualResult ]! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>assertUnaryRegisterOperation:gives:times: (in category 'helpers') ----- + assertUnaryRegisterOperation: registerOperationBlock gives: integerOperationBlock times: n + + | rx | + rx := ThirtyTwoBitRegister new. + n timesRepeat: [ + | x expectedResult | + x := self nextRandom. + expectedResult := integerOperationBlock value: x. + rx load: x. + registerOperationBlock value: rx. + self assert: expectedResult equals: rx asInteger ]! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>nextRandom (in category 'helpers') ----- + nextRandom + "Return the next random 32-bit unsigned integer value." + + ^(random nextInt: 4294967296) - 1! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>setUp (in category 'running') ----- + setUp + + random := Random seed: 36rSqueak! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testAddition (in category 'tests - accumulator ops') ----- + testAddition + + self + assertBinaryRegisterOperation: [ :rx :ry | rx += ry ] + gives: [ :x :y | x + y bitAnd: 16rFFFFFFFF ] + times: 10000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testBitAnd (in category 'tests - accumulator ops') ----- + testBitAnd + + self + assertBinaryRegisterOperation: [ :rx :ry | rx bitAnd: ry ] + gives: [ :x :y | x bitAnd: y ] + times: 10000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testBitInvert (in category 'tests - accumulator ops') ----- + testBitInvert + + self + assertUnaryRegisterOperation: [ :rx | rx bitInvert ] + gives: [ :x | x bitInvert32 ] + times: 10000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testBitOr (in category 'tests - accumulator ops') ----- + testBitOr + + self + assertBinaryRegisterOperation: [ :rx :ry | rx bitOr: ry ] + gives: [ :x :y | x bitOr: y ] + times: 10000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testBitXor (in category 'tests - accumulator ops') ----- + testBitXor + + self + assertBinaryRegisterOperation: [ :rx :ry | rx bitXor: ry ] + gives: [ :x :y | x bitXor: y ] + times: 10000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testEquals (in category 'tests - comparison') ----- + testEquals + + self + assertComparisonRegisterOperation: [ :rx :ry | rx = ry ] + gives: [ :x :y | x = y ] + times: 1000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testGreater (in category 'tests - comparison') ----- + testGreater + + self + assertComparisonRegisterOperation: [ :rx :ry | rx > ry ] + gives: [ :x :y | x > y ] + times: 1000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testGreaterOrEqual (in category 'tests - comparison') ----- + testGreaterOrEqual + + self + assertComparisonRegisterOperation: [ :rx :ry | rx >= ry ] + gives: [ :x :y | x >= y ] + times: 1000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testHi (in category 'tests') ----- + testHi + + self + assertUnaryRegisterOperation: [ :rx | rx load: rx hi ] + gives: [ :x | x bitShift: -16 ] + times: 1000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testLeftRotateBy (in category 'tests - accumulator ops') ----- + testLeftRotateBy + + 0 to: 33 do: [ :shift | + self + assertUnaryRegisterOperation: [ :rx | rx leftRotateBy: shift ] + gives: [ :x | + | actualShift | + actualShift := shift \\ 32. + (x << actualShift bitOr: x >> (32 - actualShift)) bitAnd: 16rFFFFFFFF ] + times: 1000 ]! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testLeftShift (in category 'tests - accumulator ops') ----- + testLeftShift + + 0 to: 33 do: [ :shift | + self + assertUnaryRegisterOperation: [ :rx | rx << shift ] + gives: [ :x | x << shift bitAnd: 16rFFFFFFFF ] + times: 1000 ]! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testLess (in category 'tests - comparison') ----- + testLess + + self + assertComparisonRegisterOperation: [ :rx :ry | rx < ry ] + gives: [ :x :y | x < y ] + times: 1000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testLessOrEqual (in category 'tests - comparison') ----- + testLessOrEqual + + self + assertComparisonRegisterOperation: [ :rx :ry | rx <= ry ] + gives: [ :x :y | x <= y ] + times: 1000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testLoad (in category 'tests') ----- + testLoad + + 1000 timesRepeat: [ + | value | + value := self nextRandom. + self + assertUnaryRegisterOperation: [ :rx | rx load: value ] + gives: [ :x | value ] + times: 1 ]! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testLoadFrom (in category 'tests') ----- + testLoadFrom + + self + assertBinaryRegisterOperation: [ :rx :ry | rx loadFrom: ry ] + gives: [ :x :y | y ] + times: 10000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testLow (in category 'tests') ----- + testLow + + self + assertUnaryRegisterOperation: [ :rx | rx load: rx low ] + gives: [ :x | x bitAnd: 16rFFFF ] + times: 1000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testMultiplication (in category 'tests - accumulator ops') ----- + testMultiplication + + self + assertBinaryRegisterOperation: [ :rx :ry | rx *= ry ] + gives: [ :x :y | x * y bitAnd: 16rFFFFFFFF ] + times: 10000! Item was added: + ----- Method: ThirtyTwoBitRegisterTest>>testRightShift (in category 'tests - accumulator ops') ----- + testRightShift + + 0 to: 33 do: [ :shift | + self + assertUnaryRegisterOperation: [ :rx | rx >> shift ] + gives: [ :x | x >> shift bitAnd: 16rFFFFFFFF ] + times: 1000 ]! |
Free forum by Nabble | Edit this page |