Skip to content

Commit

Permalink
Added tests for Ruler Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Lietze committed Jun 27, 2022
1 parent e19a6d6 commit 632d24e
Show file tree
Hide file tree
Showing 30 changed files with 156 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ inputMouseUp: aPosition
startPosition: nil;
endPosition: nil.
self process terminate.
self arrowMorph delete]
self arrowMorph ifNotNil:[self arrowMorph delete]]


Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"inputField" : "OB 6/15/2022 09:48",
"inputField:" : "OB 6/15/2022 09:48",
"inputMouseDown:" : "ML 6/26/2022 16:16",
"inputMouseUp:" : "ML 6/26/2022 16:46",
"inputMouseUp:" : "ML 6/27/2022 16:18",
"manualStep" : "ML 6/26/2022 16:27",
"map" : "OB 6/13/2022 08:46",
"map:" : "OB 6/13/2022 08:46",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
converting
convertPixelPositionToTileCoordinates: aPoint

^ ((aPoint - self position) / TTTile defaultSize) rounded + (1 @ 1)
^ ((aPoint - self position) / TTTile defaultSize) floor + (1 @ 1)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"class" : {
"newWith:" : "ML 6/26/2022 14:54" },
"instance" : {
"convertPixelPositionToTileCoordinates:" : "ML 6/26/2022 17:06",
"convertPixelPositionToTileCoordinates:" : "ML 6/27/2022 15:30",
"convertTileCoordinatesToPixelPosition:" : "rf 5/8/2021 10:27",
"createAndInsertTileAt:" : "rf 7/8/2021 10:07",
"createSpecWith:" : "PB 7/3/2021 10:39",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
initialize-release
initialize

super initialize.
self outputs: OrderedCollection new.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
actions
logInput: aString

self outputs add: aString
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
actions
logOutput: aString

self outputs add: aString
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
outputs: anObject
outputs := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
outputs
^ outputs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"class" : {
},
"instance" : {
"initialize" : "ML 6/27/2022 16:09",
"logInput:" : "ML 6/27/2022 16:10",
"logOutput:" : "ML 6/27/2022 16:10",
"outputs" : "ML 6/27/2022 16:09",
"outputs:" : "ML 6/27/2022 16:09" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"category" : "TabletopUI-Tests",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"outputs" ],
"name" : "TTMockActionLog",
"pools" : [
],
"super" : "Object",
"type" : "normal" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ as yet unclassified
initialize

super initialize.
self inputs: OrderedCollection new
self inputs: OrderedCollection new.
self log: TTMockActionLog new
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
log: anObject
log := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
log
^ log
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"class" : {
},
"instance" : {
"initialize" : "ML 6/1/2022 20:03",
"initialize" : "ML 6/27/2022 16:11",
"inputs" : "ML 6/1/2022 20:03",
"inputs:" : "ML 6/1/2022 20:03",
"log" : "ML 6/27/2022 16:08",
"log:" : "ML 6/27/2022 16:08",
"processInput:" : "ML 6/1/2022 20:03" } }
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
],
"commentStamp" : "",
"instvars" : [
"inputs" ],
"inputs",
"log" ],
"name" : "TTMockInputField",
"pools" : [
],
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
inputField: anObject
inputField := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
inputField
^ inputField
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
map: anObject
map := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
map
^ map
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
rulerTool: anObject
rulerTool := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
rulerTool
^ rulerTool
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
testing
setUp

self inputField: TTMockInputField new.
self map: (TTMap newWith: OrderedCollection new).
self rulerTool: (TTRulerTool newWithMap: self map inputField: self inputField)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
testing
test01CalculateDistanceWithEnd

| result |
self rulerTool startPosition: (self map convertTileCoordinatesToPixelPosition: 1 @ 1).
result := self rulerTool calculateDistanceWithEnd: (self map convertTileCoordinatesToPixelPosition: 1 @ 1).
self assert: result equals: 0.
result := self rulerTool calculateDistanceWithEnd: (self map convertTileCoordinatesToPixelPosition: 2 @ 1).
self assert: result equals: 5.
result := self rulerTool calculateDistanceWithEnd: (self map convertTileCoordinatesToPixelPosition: 1 @ 2).
self assert: result equals: 5.
result := self rulerTool calculateDistanceWithEnd: (self map convertTileCoordinatesToPixelPosition: 2 @ 2).
self assert: result equals: 5.
result := self rulerTool calculateDistanceWithEnd: (self map convertTileCoordinatesToPixelPosition: 4 @ 2).
self assert: result equals: 15.
result := self rulerTool calculateDistanceWithEnd: (self map convertTileCoordinatesToPixelPosition: -9 @ 2).
self assert: result equals: 50.
"this is expected, as long as the conversion is only math based and does not check whether tiles actually exist"
result := self rulerTool calculateDistanceWithEnd: (self map convertTileCoordinatesToPixelPosition: 9 @ 10).
self assert: result equals: 45.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
testing
test02CalculateDistance

| result |
self rulerTool startPosition: (self map convertTileCoordinatesToPixelPosition: 1 @ 1).
self rulerTool endPosition: (self map convertTileCoordinatesToPixelPosition: 1 @ 1).
result := self rulerTool calculateDistance.
self assert: result equals: 0.
self rulerTool endPosition: (self map convertTileCoordinatesToPixelPosition: 10 @ 1).
result := self rulerTool calculateDistance.
self assert: result equals: 45.
self rulerTool endPosition: (self map convertTileCoordinatesToPixelPosition: 2 @ 2).
result := self rulerTool calculateDistance.
self assert: result equals: 5.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
testing
test03MouseDownMouseUp

| result |
self rulerTool inputMouseDown: (self map convertTileCoordinatesToPixelPosition: 1 @ 1).
self rulerTool inputMouseUp: (self map convertTileCoordinatesToPixelPosition: 1 @ 1).
result := self inputField log outputs first.
self inputField log outputs removeFirst.
self assert: result equals: 'Distance measured: 0ft'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"class" : {
},
"instance" : {
"inputField" : "ML 6/27/2022 15:38",
"inputField:" : "ML 6/27/2022 15:38",
"map" : "ML 6/27/2022 15:38",
"map:" : "ML 6/27/2022 15:38",
"rulerTool" : "ML 6/27/2022 15:36",
"rulerTool:" : "ML 6/27/2022 15:36",
"setUp" : "ML 6/27/2022 15:40",
"test01CalculateDistanceWithEnd" : "ML 6/27/2022 15:51",
"test02CalculateDistance" : "ML 6/27/2022 15:54",
"test03MouseDownMouseUp" : "ML 6/27/2022 16:13" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category" : "TabletopUI-Tests",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"rulerTool",
"map",
"inputField" ],
"name" : "TTRulerToolTest",
"pools" : [
],
"super" : "TestCase",
"type" : "normal" }

0 comments on commit 632d24e

Please sign in to comment.