convert
| s |
s := '#000000' copy.
s at: 2 put: (Character digitValue: ((rgb bitShift: -6 - RedShift) bitAnd: 15)).
s at: 3 put: (Character digitValue: ((rgb bitShift: -2 - RedShift) bitAnd: 15)).
s at: 4 put: (Character digitValue: ((rgb bitShift: -6 - GreenShift) bitAnd: 15)).
s at: 5 put: (Character digitValue: ((rgb bitShift: -2 - GreenShift) bitAnd: 15)).
s at: 6 put: (Character digitValue: ((rgb bitShift: -6 - BlueShift) bitAnd: 15)).
s at: 7 put: (Character digitValue: ((rgb bitShift: -2 - BlueShift) bitAnd: 15)).
^ s
testConvert
self assert: Color white convert = '#FFFFFF'.
self assert: Color red convert = '#FF0000'.
self assert: Color black convert = '#000000'
testConvert2
| table aColorString |
table := #('0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'A' 'B' 'C' 'D' 'E' 'F').
table do: [ :each |
aColorString := '#', each, each, '0000'.
self assert: ((Color fromString: aColorString) convert sameAs: aColorString)].
table do: [ :each |
aColorString := '#', '00', each, each, '00'.
self assert: ((Color fromString: aColorString) convert sameAs: aColorString)].
table do: [ :each |
aColorString := '#', '0000', each, each.
self assert: ((Color fromString: aColorString) convert sameAs: aColorString)].
testBitShift
self assert: (2r11 bitShift: 2) equals: 2r1100.
self assert: (2r1011 bitShift: -2) equals: 2r10.
testShiftOneLeftThenRight
"Shift 1 bit left then right and test for 1"
1 to: 100 do: [:i | self assert: ((1 bitShift: i) bitShift: i negated) = 1].
How do you test contracts of abstract types?
How do you test that one and only one state is active at any time?
testOnlyOneValidStateAtEachMoment
| action |
action := self createAction.
self assert: action isReady.
self deny: action isInProgress. self deny: action isFinished.
[ action isFinished ] whileFalse: [
action doStep.
self deny: action isReady.
self assert: action isFinished = action isInProgress not ].
self deny: action isReady. self deny: action isInProgress.
self assert: action isFinished
How do you test that a questionnaire only accepts compatible answers from the user?
How do you test that a questionnaire only accepts compatible answers from the user?
readAnswerAsLongAsItIsNotCompatible
| nbRejectsBeforeAccept question ui |
nbRejectsBeforeAccept := 3.
question := MockQuestion new nbRejects: nbRejectsBeforeAccept.
ui := MockQuestionnaireUI new.
self assert: ui nbReadAnswers equals: 0.
self assert: question nbAcceptAnswerCalls equals: 0.
questionnaire runQuestion: question on: ui.
self assert: ui nbReadAnswers equals: nbRejectsBeforeAccept + 1.
self assert: question nbAcceptAnswerCalls equals: nbRejectsBeforeAccept + 1.
/