I want to create some tests with varying values, using hspec. I wrote the following code which does not compile but give an idea of what I am aiming at:
spec :: Spec
spec = do
describe "productOneLine" $ do
let
inVector = Data.Vector.replicate 0 0
inInteger = 3
outVector = Data.Vector.replicate 1 0
in
it "must manage empty vector" $ productOneLine inVector inInteger `shouldBe` outVector
let
inVector = Data.Vector.fromList [2, 4, 5]
inInteger = 4
outVector = Data.Vector.fromList [9, 6, 1, 2]
in
it "must multiply a vector by an integer" $ productOneLine inVector inInteger `shouldBe` outVector
How can I create different sets of inVector, inInteger et outVector for each ligne beginning with it ?
Assuming you're getting the error:
the problem is just indentation, as per @n.`pronouns'm.'s comment.
In most cases, a
letblock can be written with theletandinkeywords lining up:In fact, the
incan be less indented than thelet, it just needs to be indented more than thefoo:However, in a
doblock, anin-lessletstatement is allowed:If you try to write:
the
let s = "Hello"is parsed as aletstatement, and thein PutStrLn sis parsed as a seconddostatement, with invalid syntax as it starts with the reserved wordin.You can write:
or:
or:
In each case, the indention will cause the entire expression
let ... in ...to be parsed as a single expression, which is itself a validdo-statement. Combining two such statements is easy enough: