Skip to content

Commit 2c93809

Browse files
committed
WIP
1 parent 788cc5b commit 2c93809

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/Trace.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ data LongLinDiff = LongLinDiff Axis Int8
2323
deriving (Eq, Show)
2424

2525
data NearDiff = NearDiff Int8 Int8 Int8
26+
deriving (Eq, Show)
2627

28+
data FarDiff = FarDiff Int8 Int8 Int8
2729
deriving (Eq, Show)
2830

2931
data Command =
@@ -36,6 +38,8 @@ data Command =
3638
| Fill NearDiff
3739
| FusionP NearDiff
3840
| FusionS NearDiff
41+
| GFill NearDiff FarDiff
42+
| GVoid NearDiff FarDiff
3943
deriving (Eq, Show)
4044

4145
instance Coded Axis where
@@ -85,6 +89,21 @@ instance Coded NearDiff where
8589
x = xy `div` 3
8690
return $ NearDiff (x-1) (y-1) (z-1)
8791

92+
instance Coded FarDiff where
93+
encode (FarDiff dx dy dz) = do
94+
putBits 7 0 ((dx + 30) :: Word8)
95+
putBits 7 0 ((dy + 30) :: Word8)
96+
putBits 7 0 ((dz + 30) :: Word8)
97+
98+
decode = do
99+
dx <- getWord8
100+
dy <- getWord8
101+
dz <- getWord8
102+
FarDiff
103+
<$> ((fromIntegral dx)-30)
104+
<*> ((fromIntegral dy)-30)
105+
<*> ((fromIntegral dz)-30)
106+
88107
instance Coded Command where
89108
encode Halt = putBits 7 0 (0b11111111 :: Word8)
90109
encode Wait = putBits 7 0 (0b11111110 :: Word8)
@@ -121,6 +140,10 @@ instance Coded Command where
121140
encode nd
122141
putBits 2 0 (0b011 :: Int)
123142

143+
encode (GFill nd fd) = undefined
144+
145+
encode (GVoid nd fd) = undefined
146+
124147
decode = parseOpcode =<< getWord8
125148
where
126149
parseOpcode :: MonadGet m => Word8 -> Coding m Command

test/TestSpec.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ specExamples = testGroup "Specification examples"
5353

5454
, testCase "encode.Fill" $
5555
testEncode (Fill (NearDiff 0 (-1) 0)) @?= "01010011"
56+
57+
, testCsae "encode.GFill" $
58+
testEncode (GFill (NearDiff 0 (-1) 0) (FarDiff 10 (-15) 20)) @?= "01010001 00101000 00001111 00110010"
59+
60+
, testCase "encode.GVoid" $
61+
testEncode (GVoid (NearDiff 1 0 0) (FarDiff 5 5 (-5))) @?= "10110000 00100011 00100011 00011001"
5662
]
5763

5864
testCodecFor :: (Eq a, Show a, Coded a) => a -> Assertion
@@ -83,4 +89,10 @@ codec = testGroup "Encoding-then-decoding returns the same value"
8389
, testCase "Fission" $ testCodecFor (Fission (NearDiff 0 0 1) 5)
8490

8591
, testCase "Fill" $ testCodecFor (Fill (NearDiff 0 (-1) 0))
92+
93+
, testCsae "GFill" $
94+
testCodecFor (GFill (NearDiff 0 (-1) 0) (FarDiff 10 (-15) 20))
95+
96+
, testCase "GVoid" $
97+
testCodecFor (GVoid (NearDiff 1 0 0) (FarDiff 5 5 (-5)))
8698
]

0 commit comments

Comments
 (0)