Marcel Taeumel uploaded a new version of KernelTests to project The Trunk:
http://source.squeak.org/trunk/KernelTests-mt.365.mcz ==================== Summary ==================== Name: KernelTests-mt.365 Author: mt Time: 31 May 2019, 11:49:30.444936 am UUID: 4087706d-1610-504e-9930-d0ab9de30dd5 Ancestors: KernelTests-nice.364, KernelTests-cmfcmf.357 merge cmfcmf.357 =============== Diff against KernelTests-nice.364 =============== Item was added: + ----- Method: RandomTest>>testRoll (in category 'tests') ----- + testRoll + + | random result | + random := Random seed: 14482. + + "Roll the default die (d6)" + 100 timesRepeat: [ + result := random roll: 'd'. + self assert: result >= 1 description: [ 'Rolled value ', result asString, ' should be 1 or more.' ]. + self assert: result <= 6 description: [ 'Rolled value ', result asString, ' should be 6 or less.' ] ]. + 100 timesRepeat: [ + result := random roll: '1d'. + self assert: result >= 1 description: [ 'Rolled value ', result asString, ' should be 1 or more.' ]. + self assert: result <= 6 description: [ 'Rolled value ', result asString, ' should be 6 or less.' ] ]. + + "Roll a d20" + 100 timesRepeat: [ + result := random roll: '1d20'. + self assert: result >= 1 description: [ 'Rolled value ', result asString, ' should be 1 or more.' ]. + self assert: result <= 20 description: [ 'Rolled value ', result asString, ' should be 20 or less.' ] ]. + + "Roll a d% (d100)" + 1000 timesRepeat: [ + result := random roll: '1d%'. + self assert: result >= 1 description: [ 'Rolled value ', result asString, ' should be 1 or more.' ]. + self assert: result <= 100 description: [ 'Rolled value ', result asString, ' should be 100 or less.' ] ]. + 1000 timesRepeat: [ + result := random roll: 'd%'. + self assert: result >= 1 description: [ 'Rolled value ', result asString, ' should be 1 or more.' ]. + self assert: result <= 100 description: [ 'Rolled value ', result asString, ' should be 100 or less.' ] ]. + + "Roll multiple dice" + 100 timesRepeat: [ + result := random roll: '2d2'. + self assert: result >= 2 description: [ 'Rolled value ', result asString, ' should be 2 or more.' ]. + self assert: result <= 4 description: [ 'Rolled value ', result asString, ' should be 4 or less.' ] ]. + 100 timesRepeat: [ + result := random roll: '1d2+1d2'. + self assert: result >= 2 description: [ 'Rolled value ', result asString, ' should be 2 or more.' ]. + self assert: result <= 4 description: [ 'Rolled value ', result asString, ' should be 4 or less.' ] ]. + + "Roll some d1s" + result := random roll: '10d1'. + self assert: result = 10 description: [ 'Rolled value ', result asString, 'should be 10.' ]. + result := random roll: '10d1-5d1'. + self assert: result = 5 description: [ 'Rolled value ', result asString, 'should be 5.' ]. + + "Roll a constant value" + result := random roll: '5'. + self assert: result = 5 description: [ 'Rolled value ', result asString, 'should be 5.' ]. + result := random roll: '5+3+2'. + self assert: result = 10 description: [ 'Rolled value ', result asString, 'should be 10.' ]. + + "Roll die and add constant value" + result := random roll: '1d1+3'. + self assert: result = 4 description: [ 'Rolled value ', result asString, 'should be 4.' ].! |
Free forum by Nabble | Edit this page |