nfa2dfa 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/spec/state_spec.rb CHANGED
@@ -1,101 +1,100 @@
1
- require 'rspec'
2
- require 'spec_helper'
3
- require_relative '../lib/state.rb'
4
-
5
- describe Nfa2Dfa::State do
6
- before(:each) do
7
- @end_state = State.new("end")
8
- @end_state.to_starting_node
9
- end
10
- context "should keep " do
11
- subject { State.new("state") }
12
-
13
- it "basic data" do
14
- subject.id.should eq "state"
15
- subject.is_final.should eq false
16
- end
17
-
18
- it "transitions as private data" do
19
- expect { subject.transitions }.to raise_error NoMethodError
20
- end
21
-
22
- it "added transitions" do
23
- trans = Transition.new(subject, "jump", @end_state)
24
- transes = subject.add_transition(trans)
25
- transes.size.should eq 1
26
- transes[0].should eq trans
27
- end
28
-
29
- it "cleared transition array" do
30
- subject.clear_transitions.size.should eq 0
31
- end
32
- end
33
-
34
- it "should be able to be finalized" do
35
- state_a = State.new("a")
36
- state_a.is_final.should eq false
37
- state_a.finalize
38
- state_a.is_final.should eq true
39
- state_a.finalize
40
- state_a.is_final.should eq true
41
- end
42
- it "should be able to be starting node" do
43
- state_a = State.new("a")
44
- state_a.is_starting.should eq false
45
- state_a.to_starting_node
46
- state_a.is_starting.should eq true
47
- state_a.to_starting_node
48
- state_a.is_starting.should eq true
49
- end
50
-
51
- context "gets correct next state" do
52
- trans = []
53
- state_a = State.new("a")
54
- state_b = State.new("b")
55
- state_c = State.new("c")
56
- trans[0] = Transition.new(state_a, "0", state_b)
57
- trans[1] = Transition.new(state_b, "1", state_a)
58
- trans[2] = Transition.new(state_a, "0", state_a)
59
- trans[3] = Transition.new(state_c, "1", state_a)
60
- trans[4] = Transition.new(state_a, "0", state_c)
61
- state_a.add_transition(trans[0])
62
- state_a.add_transition(trans[2])
63
- state_a.add_transition(trans[4])
64
- state_b.add_transition(trans[1])
65
- state_c.add_transition(trans[3])
66
-
67
- it "array" do
68
- state_a.get_next("0").size.should eq 3
69
- state_a.get_next("1").size.should eq 0
70
- end
71
-
72
- it "in first step" do
73
- state_a.get_next("0")[0].should eq state_b
74
- end
75
-
76
- it "in second step" do
77
- state_a.get_next("0")[0].get_next("1")[0].should eq state_a
78
- end
79
- end
80
-
81
- context "while conversion from NFA to DFA" do
82
- trans = Array.new
83
- state_a = State.new("a")
84
- state_b = State.new("b")
85
- state_c = State.new("c")
86
- trans[0] = Transition.new(state_a, "0", state_b)
87
- trans[1] = Transition.new(state_b, "1", state_a)
88
- trans[2] = Transition.new(state_a, "0", state_a)
89
- trans[3] = Transition.new(state_c, "1", state_a)
90
- trans[4] = Transition.new(state_a, "0", state_c)
91
-
92
- subject { State.new("a,b") }
93
- it "should find correct transitions" do
94
- subject.associate_transitions(trans)
95
- subject.get_next("a").size.should eq 0
96
- subject.get_next("1").size.should eq 1
97
- subject.get_next("0").size.should eq 3
98
- end
99
- end
100
- end
101
-
1
+ require 'rspec'
2
+ require 'spec_helper'
3
+ require_relative '../lib/state.rb'
4
+
5
+ describe Nfa2Dfa::State do
6
+ before(:each) do
7
+ @end_state = State.new('end')
8
+ @end_state.to_starting_node
9
+ end
10
+ context 'should keep ' do
11
+ subject { State.new('state') }
12
+
13
+ it 'basic data' do
14
+ subject.id.should eq 'state'
15
+ subject.is_final.should eq false
16
+ end
17
+
18
+ it 'transitions as private data' do
19
+ expect { subject.transitions }.to raise_error NoMethodError
20
+ end
21
+
22
+ it 'added transitions' do
23
+ trans = Transition.new(subject, 'jump', @end_state)
24
+ transes = subject.add_transition(trans)
25
+ transes.size.should eq 1
26
+ transes[0].should eq trans
27
+ end
28
+
29
+ it 'cleared transition array' do
30
+ subject.clear_transitions.size.should eq 0
31
+ end
32
+ end
33
+
34
+ it 'should be able to be finalized' do
35
+ state_a = State.new('a')
36
+ state_a.is_final.should eq false
37
+ state_a.finalize
38
+ state_a.is_final.should eq true
39
+ state_a.finalize
40
+ state_a.is_final.should eq true
41
+ end
42
+
43
+ it 'should be able to be starting node' do
44
+ state_a = State.new('a')
45
+ state_a.is_starting.should eq false
46
+ state_a.to_starting_node
47
+ state_a.is_starting.should eq true
48
+ state_a.to_starting_node
49
+ state_a.is_starting.should eq true
50
+ end
51
+
52
+ context 'gets correct next state' do
53
+ trans = []
54
+ state_a = State.new('a')
55
+ state_b = State.new('b')
56
+ state_c = State.new('c')
57
+ trans[0] = Transition.new(state_a, '0', state_b)
58
+ trans[1] = Transition.new(state_b, '1', state_a)
59
+ trans[2] = Transition.new(state_a, '0', state_a)
60
+ trans[3] = Transition.new(state_c, '1', state_a)
61
+ trans[4] = Transition.new(state_a, '0', state_c)
62
+ state_a.add_transition(trans[0])
63
+ state_a.add_transition(trans[2])
64
+ state_a.add_transition(trans[4])
65
+ state_b.add_transition(trans[1])
66
+ state_c.add_transition(trans[3])
67
+
68
+ it 'array' do
69
+ state_a.get_next('0').size.should eq 3
70
+ state_a.get_next('1').size.should eq 0
71
+ end
72
+
73
+ it 'in first step' do
74
+ state_a.get_next('0')[0].should eq state_b
75
+ end
76
+
77
+ it 'in second step' do
78
+ state_a.get_next('0')[0].get_next('1')[0].should eq state_a
79
+ end
80
+ end
81
+
82
+ context 'while conversion from NFA to DFA' do
83
+ trans = Array.new
84
+ state_a = State.new('a')
85
+ state_b = State.new('b')
86
+ state_c = State.new('c')
87
+ trans[0] = Transition.new(state_a, '0', state_b)
88
+ trans[1] = Transition.new(state_b, '1', state_a)
89
+ trans[2] = Transition.new(state_a, '0', state_a)
90
+ trans[3] = Transition.new(state_c, '1', state_a)
91
+ trans[4] = Transition.new(state_a, '0', state_c)
92
+ subject { State.new('a,b') }
93
+ it 'should find correct transitions' do
94
+ subject.associate_transitions(trans)
95
+ subject.get_next('a').size.should eq 0
96
+ subject.get_next('1').size.should eq 1
97
+ subject.get_next('0').size.should eq 3
98
+ end
99
+ end
100
+ end
@@ -1,28 +1,27 @@
1
- require 'rspec'
2
- require 'spec_helper'
3
- require_relative '../lib/transition.rb'
4
-
5
- describe Nfa2Dfa::Transition do
6
- context "should keep " do
7
- state1 = State.new("1")
8
- state2 = State.new("2")
9
- state2.finalize
10
- subject { Transition.new(state1, "a", state2) }
11
-
12
- it "states" do
13
- subject.beginning_state.should eq state1
14
- subject.ending_state.should eq state2
15
- end
16
-
17
- it "transition alphabet" do
18
- subject.alphabet.should eq "a"
19
- end
20
-
21
- it "correct types" do
22
- subject.beginning_state.class.should eq State
23
- subject.ending_state.class.should eq State
24
- subject.alphabet.class.should eq String
25
- end
26
- end
27
- end
28
-
1
+ require 'rspec'
2
+ require 'spec_helper'
3
+ require_relative '../lib/transition.rb'
4
+
5
+ describe Nfa2Dfa::Transition do
6
+ context 'should keep ' do
7
+ state1 = State.new('1')
8
+ state2 = State.new('2')
9
+ state2.finalize
10
+ subject { Transition.new(state1, 'a', state2) }
11
+
12
+ it 'states' do
13
+ subject.beginning_state.should eq state1
14
+ subject.ending_state.should eq state2
15
+ end
16
+
17
+ it 'transition alphabet' do
18
+ subject.alphabet.should eq 'a'
19
+ end
20
+
21
+ it 'correct types' do
22
+ subject.beginning_state.class.should eq State
23
+ subject.ending_state.class.should eq State
24
+ subject.alphabet.class.should eq String
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nfa2dfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Zachov