1
exercism fetch purescript bracket-push

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
module Test.Main where

import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.AVar (AVAR)
import Control.Monad.Eff.Console (CONSOLE)
import Test.Unit.Assert as Assert
import Test.Unit (TestSuite, suite, test)
import Test.Unit.Console (TESTOUTPUT)
import Test.Unit.Main (runTest)
import BracketPush (isPaired)

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

suites :: forall e. TestSuite e
suites = do
  suite "BracketPush.isPaired" do

    test "paired square brackets" $
      Assert.equal true
                   (isPaired "[]")

    test "empty string" $
      Assert.equal true
                   (isPaired "")

    test "unpaired brackets" $
      Assert.equal false
                   (isPaired "[[")

    test "wrong ordered brackets" $
      Assert.equal false
                   (isPaired "}{")

    test "paired with whitespace" $
      Assert.equal true
                   (isPaired "{ }")

    test "simple nested brackets" $
      Assert.equal true
                   (isPaired "{[]}")

    test "several paired brackets" $
      Assert.equal true
                   (isPaired "{}[]")

    test "paired and nested brackets" $
      Assert.equal true
                   (isPaired "([{}({}[])])")

    test "unopened closing brackets" $
      Assert.equal false
                   (isPaired "{[)][]}")

    test "unpaired and nested brackets" $
      Assert.equal false
                   (isPaired "([{])")

    test "paired and wrong nested brackets" $
      Assert.equal false
                   (isPaired "[({]})")

    test "math expression" $
      Assert.equal true
                   (isPaired "(((185 + 223.85) * 15) - 543)/2")

    test "complex latex expression" $
      Assert.equal true
                   (isPaired "\\left(\\begin{array}{cc} \\frac{1}{3} & x\\\\ \\mathrm{e}^{x} &... x^2 \\end{array}\\right)")