logic 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +53 -0
- data/lib/logic_parser.treetop +19 -7
- data/spec/logic_parser_spec.rb +12 -0
- metadata +4 -4
- data/README.rdoc +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f481073e7764c17e89d4b3dc6c815a4f80a6c5bbe1127e7c1eb6aed715a772cf
|
4
|
+
data.tar.gz: d376cb1038e3d591a8f08f7f729cac2cb63212bf253b42923391e594dc1b6f8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e5151ce6d38b0b049d8b10fe0daa4aaf35d8e10e8dd138239c64f76ede097fd80f724c9fd69c54a4cd628f4484465903fe2164c83555ef650ef4f7b7a999591
|
7
|
+
data.tar.gz: 155670f39c0a88e89fc7be17ac12338f984c89a4aede20af26d4587bd744967a4f18090c939ac3a30e2a3576bc35695c1a077844ed3799c747cdf8e8b3416d04
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# logic
|
2
|
+
|
3
|
+
Parses logic expressions to produce a truth table and MC/DC cases.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install logic
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
By default, you get a truth table and a list of MC/DC pairs:
|
12
|
+
|
13
|
+
logic '(apple or bongo) and (cat or dog)'
|
14
|
+
|
15
|
+
Gives you:
|
16
|
+
|
17
|
+
a <= apple
|
18
|
+
b <= bongo
|
19
|
+
c <= cat
|
20
|
+
d <= dog
|
21
|
+
|
22
|
+
a b c d | output
|
23
|
+
1) 0 0 0 0 | 0
|
24
|
+
2) 0 0 0 1 | 0
|
25
|
+
3) 0 0 1 0 | 0
|
26
|
+
4) 0 0 1 1 | 0
|
27
|
+
5) 0 1 0 0 | 0
|
28
|
+
6) 0 1 0 1 | 1
|
29
|
+
7) 0 1 1 0 | 1
|
30
|
+
8) 0 1 1 1 | 1
|
31
|
+
9) 1 0 0 0 | 0
|
32
|
+
10) 1 0 0 1 | 1
|
33
|
+
11) 1 0 1 0 | 1
|
34
|
+
12) 1 0 1 1 | 1
|
35
|
+
13) 1 1 0 0 | 0
|
36
|
+
14) 1 1 0 1 | 1
|
37
|
+
15) 1 1 1 0 | 1
|
38
|
+
16) 1 1 1 1 | 1
|
39
|
+
|
40
|
+
a => [[2, 10], [3, 11], [4, 12]]
|
41
|
+
b => [[2, 6], [3, 7], [4, 8]]
|
42
|
+
c => [[5, 7], [9, 11], [13, 15]]
|
43
|
+
d => [[5, 6], [9, 10], [13, 14]]
|
44
|
+
|
45
|
+
## Options
|
46
|
+
|
47
|
+
-l, --[no-]truth_table Show the truth table for the decision
|
48
|
+
-m, --[no-]mcdc_pairs Show MC/DC test case pairs
|
49
|
+
|
50
|
+
|
51
|
+
## Operators
|
52
|
+
|
53
|
+
The syntax understands: `and`, `&&`, `or`, `||`, `xor`, `^`, `not`, `!`, and parenthesis.
|
data/lib/logic_parser.treetop
CHANGED
@@ -8,21 +8,21 @@ grammar Logic
|
|
8
8
|
end
|
9
9
|
|
10
10
|
rule and_tail
|
11
|
-
(operator:
|
11
|
+
(operator:and_operator operand:primitive)* <Tail>
|
12
12
|
end
|
13
13
|
|
14
14
|
rule or_tail
|
15
|
-
(operator:
|
15
|
+
(operator:or_operator operand:conjunction)* <Tail>
|
16
16
|
end
|
17
17
|
|
18
|
-
rule
|
19
|
-
(space
|
18
|
+
rule and_operator
|
19
|
+
(space and space / space? '&&' space?) <And>
|
20
20
|
end
|
21
21
|
|
22
|
-
rule
|
23
|
-
(space
|
22
|
+
rule or_operator
|
23
|
+
(space or space / space? '||' space?) <Or>
|
24
24
|
/
|
25
|
-
(space
|
25
|
+
(space xor space / space? '^' space?) <Xor>
|
26
26
|
end
|
27
27
|
|
28
28
|
rule primitive
|
@@ -41,6 +41,18 @@ grammar Logic
|
|
41
41
|
'(' space? contents:disjunction space? ')' <Parenthesized>
|
42
42
|
end
|
43
43
|
|
44
|
+
rule and
|
45
|
+
[aA] [nN] [dD]
|
46
|
+
end
|
47
|
+
|
48
|
+
rule or
|
49
|
+
[oO] [rR]
|
50
|
+
end
|
51
|
+
|
52
|
+
rule xor
|
53
|
+
[xX] [oO] [rR]
|
54
|
+
end
|
55
|
+
|
44
56
|
rule space
|
45
57
|
[ \t\n\r]+
|
46
58
|
end
|
data/spec/logic_parser_spec.rb
CHANGED
@@ -68,6 +68,12 @@ describe LogicParser, :parsing do
|
|
68
68
|
[1, 0] => 1,
|
69
69
|
[1, 1] => 1
|
70
70
|
},
|
71
|
+
'A OR B' =>
|
72
|
+
{ [0, 0] => 0,
|
73
|
+
[0, 1] => 1,
|
74
|
+
[1, 0] => 1,
|
75
|
+
[1, 1] => 1
|
76
|
+
},
|
71
77
|
'A || B' =>
|
72
78
|
{ [0, 0] => 0,
|
73
79
|
[0, 1] => 1,
|
@@ -104,6 +110,12 @@ describe LogicParser, :parsing do
|
|
104
110
|
[1, 0] => 0,
|
105
111
|
[1, 1] => 1
|
106
112
|
},
|
113
|
+
'A AND B' =>
|
114
|
+
{ [0, 0] => 0,
|
115
|
+
[0, 1] => 0,
|
116
|
+
[1, 0] => 0,
|
117
|
+
[1, 1] => 1
|
118
|
+
},
|
107
119
|
'A && B' =>
|
108
120
|
{ [0, 0] => 0,
|
109
121
|
[0, 1] => 0,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Ash
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|
@@ -59,10 +59,10 @@ executables:
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files:
|
61
61
|
- LICENSE
|
62
|
-
- README.
|
62
|
+
- README.md
|
63
63
|
files:
|
64
64
|
- LICENSE
|
65
|
-
- README.
|
65
|
+
- README.md
|
66
66
|
- bin/logic
|
67
67
|
- lib/integer.rb
|
68
68
|
- lib/logic_operations.rb
|
data/README.rdoc
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
= logic
|
2
|
-
|
3
|
-
== Installation
|
4
|
-
|
5
|
-
gem install logic
|
6
|
-
|
7
|
-
== Usage
|
8
|
-
|
9
|
-
By default, you get a truth table and a list of MC/DC pairs:
|
10
|
-
|
11
|
-
logic '(apple or bongo) and (cat or dog)'
|
12
|
-
|
13
|
-
Gives you:
|
14
|
-
|
15
|
-
a <= apple
|
16
|
-
b <= bongo
|
17
|
-
c <= cat
|
18
|
-
d <= dog
|
19
|
-
|
20
|
-
a b c d | output
|
21
|
-
1) 0 0 0 0 | 0
|
22
|
-
2) 0 0 0 1 | 0
|
23
|
-
3) 0 0 1 0 | 0
|
24
|
-
4) 0 0 1 1 | 0
|
25
|
-
5) 0 1 0 0 | 0
|
26
|
-
6) 0 1 0 1 | 1
|
27
|
-
7) 0 1 1 0 | 1
|
28
|
-
8) 0 1 1 1 | 1
|
29
|
-
9) 1 0 0 0 | 0
|
30
|
-
10) 1 0 0 1 | 1
|
31
|
-
11) 1 0 1 0 | 1
|
32
|
-
12) 1 0 1 1 | 1
|
33
|
-
13) 1 1 0 0 | 0
|
34
|
-
14) 1 1 0 1 | 1
|
35
|
-
15) 1 1 1 0 | 1
|
36
|
-
16) 1 1 1 1 | 1
|
37
|
-
|
38
|
-
a => [[2, 10], [3, 11], [4, 12]]
|
39
|
-
b => [[2, 6], [3, 7], [4, 8]]
|
40
|
-
c => [[5, 7], [9, 11], [13, 15]]
|
41
|
-
d => [[5, 6], [9, 10], [13, 14]]
|
42
|
-
|
43
|
-
== Operators
|
44
|
-
|
45
|
-
The syntax understands: 'and', '&&', 'or', '||', 'xor', '^', 'not', '!', and parenthesis.
|
46
|
-
|
47
|
-
== Copyright
|
48
|
-
|
49
|
-
Copyright (c) 2019 Bryan Ash. See LICENSE for details.
|