diff options
-rw-r--r-- | src/Xanthous/Data.hs | 3 | ||||
-rw-r--r-- | test/Xanthous/DataSpec.hs | 9 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/Xanthous/Data.hs b/src/Xanthous/Data.hs index ff11a8da7f80..b7df191e58a8 100644 --- a/src/Xanthous/Data.hs +++ b/src/Xanthous/Data.hs @@ -136,7 +136,8 @@ diffPositions (Position x₁ y₁) (Position x₂ y₂) = Position (x₁ - x₂) -- -- ∀ dir :: Direction. isUnit ('asPosition' dir) isUnit :: Position -> Bool -isUnit (Position px py) = abs px == 1 || abs py == 1 +isUnit (Position px py) = + abs px `elem` [0,1] && abs py `elem` [0, 1] && (px, py) /= (0, 0) -------------------------------------------------------------------------------- diff --git a/test/Xanthous/DataSpec.hs b/test/Xanthous/DataSpec.hs index 6b94e6a0582a..26a862baa6a6 100644 --- a/test/Xanthous/DataSpec.hs +++ b/test/Xanthous/DataSpec.hs @@ -26,7 +26,14 @@ test = testGroup "Xanthous.Data" directionOf pos (move dir pos) == dir , testProperty "diffPositions is add inverse" $ \pos₁ pos₂ -> diffPositions pos₁ pos₂ == addPositions pos₁ (invert pos₂) - + , testGroup "isUnit" + [ testProperty "double direction is never unit" $ \dir -> + not . isUnit $ move dir (asPosition dir) + , testCase "examples" $ do + isUnit (Position 1 1) @? "not . isUnit $ Position 1 1" + isUnit (Position 0 (-1)) @? "not . isUnit $ Position 0 (-1)" + (not . isUnit) (Position 1 13) @? "isUnit $ Position 1 13" + ] ] , testGroup "Direction" [ testProperty "opposite is involutive" $ \(dir :: Direction) -> |