logic 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/array.rb CHANGED
@@ -4,4 +4,8 @@ class Array
4
4
  length
5
5
  end
6
6
 
7
+ def to_s
8
+ inspect
9
+ end
10
+
7
11
  end
@@ -1,14 +1,19 @@
1
1
  require 'array'
2
+ require 'test_case_set'
2
3
  require 'truth_table'
3
4
 
4
5
  module LogicStatement
5
6
 
7
+ def test_cases
8
+ @test_cases ||= TestCaseSet.new(condition_count, self)
9
+ end
10
+
6
11
  def truth_table
7
- TruthTable.new(condition_count) { |conditions| evaluate(conditions) }
12
+ TruthTable.new(test_cases)
8
13
  end
9
14
 
10
15
  def mcdc_pairs
11
- truth_table.mcdc_pairs
16
+ test_cases.mcdc_pairs
12
17
  end
13
18
 
14
19
  def condition_count
data/lib/test_case.rb CHANGED
@@ -1,6 +1,6 @@
1
+ require 'integer'
1
2
  require 'range'
2
3
  require 'symbol'
3
- require 'integer'
4
4
 
5
5
  class TestCase
6
6
 
@@ -24,7 +24,7 @@ class TestCase
24
24
  end
25
25
 
26
26
  def output
27
- @decision.call(conditions.dup)
27
+ @decision.evaluate(conditions.dup)
28
28
  end
29
29
 
30
30
  def mcdc_pair(index)
@@ -0,0 +1,55 @@
1
+ require 'test_case'
2
+
3
+ class TestCaseSet
4
+
5
+ def initialize(condition_count, decision)
6
+ @condition_count = condition_count
7
+ @decision = decision
8
+ @test_cases = create_cases
9
+ end
10
+
11
+ def create_cases
12
+ case_numbers.map do |case_number|
13
+ TestCase.new(case_number, @condition_count, @decision)
14
+ end
15
+ end
16
+
17
+ def case_numbers
18
+ 1..2**@condition_count
19
+ end
20
+
21
+ def condition_identifiers
22
+ identifier_range.take(@condition_count)
23
+ end
24
+
25
+ def identifier_range
26
+ 'a'..'z'
27
+ end
28
+
29
+ def mcdc_pairs
30
+ condition_identifiers.map do |condition_identifier|
31
+ "#{condition_identifier} => #{mcdc_pairs_for(condition_identifier)}"
32
+ end
33
+ end
34
+
35
+ def mcdc_pairs_for(condition_identifier)
36
+ @test_cases.inject([]) do |mcdc_cases, test_case|
37
+ mcdc_pair = test_case.mcdc_pair(index_of(condition_identifier))
38
+ mcdc_cases << mcdc_pair if test_case.is_mcdc_case_for_index?(index_of(condition_identifier))
39
+ mcdc_cases
40
+ end.uniq
41
+ end
42
+
43
+ def index_of(condition_identifier)
44
+ identifier_range.to_a.index(condition_identifier)
45
+ end
46
+
47
+ def count
48
+ @test_cases.count
49
+ end
50
+
51
+ def inject(initial, &block)
52
+ @test_cases.inject(initial, &block)
53
+ end
54
+
55
+ end
data/lib/truth_table.rb CHANGED
@@ -1,42 +1,7 @@
1
- require 'test_case'
2
-
3
1
  class TruthTable
4
2
 
5
- def initialize(condition_count, &decision)
6
- @condition_count = condition_count
7
- @decision = decision
8
- end
9
-
10
- def condition_identifiers
11
- identifier_range.take(@condition_count)
12
- end
13
-
14
- def cases
15
- case_numbers.map do |case_number|
16
- TestCase.new(case_number, @condition_count, @decision)
17
- end
18
- end
19
-
20
- def case_numbers
21
- 1..2**@condition_count
22
- end
23
-
24
- def mcdc_pairs
25
- condition_identifiers.map do |condition_identifier|
26
- "#{condition_identifier} => #{mcdc_pairs_for(condition_identifier).inspect}"
27
- end
28
- end
29
-
30
- def mcdc_pairs_for(condition_identifier)
31
- cases.inject([]) do |mcdc_cases, test_case|
32
- mcdc_pair = test_case.mcdc_pair(index_of(condition_identifier))
33
- mcdc_cases << mcdc_pair if test_case.is_mcdc_case_for_index?(index_of(condition_identifier))
34
- mcdc_cases
35
- end.uniq
36
- end
37
-
38
- def index_of(condition_identifier)
39
- identifier_range.to_a.index(condition_identifier)
3
+ def initialize(test_cases)
4
+ @test_cases = test_cases
40
5
  end
41
6
 
42
7
  def to_s
@@ -44,18 +9,14 @@ class TruthTable
44
9
  end
45
10
 
46
11
  def header
47
- conditions = condition_identifiers.join(" ")
12
+ conditions = @test_cases.condition_identifiers.join(" ")
48
13
  "#{conditions.rjust(conditions.length + 4)} | output\n"
49
14
  end
50
15
 
51
16
  def formatted_cases
52
- cases.inject("") do |output, test_case|
17
+ @test_cases.inject("") do |output, test_case|
53
18
  output += "#{test_case.number.to_s.rjust(2)}) #{test_case.conditions.join(' ')} | #{test_case.output.to_s.rjust(3)}\n"
54
19
  end
55
20
  end
56
21
 
57
- def identifier_range
58
- 'a'..'z'
59
- end
60
-
61
22
  end
@@ -0,0 +1,23 @@
1
+ require 'test_case_set'
2
+
3
+ describe TestCaseSet do
4
+
5
+ describe "with 1 condition" do
6
+
7
+ let(:test_case_set) { TestCaseSet.new(1, nil) }
8
+
9
+ describe :condition_dentifiers do
10
+
11
+ it "includes 'a'" do
12
+ test_case_set.condition_identifiers.should include('a')
13
+ end
14
+
15
+ end
16
+
17
+ it "has 2 test cases" do
18
+ test_case_set.count.should == 2
19
+ end
20
+
21
+ end
22
+
23
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Bryan Ash
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-07 00:00:00 -04:00
17
+ date: 2010-04-08 00:00:00 -04:00
18
18
  default_executable: logic
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -58,15 +58,16 @@ files:
58
58
  - lib/array.rb
59
59
  - lib/integer.rb
60
60
  - lib/logic_operations.rb
61
+ - lib/logic_parser.treetop
61
62
  - lib/range.rb
62
63
  - lib/symbol.rb
63
64
  - lib/test_case.rb
65
+ - lib/test_case_set.rb
64
66
  - lib/truth_table.rb
65
- - lib/logic_parser.treetop
66
67
  - bin/logic
67
68
  - spec/logic_parser_spec.rb
68
69
  - spec/spec.opts
69
- - spec/truth_table_spec.rb
70
+ - spec/test_case_set_spec.rb
70
71
  - LICENSE
71
72
  - README.rdoc
72
73
  has_rdoc: true
@@ -1,27 +0,0 @@
1
- require 'truth_table'
2
-
3
- describe TruthTable do
4
-
5
- describe "with 1 condition" do
6
-
7
- let(:table) { TruthTable.new(1) }
8
-
9
- describe :condition_dentifiers do
10
-
11
- it "includes 'a'" do
12
- table.condition_identifiers.should include('a')
13
- end
14
-
15
- end
16
-
17
- describe :cases do
18
-
19
- it "has 2 cases" do
20
- table.cases.length.should == 2
21
- end
22
-
23
- end
24
-
25
- end
26
-
27
- end