logic 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
- require 'array'
2
1
  require 'test_case_set'
3
2
  require 'truth_table'
4
3
 
@@ -87,3 +86,9 @@ module Or
87
86
  a | b
88
87
  end
89
88
  end
89
+
90
+ module Xor
91
+ def apply(a, b)
92
+ a ^ b
93
+ end
94
+ end
@@ -30,6 +30,8 @@ grammar Logic
30
30
  'and' <And>
31
31
  /
32
32
  'or' <Or>
33
+ /
34
+ 'xor' <Xor>
33
35
  end
34
36
 
35
37
  rule space
data/lib/test_case_set.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'array'
1
2
  require 'test_case'
2
3
 
3
4
  class TestCaseSet
@@ -8,48 +8,38 @@ describe LogicParser, :parsing do
8
8
  let(:parser) { LogicParser.new }
9
9
 
10
10
  describe "a single condition" do
11
-
12
11
  it "identifies the condition" do
13
12
  decision = parser.parse('Hello')
14
13
  decision.condition_identifiers.should == ['Hello']
15
14
  end
16
-
17
15
  end
18
16
 
19
17
  describe "'A or B'" do
20
-
21
18
  it "condition identifiers are ['A','B']" do
22
19
  decision = parser.parse('A or B')
23
20
  decision.condition_identifiers.should == ['A','B']
24
21
  end
25
-
26
22
  end
27
23
 
28
24
  describe "'A or B or C'" do
29
-
30
25
  it "condition identifiers are ['A','B','C']" do
31
26
  decision = parser.parse('A or B or C')
32
27
  decision.condition_identifiers.should == ['A','B','C']
33
28
  end
34
-
35
29
  end
36
30
 
37
31
  describe "'A and B'" do
38
-
39
32
  it "conditions are ['A','B']" do
40
33
  decision = parser.parse('A and B')
41
34
  decision.condition_identifiers.should == ['A','B']
42
35
  end
43
-
44
36
  end
45
37
 
46
38
  describe "'A and B and C'" do
47
-
48
39
  it "condition identifiers are ['A','B','C']" do
49
40
  decision = parser.parse('A and B and C')
50
41
  decision.condition_identifiers.should == ['A','B','C']
51
42
  end
52
-
53
43
  end
54
44
 
55
45
  { 'Hello' =>
@@ -69,6 +59,12 @@ describe LogicParser, :parsing do
69
59
  [0, 1] => 1,
70
60
  [1, 0] => 1
71
61
  },
62
+ 'A xor B' =>
63
+ { [0, 0] => 0,
64
+ [0, 1] => 1,
65
+ [1, 0] => 1,
66
+ [1, 1] => 0
67
+ },
72
68
  'A and B' =>
73
69
  { [1, 1] => 1,
74
70
  [0, 1] => 0,
@@ -3,12 +3,10 @@ require 'test_case_set'
3
3
  describe TestCaseSet do
4
4
 
5
5
  describe "with 1 condition" do
6
-
7
6
  it "input_dentifiers includes 'a'" do
8
7
  test_case_set = TestCaseSet.new(['hello'], nil)
9
8
  test_case_set.input_identifiers.should include('a')
10
9
  end
11
-
12
10
  end
13
11
 
14
12
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bryan Ash