1
exercism fetch purescript pascals-triangle

test/Main.purs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module Test.Main where

import Prelude
import Test.Unit.Assert as Assert
import Control.Monad.Eff (Eff)
import Control.Monad.Aff.AVar (AVAR)
import Control.Monad.Eff.Console (CONSOLE)
import Data.Maybe (Maybe(..))
import PascalsTriangle (rows)
import Test.Unit (TestSuite, suite, test)
import Test.Unit.Console (TESTOUTPUT)
import Test.Unit.Main (runTest)

main :: forall eff
  . Eff ( avar :: AVAR
        , console :: CONSOLE
        , testOutput :: TESTOUTPUT
        | eff                     
        )
        Unit
main = runTest suites

suites :: forall e. TestSuite e
suites = do
  suite "Given a count, return a collection of that many rows of pascal's triangle" do
      
      test "zero rows" $
        Assert.equal
          (Just
            []
          )
          (rows (Just 0))
      
      test "single row" $
        Assert.equal
          (Just
            [[1]]
          )
          (rows (Just 1))
      
      test "two rows" $
        Assert.equal
          (Just
            [ [1]
            , [1,1]
            ]
          )
          (rows (Just 2))
      
      test "three rows" $
        Assert.equal
          (Just
            [ [1]
            , [1,1]
            , [1,2,1]
            ]
          )
          (rows (Just 3))
      
      test "four rows" $
        Assert.equal
          (Just
            [ [1]
            , [1,1]
            , [1,2,1]
            , [1,3,3,1]
            ]
          )
          (rows (Just 4))
      
      test "negative rows" $
        Assert.equal
          Nothing
          (rows (Just (-1)))
      
      test "null/no rows" $
        Assert.equal
          Nothing
          (rows Nothing)