From c83fe00adad71c831d75d1dd69022177395eea08 Mon Sep 17 00:00:00 2001 From: YannLEGOFF Date: Thu, 27 Jul 2023 18:17:35 +0200 Subject: [PATCH 1/3] Add command test --- .../PyramidBackgroundCommandTest.class.st | 51 +++++++++++++++ .../PyramidClipChildrenCommandTest.class.st | 43 ++++++++++++ .../PyramidCommandTestContainer.class.st | 52 +++++++++++++++ .../PyramidElementIdCommandTest.class.st | 34 ++++++++++ .../PyramidPositionCommandTest.class.st | 31 +++++++++ .../TPyramidCommandTest.trait.st | 65 +++++++++++++++++++ 6 files changed, 276 insertions(+) create mode 100644 src/Pyramid-Tests/PyramidBackgroundCommandTest.class.st create mode 100644 src/Pyramid-Tests/PyramidClipChildrenCommandTest.class.st create mode 100644 src/Pyramid-Tests/PyramidCommandTestContainer.class.st create mode 100644 src/Pyramid-Tests/PyramidElementIdCommandTest.class.st create mode 100644 src/Pyramid-Tests/PyramidPositionCommandTest.class.st create mode 100644 src/Pyramid-Tests/TPyramidCommandTest.trait.st diff --git a/src/Pyramid-Tests/PyramidBackgroundCommandTest.class.st b/src/Pyramid-Tests/PyramidBackgroundCommandTest.class.st new file mode 100644 index 00000000..e1481bc3 --- /dev/null +++ b/src/Pyramid-Tests/PyramidBackgroundCommandTest.class.st @@ -0,0 +1,51 @@ +Class { + #name : #PyramidBackgroundCommandTest, + #superclass : #TestCase, + #traits : 'TPyramidCommandTest', + #classTraits : 'TPyramidCommandTest classTrait', + #category : #'Pyramid-Tests-cases-plugin-bloc' +} + +{ #category : #accessing } +PyramidBackgroundCommandTest >> command [ + + ^ PyramidBackgroundCommand new +] + +{ #category : #'as yet unclassified' } +PyramidBackgroundCommandTest >> targetContainers [ + + ^ { + (PyramidCommandTestContainer + no: BlElement new + with: (BlElement new + background: BlTransparentBackground new; + yourself) + prop: BlTransparentBackground new). + (PyramidCommandTestContainer + no: BlElement new + with: (BlElement new + background: BlTransparentBackground new; + yourself) + prop: BlTransparentBackground new). + (PyramidCommandTestContainer + no: BlElement new + with: (BlElement new + background:(BlImageBackground image: (self iconNamed: #add)); + yourself) + prop: (BlImageBackground image: (self iconNamed: #add))). + (PyramidCommandTestContainer + no: BlElement new + with: (BlElement new + background: (BlPaintBackground new paint: + (BlLinearGradientPaint vertical stops: { + (0.2 -> Color yellow). + (0.5 -> Color black). + (1 -> Color orange) })); + yourself) + prop: (BlPaintBackground new paint: + (BlLinearGradientPaint vertical stops: { + (0.2 -> Color yellow). + (0.5 -> Color black). + (1 -> Color orange) }))) } +] diff --git a/src/Pyramid-Tests/PyramidClipChildrenCommandTest.class.st b/src/Pyramid-Tests/PyramidClipChildrenCommandTest.class.st new file mode 100644 index 00000000..07f02a09 --- /dev/null +++ b/src/Pyramid-Tests/PyramidClipChildrenCommandTest.class.st @@ -0,0 +1,43 @@ +Class { + #name : #PyramidClipChildrenCommandTest, + #superclass : #TestCase, + #traits : 'TPyramidCommandTest', + #classTraits : 'TPyramidCommandTest classTrait', + #category : #'Pyramid-Tests-cases-plugin-bloc' +} + +{ #category : #accessing } +PyramidClipChildrenCommandTest >> command [ + + ^ PyramidClipChildrenCommand new +] + +{ #category : #'as yet unclassified' } +PyramidClipChildrenCommandTest >> targetContainers [ + + ^ { + (PyramidCommandTestContainer + no: BlElement new + with: (BlElement new + clipChildren: true; + yourself) + prop: true). + (PyramidCommandTestContainer + no: (BlElement new clipChildren: true; yourself) + with: (BlElement new + clipChildren: true; + yourself) + prop: true). + (PyramidCommandTestContainer + no: (BlElement new clipChildren: true; yourself) + with: (BlElement new + clipChildren: false; + yourself) + prop: false). + (PyramidCommandTestContainer + no: BlElement new + with: (BlElement new + clipChildren: false; + yourself) + prop: false). } +] diff --git a/src/Pyramid-Tests/PyramidCommandTestContainer.class.st b/src/Pyramid-Tests/PyramidCommandTestContainer.class.st new file mode 100644 index 00000000..37081f63 --- /dev/null +++ b/src/Pyramid-Tests/PyramidCommandTestContainer.class.st @@ -0,0 +1,52 @@ +Class { + #name : #PyramidCommandTestContainer, + #superclass : #Object, + #instVars : [ + 'targetNoProp', + 'targetWithProp', + 'prop' + ], + #category : #'Pyramid-Tests-cases-plugin-bloc' +} + +{ #category : #'as yet unclassified' } +PyramidCommandTestContainer class >> no: aTargetNoProp with: aTargetWithProp prop: aProp [ + +^ self new targetNoProp: aTargetNoProp; targetWithProp: aTargetWithProp; prop: aProp; yourself +] + +{ #category : #accessing } +PyramidCommandTestContainer >> prop [ + + ^ prop +] + +{ #category : #accessing } +PyramidCommandTestContainer >> prop: anObject [ + + prop := anObject +] + +{ #category : #accessing } +PyramidCommandTestContainer >> targetNoProp [ + + ^ targetNoProp +] + +{ #category : #accessing } +PyramidCommandTestContainer >> targetNoProp: anObject [ + + targetNoProp := anObject +] + +{ #category : #accessing } +PyramidCommandTestContainer >> targetWithProp [ + + ^ targetWithProp +] + +{ #category : #accessing } +PyramidCommandTestContainer >> targetWithProp: anObject [ + + targetWithProp := anObject +] diff --git a/src/Pyramid-Tests/PyramidElementIdCommandTest.class.st b/src/Pyramid-Tests/PyramidElementIdCommandTest.class.st new file mode 100644 index 00000000..b235dc3b --- /dev/null +++ b/src/Pyramid-Tests/PyramidElementIdCommandTest.class.st @@ -0,0 +1,34 @@ +Class { + #name : #PyramidElementIdCommandTest, + #superclass : #TestCase, + #traits : 'TPyramidCommandTest', + #classTraits : 'TPyramidCommandTest classTrait', + #category : #'Pyramid-Tests-cases-plugin-bloc' +} + +{ #category : #accessing } +PyramidElementIdCommandTest >> command [ + + ^ PyramidElementIdCommand new +] + +{ #category : #'as yet unclassified' } +PyramidElementIdCommandTest >> targetContainers [ + + + ^ { + (PyramidCommandTestContainer + no: BlElement new + with: (BlElement new + id: #test; + yourself) + prop: 'test'). + (PyramidCommandTestContainer + no: (BlElement new + id: #old; + yourself) + with: (BlElement new + id: #new; + yourself) + prop: 'new') } +] diff --git a/src/Pyramid-Tests/PyramidPositionCommandTest.class.st b/src/Pyramid-Tests/PyramidPositionCommandTest.class.st new file mode 100644 index 00000000..596e92eb --- /dev/null +++ b/src/Pyramid-Tests/PyramidPositionCommandTest.class.st @@ -0,0 +1,31 @@ +Class { + #name : #PyramidPositionCommandTest, + #superclass : #TestCase, + #traits : 'TPyramidCommandTest', + #classTraits : 'TPyramidCommandTest classTrait', + #category : #'Pyramid-Tests-cases-plugin-bloc' +} + +{ #category : #accessing } +PyramidPositionCommandTest >> command [ + + ^ PyramidPositionCommand new +] + +{ #category : #'as yet unclassified' } +PyramidPositionCommandTest >> targetContainers [ + + ^ { + (PyramidCommandTestContainer + no: BlElement new + with: (BlElement new + position: 50 @ 50; + yourself) + prop: 50 @ 50). + (PyramidCommandTestContainer + no: (BlElement new position: 50 @ 50; yourself) + with: (BlElement new + position: 400 @ 0; + yourself) + prop: 400 @ 0). } +] diff --git a/src/Pyramid-Tests/TPyramidCommandTest.trait.st b/src/Pyramid-Tests/TPyramidCommandTest.trait.st new file mode 100644 index 00000000..7183effb --- /dev/null +++ b/src/Pyramid-Tests/TPyramidCommandTest.trait.st @@ -0,0 +1,65 @@ +Trait { + #name : #TPyramidCommandTest, + #category : #'Pyramid-Tests-cases-plugin-bloc' +} + +{ #category : #accessing } +TPyramidCommandTest >> command [ + + ^ self shouldBeImplemented +] + +{ #category : #'as yet unclassified' } +TPyramidCommandTest >> targetContainers [ + + ^ self shouldBeImplemented +] + +{ #category : #'as yet unclassified' } +TPyramidCommandTest >> targetsCanBeUsedFor [ + + ^ self targetContainers flatCollect: [ :each | { each targetNoProp . each targetWithProp } ]. +] + +{ #category : #'as yet unclassified' } +TPyramidCommandTest >> targetsCannotBeUsedFor [ + "override if needed" + ^ { nil . false . 0 . $a } +] + +{ #category : #accessing } +TPyramidCommandTest >> targetsWithValuesAndValues [ + + ^ self targetContainers collect: [ :each | + each targetWithProp -> each prop ] +] + +{ #category : #accessing } +TPyramidCommandTest >> targetsWithoutValuesAndValues [ + + ^ self targetContainers collect: [ :each | each targetNoProp -> each prop ] +] + +{ #category : #tests } +TPyramidCommandTest >> testCanBeUsedFor [ + + self targetsCanBeUsedFor do: [ :each | + self assert: (self command canBeUsedFor: each) ]. + self targetsCannotBeUsedFor do: [ :each | + self deny: (self command canBeUsedFor: each) ]. +] + +{ #category : #tests } +TPyramidCommandTest >> testGetValueFor [ + + self targetsWithValuesAndValues do: [ :each | + self assert: (self command getValueFor: each key) equals: each value ]. +] + +{ #category : #tests } +TPyramidCommandTest >> testSetValueForWith [ + + self targetsWithoutValuesAndValues do: [ :each | + self command setValueFor: each key with: each value. + self assert: (self command getValueFor: each key) equals: each value ]. +] From bbeff627fa13f5c6d7c7133894bd991c1e4dcd83 Mon Sep 17 00:00:00 2001 From: YannLEGOFF Date: Fri, 28 Jul 2023 09:17:59 +0200 Subject: [PATCH 2/3] Add bloc command TU --- .../PyramidPositionOffsetCommandTest.class.st | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Pyramid-Tests/PyramidPositionOffsetCommandTest.class.st diff --git a/src/Pyramid-Tests/PyramidPositionOffsetCommandTest.class.st b/src/Pyramid-Tests/PyramidPositionOffsetCommandTest.class.st new file mode 100644 index 00000000..538e7e67 --- /dev/null +++ b/src/Pyramid-Tests/PyramidPositionOffsetCommandTest.class.st @@ -0,0 +1,50 @@ +Class { + #name : #PyramidPositionOffsetCommandTest, + #superclass : #TestCase, + #traits : 'TPyramidCommandTest', + #classTraits : 'TPyramidCommandTest classTrait', + #category : #'Pyramid-Tests-cases-plugin-bloc' +} + +{ #category : #accessing } +PyramidPositionOffsetCommandTest >> command [ + + ^ PyramidPositionOffsetCommand new +] + +{ #category : #'as yet unclassified' } +PyramidPositionOffsetCommandTest >> targetContainers [ + + ^ { + (PyramidCommandTestContainer + no: BlElement new + with: (BlElement new + position: 50 @ 50; + yourself) + prop: 50 @ 50). + (PyramidCommandTestContainer + no: (BlElement new + position: 50 @ 50; + yourself) + with: (BlElement new + position: 100 @ 100; + yourself) + prop: 50 @ 50) } +] + +{ #category : #accessing } +PyramidPositionOffsetCommandTest >> targetsWithValuesAndValues [ + + ^ self targetContainers collect: [ :each | + each targetWithProp -> each targetWithProp constraints position ] +] + +{ #category : #tests } +PyramidPositionOffsetCommandTest >> testSetValueForWith [ + + self targetsWithoutValuesAndValues do: [ :each | + | initialValue | + initialValue := self command getValueFor: each key. + self command setValueFor: each key with: each value. + self assert: (self command getValueFor: each key) equals: each value + initialValue ] +] From 837ccabe7754364a247137adac730b33aaca9b55 Mon Sep 17 00:00:00 2001 From: YannLEGOFF Date: Fri, 28 Jul 2023 10:11:36 +0200 Subject: [PATCH 3/3] command history TU --- .../PyramidPositionOffsetCommand.class.st | 22 ++++---- .../PyramidPositionOffsetCommandTest.class.st | 54 +++++++++++++++++++ .../TPyramidCommandTest.trait.st | 52 ++++++++++++++++++ 3 files changed, 115 insertions(+), 13 deletions(-) diff --git a/src/Pyramid-Bloc/PyramidPositionOffsetCommand.class.st b/src/Pyramid-Bloc/PyramidPositionOffsetCommand.class.st index dd22de5d..c90e258b 100644 --- a/src/Pyramid-Bloc/PyramidPositionOffsetCommand.class.st +++ b/src/Pyramid-Bloc/PyramidPositionOffsetCommand.class.st @@ -4,6 +4,12 @@ Class { #category : #'Pyramid-Bloc-plugin-bloc' } +{ #category : #'as yet unclassified' } +PyramidPositionOffsetCommand >> commandInverse [ + + ^ PyramidPositionCommand new +] + { #category : #'as yet unclassified' } PyramidPositionOffsetCommand >> getValueFor: aBlElement [ @@ -11,19 +17,9 @@ PyramidPositionOffsetCommand >> getValueFor: aBlElement [ ] { #category : #'as yet unclassified' } -PyramidPositionOffsetCommand >> saveStatesOf: aCollection withCommand: aCommand withArguments: anArguments [ - - | mementos | - mementos := aCollection collect: [ :each | - PyramidCommandMemento new - command: PyramidPositionCommand new; - target: each; - arguments: (self getValueFor: each); - yourself ]. - mementos size = 1 ifTrue: [ ^ mementos first ]. - ^ PyramidCompositeMemento new - mementos: mementos; - yourself +PyramidPositionOffsetCommand >> saveStatesOf: aCollection with: arguments [ + + ^ self saveStatesWithCommandInverseOf: aCollection with: arguments ] { #category : #'as yet unclassified' } diff --git a/src/Pyramid-Tests/PyramidPositionOffsetCommandTest.class.st b/src/Pyramid-Tests/PyramidPositionOffsetCommandTest.class.st index 538e7e67..34285057 100644 --- a/src/Pyramid-Tests/PyramidPositionOffsetCommandTest.class.st +++ b/src/Pyramid-Tests/PyramidPositionOffsetCommandTest.class.st @@ -39,6 +39,60 @@ PyramidPositionOffsetCommandTest >> targetsWithValuesAndValues [ each targetWithProp -> each targetWithProp constraints position ] ] +{ #category : #tests } +PyramidPositionOffsetCommandTest >> testHistory [ + "Do once. + undo + redo + undo + redo" + + | history commandExecutor targets initialValue | + targets := { + BlElement new. + BlElement new. + BlElement new }. + initialValue := 0 @ 0. + history := PyramidHistory new. + commandExecutor := PyramidHistoryCommandExecutor new + history: history; + wrappee: PyramidMainCommandExecutor new; + yourself. + + "Do once" + self argumentsForHistory do: [ :each | + commandExecutor use: self command on: targets with: each. + initialValue := initialValue + each ]. + + "Undo all" + self argumentsForHistory reverseDo: [ :argument | + targets do: [ :target | + self assert: (self command getValueFor: target) equals: initialValue ]. + initialValue := initialValue - argument. + history canUndo ifTrue: [ history undo ] ]. + + "Redo all" + self argumentsForHistory do: [ :argument | + initialValue := initialValue + argument. + history canRedo ifTrue: [ history redo ]. + targets do: [ :target | + self assert: (self command getValueFor: target) equals: initialValue ] ]. + + "Undo all" + self argumentsForHistory reverseDo: [ :argument | + targets do: [ :target | + self assert: (self command getValueFor: target) equals: initialValue ]. + initialValue := initialValue - argument. + history canUndo ifTrue: [ history undo ] ]. + + "Redo all" + self argumentsForHistory do: [ :argument | + initialValue := initialValue + argument. + history canRedo ifTrue: [ history redo ]. + targets do: [ :target | + self assert: (self command getValueFor: target) equals: initialValue ] ] +] + { #category : #tests } PyramidPositionOffsetCommandTest >> testSetValueForWith [ diff --git a/src/Pyramid-Tests/TPyramidCommandTest.trait.st b/src/Pyramid-Tests/TPyramidCommandTest.trait.st index 7183effb..4ce5e66f 100644 --- a/src/Pyramid-Tests/TPyramidCommandTest.trait.st +++ b/src/Pyramid-Tests/TPyramidCommandTest.trait.st @@ -3,6 +3,13 @@ Trait { #category : #'Pyramid-Tests-cases-plugin-bloc' } +{ #category : #'as yet unclassified' } +TPyramidCommandTest >> argumentsForHistory [ + + + ^ self targetContainers collect: [ :each | each prop ] +] + { #category : #accessing } TPyramidCommandTest >> command [ @@ -56,6 +63,51 @@ TPyramidCommandTest >> testGetValueFor [ self assert: (self command getValueFor: each key) equals: each value ]. ] +{ #category : #tests } +TPyramidCommandTest >> testHistory [ + "Do once. + undo + redo + undo + redo" + + | history commandExecutor targets | + targets := self targetsCanBeUsedFor. + history := PyramidHistory new. + commandExecutor := PyramidHistoryCommandExecutor new + history: history; + wrappee: PyramidMainCommandExecutor new; + yourself. + + "Do once" + self argumentsForHistory do: [ :each | + commandExecutor use: self command on: targets with: each ]. + + "Undo all" + self argumentsForHistory reverseDo: [ :argument | + targets do: [ :target | + self assert: (self command getValueFor: target) equals: argument ]. + history canUndo ifTrue: [ history undo ] ]. + + "Redo all" + self argumentsForHistory do: [ :argument | + history canRedo ifTrue: [ history redo ]. + targets do: [ :target | + self assert: (self command getValueFor: target) equals: argument ] ]. + + "Undo all" + self argumentsForHistory reverseDo: [ :argument | + targets do: [ :target | + self assert: (self command getValueFor: target) equals: argument ]. + history canUndo ifTrue: [ history undo ] ]. + + "Redo all" + self argumentsForHistory do: [ :argument | + history canRedo ifTrue: [ history redo ]. + targets do: [ :target | + self assert: (self command getValueFor: target) equals: argument ] ] +] + { #category : #tests } TPyramidCommandTest >> testSetValueForWith [