feat: tests for the rendering/parsing
This commit is contained in:
parent
9484d097d4
commit
d012307d19
8 changed files with 104 additions and 45 deletions
|
@ -1,7 +1,13 @@
|
|||
{-# LANGUAGE DerivingStrategies #-}
|
||||
{-# LANGUAGE InstanceSigs #-}
|
||||
module Language.Brainfuck.Instruction (Instruction(..)) where
|
||||
|
||||
import Data.Vector ( Vector )
|
||||
import Test.QuickCheck.Gen (Gen)
|
||||
import Test.QuickCheck.Arbitrary (Arbitrary (arbitrary))
|
||||
import Test.QuickCheck.Instances.Vector ()
|
||||
|
||||
import qualified Test.QuickCheck.Gen as Gen
|
||||
|
||||
data Instruction
|
||||
= Increment
|
||||
|
@ -12,3 +18,20 @@ data Instruction
|
|||
| PutByte
|
||||
| Loop (Vector Instruction)
|
||||
deriving stock (Show, Eq)
|
||||
|
||||
instance Arbitrary Instruction where
|
||||
arbitrary :: Gen Instruction
|
||||
arbitrary = Gen.oneof $
|
||||
[ pure Increment
|
||||
, pure Decrement
|
||||
, pure MoveLeft
|
||||
, pure MoveRight
|
||||
, pure ReadByte
|
||||
, pure PutByte
|
||||
, Loop <$> reduceSize 8 arbitrary
|
||||
]
|
||||
where
|
||||
reduceSize d g = Gen.sized $ \ s -> Gen.resize (s `div` d) g
|
||||
|
||||
-- >>> Gen.generate (Gen.resize 30 arbitrary) :: IO [Instruction]
|
||||
-- [MoveLeft,Decrement,PutByte,Decrement,Decrement,Increment,ReadByte,MoveLeft,Increment,Loop [],MoveRight,Increment,Increment,Loop [],MoveLeft,Loop [],MoveRight,ReadByte,ReadByte,MoveLeft,Decrement,MoveRight,MoveLeft,Loop [PutByte,Increment,Loop []],Decrement]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue