Test properties – a case study
In this section, we’ll explore writing different test properties by employing a small case study.
System under test
Our system under test is a compiler from a small expression language to a corresponding stack language.
We can use the following type of expression:
data Expr = Lit Int | Add Expr Expr | Sub Expr Expr | Mul Expr Expr deriving Show
It features literals, addition, subtraction, and multiplication.
The stack language features similar functionality, but the parameters of the binary operators are not explicitly given. Instead, they are taken from a stack:
data Instr = Push Int | Plus | Minus | Times type Prog = [Instr] type Stack = [Int]
A program in the stack language is a sequence of instructions that are executed consecutively:
exec :: Prog -> Stack -> Maybe Stack exec [] s = Just s exec (i:is) s ...