1
exercism fetch crystal bracket-push

spec/bracket_push_spec.cr

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
require "spec"
require "../src/*"

describe "Brackets" do
  describe "#are_valid?" do
    it "paired square brackets" do
      Brackets.are_valid?("[]").should be_true
    end
    it "empty string" do
      Brackets.are_valid?("").should be_true
    end
    it "unpaired brackets" do
      Brackets.are_valid?("[[").should be_false
    end
    it "wrong ordered brackets" do
      Brackets.are_valid?("}{").should be_false
    end
    it "paired with whitespace" do
      Brackets.are_valid?("{ }").should be_true
    end
    it "simple nested brackets" do
      Brackets.are_valid?("{[]}").should be_true
    end
    it "several paired brackets" do
      Brackets.are_valid?("{}[]").should be_true
    end
    it "paired and nested brackets" do
      Brackets.are_valid?("([{}({}[])])").should be_true
    end
    it "unopened closing brackets" do
      Brackets.are_valid?("{[)][]}").should be_false
    end
    it "unpaired and nested brackets" do
      Brackets.are_valid?("([{])").should be_false
    end
    it "paired and wrong nested brackets" do
      Brackets.are_valid?("[({]})").should be_false
    end
    it "math expression" do
      Brackets.are_valid?("(((185 + 223.85) * 15) - 543)/2").should be_true
    end
    it "complex latex expression" do
      Brackets.are_valid?("\left(\begin{array}{cc} \frac{1}{3} & x\\ \mathrm{e}^{x} &... x^2 \end{array}\right)").should be_true
    end
  end
end