stamina 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +22 -5
- data/LICENCE.md +2 -2
- data/bin/stamina +1 -7
- data/lib/stamina.rb +10 -19
- metadata +54 -333
- data/.gemtest +0 -0
- data/Gemfile +0 -2
- data/Gemfile.lock +0 -37
- data/Manifest.txt +0 -16
- data/README.md +0 -78
- data/Rakefile +0 -23
- data/example/adl/automaton.adl +0 -49
- data/example/adl/sample.adl +0 -53
- data/example/basic/characteristic_sample.adl +0 -32
- data/example/basic/target.adl +0 -9
- data/example/competition/31_test.adl +0 -1500
- data/example/competition/31_training.adl +0 -1759
- data/lib/stamina/abbadingo.rb +0 -2
- data/lib/stamina/abbadingo/random_dfa.rb +0 -48
- data/lib/stamina/abbadingo/random_sample.rb +0 -146
- data/lib/stamina/adl.rb +0 -298
- data/lib/stamina/automaton.rb +0 -1263
- data/lib/stamina/automaton/complete.rb +0 -36
- data/lib/stamina/automaton/equivalence.rb +0 -55
- data/lib/stamina/automaton/metrics.rb +0 -78
- data/lib/stamina/automaton/minimize.rb +0 -25
- data/lib/stamina/automaton/minimize/hopcroft.rb +0 -116
- data/lib/stamina/automaton/minimize/pitchies.rb +0 -64
- data/lib/stamina/automaton/strip.rb +0 -16
- data/lib/stamina/automaton/walking.rb +0 -363
- data/lib/stamina/classifier.rb +0 -52
- data/lib/stamina/command.rb +0 -45
- data/lib/stamina/command/abbadingo_dfa.rb +0 -81
- data/lib/stamina/command/abbadingo_samples.rb +0 -40
- data/lib/stamina/command/adl2dot.rb +0 -71
- data/lib/stamina/command/classify.rb +0 -48
- data/lib/stamina/command/help.rb +0 -27
- data/lib/stamina/command/infer.rb +0 -141
- data/lib/stamina/command/metrics.rb +0 -51
- data/lib/stamina/command/robustness.rb +0 -22
- data/lib/stamina/command/score.rb +0 -35
- data/lib/stamina/errors.rb +0 -23
- data/lib/stamina/ext/math.rb +0 -20
- data/lib/stamina/induction/blue_fringe.rb +0 -265
- data/lib/stamina/induction/commons.rb +0 -156
- data/lib/stamina/induction/rpni.rb +0 -186
- data/lib/stamina/induction/union_find.rb +0 -377
- data/lib/stamina/input_string.rb +0 -123
- data/lib/stamina/loader.rb +0 -1
- data/lib/stamina/markable.rb +0 -42
- data/lib/stamina/sample.rb +0 -267
- data/lib/stamina/scoring.rb +0 -213
- data/lib/stamina/utils.rb +0 -1
- data/lib/stamina/utils/decorate.rb +0 -81
- data/lib/stamina/version.rb +0 -14
- data/stamina.gemspec +0 -191
- data/stamina.noespec +0 -32
- data/tasks/debug_mail.rake +0 -78
- data/tasks/debug_mail.txt +0 -13
- data/tasks/gem.rake +0 -68
- data/tasks/spec_test.rake +0 -79
- data/tasks/unit_test.rake +0 -77
- data/tasks/yard.rake +0 -51
- data/test/stamina/abbadingo/random_dfa_test.rb +0 -16
- data/test/stamina/abbadingo/random_sample_test.rb +0 -78
- data/test/stamina/adl_test.rb +0 -516
- data/test/stamina/automaton/classifier_test.rb +0 -259
- data/test/stamina/automaton/complete_test.rb +0 -58
- data/test/stamina/automaton/equivalence_test.rb +0 -120
- data/test/stamina/automaton/metrics_test.rb +0 -36
- data/test/stamina/automaton/minimize/hopcroft_test.rb +0 -15
- data/test/stamina/automaton/minimize/minimize_test.rb +0 -55
- data/test/stamina/automaton/minimize/pitchies_test.rb +0 -15
- data/test/stamina/automaton/minimize/rice_edu_10.adl +0 -16
- data/test/stamina/automaton/minimize/rice_edu_10.min.adl +0 -13
- data/test/stamina/automaton/minimize/rice_edu_13.adl +0 -13
- data/test/stamina/automaton/minimize/rice_edu_13.min.adl +0 -7
- data/test/stamina/automaton/minimize/should_strip_1.adl +0 -8
- data/test/stamina/automaton/minimize/should_strip_1.min.adl +0 -6
- data/test/stamina/automaton/minimize/unknown_1.adl +0 -16
- data/test/stamina/automaton/minimize/unknown_1.min.adl +0 -12
- data/test/stamina/automaton/strip_test.rb +0 -36
- data/test/stamina/automaton/to_dot_test.rb +0 -64
- data/test/stamina/automaton/walking/dfa_delta_test.rb +0 -39
- data/test/stamina/automaton/walking_test.rb +0 -206
- data/test/stamina/automaton_additional_test.rb +0 -190
- data/test/stamina/automaton_test.rb +0 -1104
- data/test/stamina/exit.rb +0 -3
- data/test/stamina/induction/blue_fringe_test.rb +0 -83
- data/test/stamina/induction/induction_test.rb +0 -70
- data/test/stamina/induction/redblue_mergesamestatebug_expected.adl +0 -19
- data/test/stamina/induction/redblue_mergesamestatebug_pta.dot +0 -64
- data/test/stamina/induction/redblue_mergesamestatebug_sample.adl +0 -9
- data/test/stamina/induction/redblue_universal_expected.adl +0 -4
- data/test/stamina/induction/redblue_universal_sample.adl +0 -5
- data/test/stamina/induction/rpni_inria_expected.adl +0 -7
- data/test/stamina/induction/rpni_inria_sample.adl +0 -9
- data/test/stamina/induction/rpni_test.rb +0 -129
- data/test/stamina/induction/rpni_test_pta.dot +0 -22
- data/test/stamina/induction/rpni_universal_expected.adl +0 -4
- data/test/stamina/induction/rpni_universal_sample.adl +0 -4
- data/test/stamina/induction/union_find_test.rb +0 -124
- data/test/stamina/input_string_test.rb +0 -323
- data/test/stamina/markable_test.rb +0 -70
- data/test/stamina/randdfa.adl +0 -66
- data/test/stamina/sample.adl +0 -4
- data/test/stamina/sample_classify_test.rb +0 -149
- data/test/stamina/sample_test.rb +0 -290
- data/test/stamina/scoring_test.rb +0 -63
- data/test/stamina/small_dfa.dot +0 -16
- data/test/stamina/small_dfa.gif +0 -0
- data/test/stamina/small_nfa.dot +0 -18
- data/test/stamina/small_nfa.gif +0 -0
- data/test/stamina/stamina_test.rb +0 -80
- data/test/stamina/utils/decorate_test.rb +0 -65
- data/test/test_all.rb +0 -7
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.expand_path("../minimize_test", __FILE__)
|
2
|
-
module Stamina
|
3
|
-
class Automaton
|
4
|
-
module Minimize
|
5
|
-
class HopcroftTest < MinimizeTest
|
6
|
-
|
7
|
-
def algo
|
8
|
-
Hopcroft
|
9
|
-
end
|
10
|
-
|
11
|
-
end # class HopcroftTest
|
12
|
-
end # module Minimize
|
13
|
-
end # class Automaton
|
14
|
-
end # module Stamina
|
15
|
-
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stamina/stamina_test'
|
3
|
-
module Stamina
|
4
|
-
class Automaton
|
5
|
-
module Minimize
|
6
|
-
class MinimizeTest < StaminaTest
|
7
|
-
|
8
|
-
# To be overriden
|
9
|
-
def algo
|
10
|
-
nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_on_unknown_1
|
14
|
-
return unless algo
|
15
|
-
dfa = load_adl_automaton("unknown_1.adl", __FILE__)
|
16
|
-
min = load_adl_automaton("unknown_1.min.adl", __FILE__)
|
17
|
-
assert_equivalent(algo.execute(dfa), min)
|
18
|
-
end
|
19
|
-
|
20
|
-
# From slide 10 in http://www.clear.rice.edu/comp412/Lectures/L07DFAMin-1up.pdf
|
21
|
-
def test_on_rice_edu_10
|
22
|
-
return unless algo
|
23
|
-
dfa = load_adl_automaton("rice_edu_10.adl", __FILE__)
|
24
|
-
min = load_adl_automaton("rice_edu_10.min.adl", __FILE__)
|
25
|
-
assert_equivalent(algo.execute(dfa), min)
|
26
|
-
end
|
27
|
-
|
28
|
-
# From slide 13 in http://www.clear.rice.edu/comp412/Lectures/L07DFAMin-1up.pdf
|
29
|
-
def test_on_rice_edu_13
|
30
|
-
return unless algo
|
31
|
-
dfa = load_adl_automaton("rice_edu_13.adl", __FILE__)
|
32
|
-
min = load_adl_automaton("rice_edu_13.min.adl", __FILE__)
|
33
|
-
assert_equivalent(algo.execute(dfa), min)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_it_strips_when_needed
|
37
|
-
return unless algo
|
38
|
-
dfa = load_adl_automaton("should_strip_1.adl", __FILE__)
|
39
|
-
min = load_adl_automaton("should_strip_1.min.adl", __FILE__)
|
40
|
-
assert_equivalent(algo.execute(dfa), min)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_it_has_no_effect_on_already_minimal
|
44
|
-
return unless algo
|
45
|
-
dfa = load_adl_automaton("rice_edu_13.min.adl", __FILE__)
|
46
|
-
min = algo.execute(dfa)
|
47
|
-
assert_equal dfa.complete.state_count, min.complete.state_count
|
48
|
-
assert_equivalent(min, dfa)
|
49
|
-
end
|
50
|
-
|
51
|
-
end # class MinimizeTest
|
52
|
-
end # module Minimize
|
53
|
-
end # class Automaton
|
54
|
-
end # module Stamina
|
55
|
-
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.expand_path("../minimize_test", __FILE__)
|
2
|
-
module Stamina
|
3
|
-
class Automaton
|
4
|
-
module Minimize
|
5
|
-
class PitchiesTest < MinimizeTest
|
6
|
-
|
7
|
-
def algo
|
8
|
-
Pitchies
|
9
|
-
end
|
10
|
-
|
11
|
-
end # class PitchiesTest
|
12
|
-
end # module Minimize
|
13
|
-
end # class Automaton
|
14
|
-
end # module Stamina
|
15
|
-
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stamina/adl'
|
3
|
-
require 'stamina/stamina_test'
|
4
|
-
module Stamina
|
5
|
-
class Automaton
|
6
|
-
class StripTest < StaminaTest
|
7
|
-
|
8
|
-
def test_on_all_reachable
|
9
|
-
assert_equivalent @small_dfa, @small_dfa.strip
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_with_unreachable_states
|
13
|
-
dfa = Stamina::ADL.parse_automaton <<-EOF
|
14
|
-
3 3
|
15
|
-
0 true false
|
16
|
-
1 false true
|
17
|
-
2 false false
|
18
|
-
0 1 a
|
19
|
-
1 0 b
|
20
|
-
2 1 a
|
21
|
-
EOF
|
22
|
-
expected = Stamina::ADL.parse_automaton <<-EOF
|
23
|
-
2 2
|
24
|
-
0 true false
|
25
|
-
1 false true
|
26
|
-
0 1 a
|
27
|
-
1 0 b
|
28
|
-
EOF
|
29
|
-
assert_not_equivalent(expected, dfa)
|
30
|
-
assert_equivalent(expected, dfa.strip)
|
31
|
-
end
|
32
|
-
|
33
|
-
end # class StripTest
|
34
|
-
end # class Automaton
|
35
|
-
end # module Stamina
|
36
|
-
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stamina'
|
3
|
-
module Stamina
|
4
|
-
module Utils
|
5
|
-
class DotTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@automaton = Automaton.new do |a|
|
9
|
-
add_state(:initial => true, :accepting => false)
|
10
|
-
add_state(:initial => false, :accepting => true)
|
11
|
-
add_state(:initial => false, :accepting => true, :error => true)
|
12
|
-
connect(0, 1, 'a')
|
13
|
-
connect(1, 0, 'b')
|
14
|
-
connect(1, 2, 'a')
|
15
|
-
connect(2, 2, nil)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_attributes2dot
|
20
|
-
attrs = {:label => 'hello'}
|
21
|
-
assert_equal 'label="hello"', @automaton.send(:attributes2dot, attrs)
|
22
|
-
attrs = {:label => 'hello', :color => 'red'}
|
23
|
-
assert_equal 'color="red" label="hello"', @automaton.send(:attributes2dot, attrs)
|
24
|
-
attrs = {:label => 'O"Neil'}
|
25
|
-
assert_equal 'label="O\"Neil"', @automaton.send(:attributes2dot, attrs)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_automaton_to_dot_with_default_rewriter
|
29
|
-
expected = <<-EOF
|
30
|
-
#digraph G {
|
31
|
-
# graph [rankdir="LR"];
|
32
|
-
# 0 [color="black" fillcolor="green" shape="circle" style="filled"];
|
33
|
-
# 1 [color="black" fillcolor="white" shape="doublecircle" style="filled"];
|
34
|
-
# 2 [color="black" fillcolor="red" shape="doublecircle" style="filled"];
|
35
|
-
# 0 -> 1 [label="a"];
|
36
|
-
# 1 -> 0 [label="b"];
|
37
|
-
# 1 -> 2 [label="a"];
|
38
|
-
# 2 -> 2 [label=""];
|
39
|
-
#}
|
40
|
-
EOF
|
41
|
-
expected = expected.gsub(/^\s+#/,'')
|
42
|
-
assert_equal expected, @automaton.to_dot
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_automaton_with_specific_rewriter
|
46
|
-
expected = <<-EOF
|
47
|
-
#digraph G {
|
48
|
-
# graph [];
|
49
|
-
# 0 [accepting="false" initial="true"];
|
50
|
-
# 1 [accepting="true" initial="false"];
|
51
|
-
# 2 [accepting="true" error="true" initial="false"];
|
52
|
-
# 0 -> 1 [symbol="a"];
|
53
|
-
# 1 -> 0 [symbol="b"];
|
54
|
-
# 1 -> 2 [symbol="a"];
|
55
|
-
# 2 -> 2 [symbol=""];
|
56
|
-
#}
|
57
|
-
EOF
|
58
|
-
expected = expected.gsub(/^\s+#/,'')
|
59
|
-
assert_equal expected, @automaton.to_dot {|elm,kind| elm.data}
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stamina/stamina_test'
|
3
|
-
module Stamina
|
4
|
-
class Automaton
|
5
|
-
# Tests Walking module on Automaton class
|
6
|
-
class WalkingTestDfaDelta < StaminaTest
|
7
|
-
|
8
|
-
DFA = Stamina::ADL::parse_automaton <<-EOF
|
9
|
-
2 3
|
10
|
-
0 true false
|
11
|
-
1 false true
|
12
|
-
0 1 a
|
13
|
-
1 0 b
|
14
|
-
1 1 a
|
15
|
-
EOF
|
16
|
-
S0 = DFA.ith_state(0)
|
17
|
-
S1 = DFA.ith_state(1)
|
18
|
-
|
19
|
-
def test_with_single_state_as_from
|
20
|
-
assert_equal S1, DFA.dfa_delta(S0, 'a')
|
21
|
-
assert_equal S1, DFA.dfa_delta(0, 'a')
|
22
|
-
assert_equal S0, DFA.dfa_delta(1, 'b')
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_with_single_array_as_from
|
26
|
-
assert_equal [S1], DFA.dfa_delta([S0], 'a')
|
27
|
-
assert_equal [S1], DFA.dfa_delta([0], 'a')
|
28
|
-
assert_equal [S0], DFA.dfa_delta([1], 'b')
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_with_multiple_array_as_from
|
32
|
-
assert_equal [S1], DFA.dfa_delta([S0, S1], 'a')
|
33
|
-
assert_equal [S1], DFA.dfa_delta([0, 1], 'a')
|
34
|
-
assert_equal [S0], DFA.dfa_delta([0, 1], 'b')
|
35
|
-
end
|
36
|
-
|
37
|
-
end # class WalkingTestDfaDelta
|
38
|
-
end # class Automaton
|
39
|
-
end # module Stamina
|
@@ -1,206 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stamina/stamina_test'
|
3
|
-
module Stamina
|
4
|
-
class Automaton
|
5
|
-
# Tests Walking module on Automaton class
|
6
|
-
class WalkingTest < StaminaTest
|
7
|
-
|
8
|
-
# Tests Walking#step on examples
|
9
|
-
def test_step_on_examples
|
10
|
-
assert_equal([], @small_dfa.step(0, 'b'))
|
11
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.step(0, 'a'))
|
12
|
-
assert_equal(@small_dfa.ith_states(1,3), @small_dfa.step([0,1], 'a').sort)
|
13
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.step([0,2], 'a').sort)
|
14
|
-
|
15
|
-
assert_equal([], @small_nfa.step(0, 'b'))
|
16
|
-
assert_equal(@small_nfa.ith_states(1), @small_nfa.step(0, 'a'))
|
17
|
-
assert_equal([], @small_nfa.step(2, 'b'))
|
18
|
-
assert_equal(@small_nfa.ith_states(2,3), @small_nfa.step(1, 'b').sort)
|
19
|
-
assert_equal(@small_nfa.ith_states(0,1), @small_nfa.step([0,3], 'a').sort)
|
20
|
-
end
|
21
|
-
|
22
|
-
# Tests Walking#dfa_step on examples
|
23
|
-
def test_step_on_examples
|
24
|
-
assert_equal(nil, @small_dfa.dfa_step(0, 'b'))
|
25
|
-
assert_equal(@small_dfa.ith_state(1), @small_dfa.dfa_step(0, 'a'))
|
26
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.dfa_step([0], 'a'))
|
27
|
-
assert_equal(@small_dfa.ith_states(1,3), @small_dfa.dfa_step([0,1], 'a').sort)
|
28
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.dfa_step([0,2], 'a').sort)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Tests Walking#delta on examples
|
32
|
-
def test_delta_on_examples
|
33
|
-
assert_equal([], @small_dfa.delta(0, 'b'))
|
34
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.delta(0, 'a'))
|
35
|
-
assert_equal(@small_dfa.ith_states(1,3), @small_dfa.delta([0,1], 'a').sort)
|
36
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.delta([0,2], 'a').sort)
|
37
|
-
|
38
|
-
assert_equal([], @small_nfa.delta(0, 'b'))
|
39
|
-
assert_equal(@small_nfa.ith_states(1), @small_nfa.delta(0, 'a'))
|
40
|
-
assert_equal(@small_nfa.ith_states(1,2,3), @small_nfa.delta(2, 'b').sort)
|
41
|
-
assert_equal(@small_nfa.ith_states(1,2,3), @small_nfa.delta(1, 'b').sort)
|
42
|
-
assert_equal(@small_nfa.ith_states(0,1), @small_nfa.delta([0,3], 'a').sort)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Tests Walking#dfa_delta on examples
|
46
|
-
def test_delta_on_examples
|
47
|
-
assert_equal(nil, @small_dfa.dfa_delta(0, 'b'))
|
48
|
-
assert_equal(@small_dfa.ith_state(1), @small_dfa.dfa_delta(0, 'a'))
|
49
|
-
assert_equal(@small_dfa.ith_states(1,3), @small_dfa.dfa_delta([0,1], 'a').sort)
|
50
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.dfa_delta([0,2], 'a').sort)
|
51
|
-
end
|
52
|
-
|
53
|
-
# Tests Walking#split on examples
|
54
|
-
def test_split_on_examples
|
55
|
-
assert_equal([[], @small_dfa.ith_states(3), []], @small_dfa.split('?'))
|
56
|
-
assert_equal([[], @small_dfa.ith_states(3), ['a']], @small_dfa.split('? a'))
|
57
|
-
assert_equal([['b'], @small_dfa.ith_states(2), []], @small_dfa.split('? b'))
|
58
|
-
assert_equal([['b'], @small_dfa.ith_states(2), ['a']], @small_dfa.split('? b a'))
|
59
|
-
assert_equal([['b','c'], @small_dfa.ith_states(0), []], @small_dfa.split('? b c'))
|
60
|
-
|
61
|
-
assert_equal([[], @small_nfa.ith_states(0,3), []], @small_nfa.split('?'))
|
62
|
-
assert_equal([[], @small_nfa.ith_states(0,3), ['b']], @small_nfa.split('? b'))
|
63
|
-
assert_equal([['a'], @small_nfa.ith_states(0,1), []], @small_nfa.split('? a',nil,true))
|
64
|
-
assert_equal([['a'], @small_nfa.ith_states(0,1), ['c']], @small_nfa.split('? a c',nil,true))
|
65
|
-
assert_equal([['a','b'], @small_nfa.ith_states(1,2,3), []], @small_nfa.split('? a b',nil,true))
|
66
|
-
end
|
67
|
-
|
68
|
-
# Tests Walking#dfa_split on examples
|
69
|
-
def test_split_on_examples
|
70
|
-
assert_equal([[], @small_dfa.ith_state(3), []], @small_dfa.dfa_split('?'))
|
71
|
-
assert_equal([[], @small_dfa.ith_state(3), ['a']], @small_dfa.dfa_split('? a'))
|
72
|
-
assert_equal([['b'], @small_dfa.ith_state(2), []], @small_dfa.dfa_split('? b'))
|
73
|
-
assert_equal([['b'], @small_dfa.ith_state(2), ['a']], @small_dfa.dfa_split('? b a'))
|
74
|
-
assert_equal([['b','c'], @small_dfa.ith_state(0), []], @small_dfa.dfa_split('? b c'))
|
75
|
-
assert_equal([['b','c'], @small_dfa.ith_states(0), []], @small_dfa.dfa_split('? b c',[3]))
|
76
|
-
end
|
77
|
-
|
78
|
-
# Tests Walking#reached on examples
|
79
|
-
def test_reached_on_examples
|
80
|
-
assert_equal([], @small_dfa.reached('? a a'))
|
81
|
-
assert_equal(@small_dfa.ith_states(2), @small_dfa.reached('? b'))
|
82
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.reached('? b c a c'))
|
83
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.reached('? a c', @small_dfa.ith_state(0)))
|
84
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.reached('? a c',0))
|
85
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.reached('? a',[0]))
|
86
|
-
assert_equal(@small_dfa.ith_states(1,3), @small_dfa.reached('? a',[0,1]))
|
87
|
-
assert_equal(@small_dfa.ith_states(2), @small_dfa.reached('? b',[3,1]))
|
88
|
-
assert_equal(@small_dfa.ith_states(2), @small_dfa.reached('? b',[0,3,1]))
|
89
|
-
|
90
|
-
assert_equal(@small_nfa.ith_states(0,3), @small_nfa.reached('?').sort)
|
91
|
-
assert_equal(@small_nfa.ith_states(0,1), @small_nfa.reached('? a').sort)
|
92
|
-
assert_equal(@small_nfa.ith_states(1,2,3), @small_nfa.reached('? a b').sort)
|
93
|
-
end
|
94
|
-
|
95
|
-
# Tests Walking#dfa_reached on examples
|
96
|
-
def test_dfa_reached_on_examples
|
97
|
-
assert_equal(nil, @small_dfa.dfa_reached('? a a'))
|
98
|
-
assert_equal(@small_dfa.ith_state(2), @small_dfa.dfa_reached('? b'))
|
99
|
-
assert_equal(@small_dfa.ith_state(1), @small_dfa.dfa_reached('? b c a c'))
|
100
|
-
assert_equal(@small_dfa.ith_state(1), @small_dfa.dfa_reached('? a c', @small_dfa.ith_state(0)))
|
101
|
-
assert_equal(@small_dfa.ith_state(1), @small_dfa.dfa_reached('? a c',0))
|
102
|
-
assert_equal(@small_dfa.ith_states(1), @small_dfa.dfa_reached('? a',[0]))
|
103
|
-
assert_equal(@small_dfa.ith_states(1,3), @small_dfa.dfa_reached('? a',[0,1]))
|
104
|
-
assert_equal(@small_dfa.ith_states(2), @small_dfa.dfa_reached('? b',[3,1]))
|
105
|
-
assert_equal(@small_dfa.ith_states(2), @small_dfa.dfa_reached('? b',[0,3,1]))
|
106
|
-
end
|
107
|
-
|
108
|
-
# Tests Walking#dfa_reached
|
109
|
-
def test_dfa_reached_on_simple_deterministic_automaton
|
110
|
-
s0, s1 = nil
|
111
|
-
fa = Automaton.new do |fa|
|
112
|
-
s0 = fa.add_state(:initial => true)
|
113
|
-
s1 = fa.add_state
|
114
|
-
fa.connect(s0, s1, 'a')
|
115
|
-
fa.connect(s1, s0, 'b')
|
116
|
-
end
|
117
|
-
assert_equal(s0, fa.dfa_reached('? '))
|
118
|
-
assert_equal(s1, fa.dfa_reached('? a'))
|
119
|
-
assert_equal(s0, fa.dfa_reached('? a b'))
|
120
|
-
assert_equal(s1, fa.dfa_reached('? a b a'))
|
121
|
-
assert_equal(s0, fa.dfa_reached('? a b a b'))
|
122
|
-
assert_nil(fa.dfa_reached('? a a'))
|
123
|
-
assert_nil(fa.dfa_reached('? b'))
|
124
|
-
assert_nil(fa.dfa_reached('? a b b'))
|
125
|
-
end
|
126
|
-
|
127
|
-
# Tests Walking#reached on a deterministic automaton
|
128
|
-
def test_reached_on_simple_deterministic_automaton
|
129
|
-
s0, s1 = nil
|
130
|
-
fa = Automaton.new do |fa|
|
131
|
-
s0 = fa.add_state(:initial => true)
|
132
|
-
s1 = fa.add_state
|
133
|
-
fa.connect(s0, s1, 'a')
|
134
|
-
fa.connect(s1, s0, 'b')
|
135
|
-
end
|
136
|
-
assert_equal([s0], fa.reached('?'))
|
137
|
-
assert_equal([s1], fa.reached('? a'))
|
138
|
-
assert_equal([s0], fa.reached('? a b'))
|
139
|
-
assert_equal([s1], fa.reached('? a b a'))
|
140
|
-
assert_equal([s0], fa.reached('? a b a b'))
|
141
|
-
assert_equal([], fa.reached('? a a'))
|
142
|
-
assert_equal([], fa.reached('? b'))
|
143
|
-
assert_equal([], fa.reached('? a b b'))
|
144
|
-
end
|
145
|
-
|
146
|
-
# Tests Walking#reached on a non-deterministic automaton.
|
147
|
-
def test_reached_on_non_deterministic_automaton
|
148
|
-
s0, s1, s2, s3, s4 = nil
|
149
|
-
fa = Automaton.new do |fa|
|
150
|
-
s0 = fa.add_state(:initial => true) #
|
151
|
-
s1, s2, s3, s4 = fa.add_n_states(4) # s1 -b-> s3
|
152
|
-
fa.connect(s0, s1, 'a') # a
|
153
|
-
fa.connect(s0, s2, 'a') # s0
|
154
|
-
fa.connect(s1, s3, 'b') # a
|
155
|
-
fa.connect(s2, s4, 'c') # s2 -c-> s4
|
156
|
-
end #
|
157
|
-
assert_equal([], s2.delta('b'))
|
158
|
-
assert_equal([s0], fa.reached('?'))
|
159
|
-
assert_equal([], fa.reached('? c'))
|
160
|
-
assert_equal([s1,s2], fa.reached('? a').sort)
|
161
|
-
assert_equal([s3], fa.reached('? a b'))
|
162
|
-
assert_equal([s4], fa.reached('? a c'))
|
163
|
-
assert_equal([s1,s2], fa.reached('? a').sort)
|
164
|
-
|
165
|
-
# add a looping b on s2
|
166
|
-
fa.connect(s2, s2, 'b')
|
167
|
-
assert_equal([s2,s3], fa.reached('? a b').sort)
|
168
|
-
|
169
|
-
# add an epsilon from s2 to s1
|
170
|
-
fa.connect(s2, s1, nil)
|
171
|
-
assert_equal([s1,s2], fa.reached('? a').sort)
|
172
|
-
assert_equal([s1,s2,s3], fa.reached('? a b').sort)
|
173
|
-
end
|
174
|
-
|
175
|
-
# Tests Walking#accepts? and Walking#rejects?
|
176
|
-
def test_accepts_and_rejects
|
177
|
-
fa = Automaton.new do
|
178
|
-
add_state(:initial => true)
|
179
|
-
add_state(:accepting => true)
|
180
|
-
add_state(:error => true)
|
181
|
-
add_state(:accepting => true, :error => true)
|
182
|
-
connect(0,1,'a')
|
183
|
-
connect(1,0,'b')
|
184
|
-
connect(0,2,'b')
|
185
|
-
connect(1,3,'a')
|
186
|
-
end
|
187
|
-
assert_equal(false, fa.accepts?("?"))
|
188
|
-
assert_equal(true, fa.accepts?("? a"))
|
189
|
-
assert_equal(false, fa.accepts?("? a b"))
|
190
|
-
assert_equal(true, fa.accepts?("? a b a"))
|
191
|
-
assert_equal(false, fa.accepts?("? z"), "not accepts? on no state")
|
192
|
-
assert_equal(false, fa.accepts?("? b"), "not accepts? on non accepting error state")
|
193
|
-
assert_equal(false, fa.accepts?("? a a"), "not accepts? on accepting error state")
|
194
|
-
|
195
|
-
assert_equal(true, fa.rejects?("?"))
|
196
|
-
assert_equal(false, fa.rejects?("? a"))
|
197
|
-
assert_equal(true, fa.rejects?("? a b"))
|
198
|
-
assert_equal(false, fa.rejects?("? a b a"))
|
199
|
-
assert_equal(true, fa.rejects?("? z"), "rejects? on no state")
|
200
|
-
assert_equal(true, fa.rejects?("? b"), "rejects? on non accepting error state")
|
201
|
-
assert_equal(true, fa.rejects?("? a a"), "rejects? on accepting error state")
|
202
|
-
end
|
203
|
-
|
204
|
-
end # class WalkingTest
|
205
|
-
end # class Automaton
|
206
|
-
end # module Stamina
|