-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathkeppy_test.rb
More file actions
69 lines (57 loc) · 1.84 KB
/
keppy_test.rb
File metadata and controls
69 lines (57 loc) · 1.84 KB
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
require 'minitest/autorun'
require_relative './keppy.rb'
class ParseRulesTest < MiniTest::Unit::TestCase
def setup
@parse_tree = [
{:state => "[", :possible_states => ["{", "(", "["], :close_this_state => "]"},
{:state => "{", :possible_states => ["{", "(", "["], :close_this_state => "}"},
{:state => "(", :possible_states => ["{", "(", "["], :close_this_state => ")"}
]
end
def test_parse_rules_with_existing_delim
# This is a stack that has seen an opening paren
stack = ["("]
parse_rules = ParseRules.new(@parse_tree)
parse_rules.method(:"(").call(")", stack)
assert_equal([], stack)
end
def test_parse_rules_with_wrong_match
stack = ["{"]
parse_rules = ParseRules.new(@parse_tree)
result = parse_rules.method(:"{").call(")", stack)
assert_equal(false, result)
end
def test_parse_rules_wrong_match_with_multiple_delims
stack = ["(", "{", "["]
parse_rules = ParseRules.new(@parse_tree)
result = parse_rules.method(:"[").call(")", stack)
assert_equal(false, result)
end
def test_parse_rules_correct_match_multiple_delims
stack = ["(", "{", "["]
expected_stack = ["(", "{"]
parse_rules = ParseRules.new(@parse_tree)
result = parse_rules.method(:"[").call("]", stack)
assert_equal(expected_stack, stack)
end
end
class StringParserTest < MiniTest::Unit::TestCase
def test_closing_delim
parser = StringParser.new
assert_equal(false, parser.solve("]"))
end
def test_open_delim
parser = StringParser.new
assert_equal(false, parser.solve("["))
end
def test_complicated_correct
parser = StringParser.new
chars = "()[]{}([{}])([]{})"
assert_equal(true, parser.solve(chars))
end
def test_complicated_incorrect
parser = StringParser.new
chars = "([)]([][])([})"
assert_equal(false, parser.solve(chars))
end
end