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,70 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stamina/markable'
|
3
|
-
module Stamina
|
4
|
-
# Tests Loaded class
|
5
|
-
class MarkableTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
class MyMarkableObject
|
8
|
-
include Markable
|
9
|
-
def initialize
|
10
|
-
@data = {}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class MarkableObjectWithStateChanges < MyMarkableObject
|
15
|
-
def initialize
|
16
|
-
super
|
17
|
-
@changes = []
|
18
|
-
end
|
19
|
-
|
20
|
-
def state_changed(what, description)
|
21
|
-
@changes << what << description
|
22
|
-
end
|
23
|
-
|
24
|
-
def changes
|
25
|
-
@changes
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Tests the effect of setting a value
|
30
|
-
def test_value_assignments
|
31
|
-
@loaded = MyMarkableObject.new
|
32
|
-
|
33
|
-
assert_nil(@loaded[:myownkey])
|
34
|
-
assert_nil(@loaded["rr"])
|
35
|
-
|
36
|
-
@loaded[:myownkey] = "myownkey"
|
37
|
-
@loaded[12] = :twelve
|
38
|
-
assert_equal("myownkey", @loaded[:myownkey])
|
39
|
-
assert_equal(:twelve, @loaded[12])
|
40
|
-
assert_nil(@loaded["rr"])
|
41
|
-
|
42
|
-
@loaded[:myownkey] = 36
|
43
|
-
assert_equal(36, @loaded[:myownkey])
|
44
|
-
assert_equal(:twelve, @loaded[12])
|
45
|
-
assert_nil(@loaded["rr"])
|
46
|
-
end
|
47
|
-
|
48
|
-
# Tests the effect of setting a value
|
49
|
-
def test_value_assignments_statechange
|
50
|
-
@loaded = MarkableObjectWithStateChanges.new
|
51
|
-
|
52
|
-
assert_nil(@loaded[:myownkey])
|
53
|
-
assert_nil(@loaded["rr"])
|
54
|
-
assert_equal([],@loaded.changes)
|
55
|
-
|
56
|
-
@loaded[:myownkey] = "myownkey"
|
57
|
-
@loaded[12] = :twelve
|
58
|
-
assert_equal("myownkey", @loaded[:myownkey])
|
59
|
-
assert_equal(:twelve, @loaded[12])
|
60
|
-
assert_equal([:loaded_pair,[:myownkey,nil,"myownkey"],:loaded_pair,[12,nil,:twelve]],@loaded.changes)
|
61
|
-
assert_nil(@loaded["rr"])
|
62
|
-
|
63
|
-
@loaded[:myownkey] = 36
|
64
|
-
assert_equal(36, @loaded[:myownkey])
|
65
|
-
assert_equal(:twelve, @loaded[12])
|
66
|
-
assert_nil(@loaded["rr"])
|
67
|
-
assert_equal([:loaded_pair,[:myownkey,nil,"myownkey"],:loaded_pair,[12,nil,:twelve],:loaded_pair,[:myownkey,"myownkey",36]],@loaded.changes)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
data/test/stamina/randdfa.adl
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
26 39
|
2
|
-
0 false false
|
3
|
-
1 false true
|
4
|
-
2 false true
|
5
|
-
3 false true
|
6
|
-
4 false false
|
7
|
-
5 false true
|
8
|
-
6 true false
|
9
|
-
7 false false
|
10
|
-
8 false true
|
11
|
-
9 false true
|
12
|
-
10 false false
|
13
|
-
11 false false
|
14
|
-
12 false false
|
15
|
-
13 false true
|
16
|
-
14 false true
|
17
|
-
15 false false
|
18
|
-
16 false false
|
19
|
-
17 false false
|
20
|
-
18 false true
|
21
|
-
19 false true
|
22
|
-
20 false false
|
23
|
-
21 false true
|
24
|
-
22 false true
|
25
|
-
23 false false
|
26
|
-
24 false true
|
27
|
-
25 false true
|
28
|
-
0 1 1
|
29
|
-
0 2 0
|
30
|
-
3 4 1
|
31
|
-
3 5 0
|
32
|
-
6 7 0
|
33
|
-
6 8 1
|
34
|
-
2 9 1
|
35
|
-
2 10 0
|
36
|
-
11 12 1
|
37
|
-
11 13 0
|
38
|
-
12 4 0
|
39
|
-
12 12 1
|
40
|
-
14 15 1
|
41
|
-
14 16 0
|
42
|
-
17 0 0
|
43
|
-
18 19 0
|
44
|
-
18 0 1
|
45
|
-
20 1 1
|
46
|
-
20 18 0
|
47
|
-
21 18 0
|
48
|
-
15 21 0
|
49
|
-
15 22 1
|
50
|
-
9 5 0
|
51
|
-
22 17 1
|
52
|
-
8 1 1
|
53
|
-
8 20 0
|
54
|
-
13 23 0
|
55
|
-
13 5 1
|
56
|
-
4 19 1
|
57
|
-
24 11 0
|
58
|
-
23 24 0
|
59
|
-
23 3 1
|
60
|
-
10 25 1
|
61
|
-
10 24 0
|
62
|
-
19 14 1
|
63
|
-
25 7 1
|
64
|
-
7 1 1
|
65
|
-
7 24 0
|
66
|
-
1 10 0
|
data/test/stamina/sample.adl
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stamina/adl'
|
3
|
-
require 'stamina/stamina_test'
|
4
|
-
module Stamina
|
5
|
-
class Sample
|
6
|
-
# Tests Classify module, as installed on Sample and InputString classes.
|
7
|
-
class ClassifyTest < StaminaTest
|
8
|
-
|
9
|
-
# Tests Classify#correctly_classified_by? is correct on valid sample against
|
10
|
-
# small_dfa example
|
11
|
-
def test_valid_sample_correctly_classified_by_small_dfa
|
12
|
-
assert_equal(true, Sample.new.correctly_classified_by?(@small_dfa))
|
13
|
-
sample = ADL::parse_sample <<-SAMPLE
|
14
|
-
-
|
15
|
-
+ b
|
16
|
-
+ b c
|
17
|
-
- b c a
|
18
|
-
- b c a c
|
19
|
-
- b c a c a
|
20
|
-
- b c a a
|
21
|
-
+ b c a b
|
22
|
-
+ b c a b c a c b
|
23
|
-
- z
|
24
|
-
- b z
|
25
|
-
SAMPLE
|
26
|
-
assert_equal(true, sample.correctly_classified_by?(@small_dfa))
|
27
|
-
end
|
28
|
-
|
29
|
-
# Tests Classify#correctly_classified_by? is correct on invalid sample against
|
30
|
-
# small_dfa example
|
31
|
-
def test_invalid_sample_correctly_classified_by_small_dfa
|
32
|
-
sample = ADL::parse_sample <<-SAMPLE
|
33
|
-
-
|
34
|
-
+ b
|
35
|
-
+ b c
|
36
|
-
- b c a
|
37
|
-
# this one is reversed
|
38
|
-
+ b c a c
|
39
|
-
- b c a c a
|
40
|
-
- b c a a
|
41
|
-
+ b c a b
|
42
|
-
+ b c a b c a c b
|
43
|
-
- z
|
44
|
-
- b z
|
45
|
-
SAMPLE
|
46
|
-
assert_equal(false, sample.correctly_classified_by?(@small_dfa))
|
47
|
-
|
48
|
-
sample = ADL::parse_sample <<-SAMPLE
|
49
|
-
-
|
50
|
-
+ b
|
51
|
-
+ b c
|
52
|
-
- b c a
|
53
|
-
- b c a c
|
54
|
-
- b c a c a
|
55
|
-
- b c a a
|
56
|
-
+ b c a b
|
57
|
-
+ b c a b c a c b
|
58
|
-
# this one is changed
|
59
|
-
+ z
|
60
|
-
- b z
|
61
|
-
SAMPLE
|
62
|
-
assert_equal(false, sample.correctly_classified_by?(@small_dfa))
|
63
|
-
|
64
|
-
sample = ADL::parse_sample <<-SAMPLE
|
65
|
-
-
|
66
|
-
+ b
|
67
|
-
+ b c
|
68
|
-
- b c a
|
69
|
-
- b c a c
|
70
|
-
- b c a c a
|
71
|
-
- b c a a
|
72
|
-
+ b c a b
|
73
|
-
# this one is changed
|
74
|
-
- b c a b c a c b
|
75
|
-
- z
|
76
|
-
- b z
|
77
|
-
SAMPLE
|
78
|
-
assert_equal(false, sample.correctly_classified_by?(@small_dfa))
|
79
|
-
end
|
80
|
-
|
81
|
-
# Tests Classify#correctly_classified_by? is correct on valid sample against
|
82
|
-
# small_nfa example
|
83
|
-
def test_valid_sample_correctly_classified_by_small_nfa
|
84
|
-
assert_equal(true, Sample.new.correctly_classified_by?(@small_nfa))
|
85
|
-
sample = ADL::parse_sample <<-SAMPLE
|
86
|
-
+
|
87
|
-
+ a
|
88
|
-
- a a
|
89
|
-
+ a a b
|
90
|
-
+ a b
|
91
|
-
+ a b c a
|
92
|
-
- a b c
|
93
|
-
+ a b b b b b b
|
94
|
-
- a z
|
95
|
-
- z
|
96
|
-
SAMPLE
|
97
|
-
assert_equal(true, sample.correctly_classified_by?(@small_nfa))
|
98
|
-
end
|
99
|
-
|
100
|
-
# Tests Classify#correctly_classified_by? is correct on invalid sample against
|
101
|
-
# small_nfa example
|
102
|
-
def test_invalid_sample_correctly_classified_by_small_nfa
|
103
|
-
sample = ADL::parse_sample <<-SAMPLE
|
104
|
-
# this one is changed
|
105
|
-
-
|
106
|
-
+ a
|
107
|
-
- a a
|
108
|
-
+ a a b
|
109
|
-
+ a b
|
110
|
-
+ a b c a
|
111
|
-
- a b c
|
112
|
-
+ a b b b b b b
|
113
|
-
- a z
|
114
|
-
- z
|
115
|
-
SAMPLE
|
116
|
-
assert_equal(false, sample.correctly_classified_by?(@small_nfa))
|
117
|
-
sample = ADL::parse_sample <<-SAMPLE
|
118
|
-
+
|
119
|
-
+ a
|
120
|
-
- a a
|
121
|
-
+ a a b
|
122
|
-
# this one is changed
|
123
|
-
- a b
|
124
|
-
+ a b c a
|
125
|
-
- a b c
|
126
|
-
+ a b b b b b b
|
127
|
-
- a z
|
128
|
-
- z
|
129
|
-
SAMPLE
|
130
|
-
assert_equal(false, sample.correctly_classified_by?(@small_nfa))
|
131
|
-
sample = ADL::parse_sample <<-SAMPLE
|
132
|
-
+
|
133
|
-
+ a
|
134
|
-
# this one is changed
|
135
|
-
+ a a
|
136
|
-
+ a a b
|
137
|
-
+ a b
|
138
|
-
+ a b c a
|
139
|
-
- a b c
|
140
|
-
+ a b b b b b b
|
141
|
-
- a z
|
142
|
-
- z
|
143
|
-
SAMPLE
|
144
|
-
assert_equal(false, sample.correctly_classified_by?(@small_nfa))
|
145
|
-
end
|
146
|
-
|
147
|
-
end # class ClassifyTest
|
148
|
-
end # class Sample
|
149
|
-
end # module Stamina
|
data/test/stamina/sample_test.rb
DELETED
@@ -1,290 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'stamina/errors'
|
3
|
-
require 'stamina/stamina_test'
|
4
|
-
require 'stamina/sample'
|
5
|
-
module Stamina
|
6
|
-
class SampleTest < StaminaTest
|
7
|
-
|
8
|
-
# Converts a String to an InputString
|
9
|
-
def s(str)
|
10
|
-
Stamina::ADL::parse_string(str)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Tests Sample#empty?
|
14
|
-
def test_empty
|
15
|
-
assert_equal(true, Sample.new.empty?)
|
16
|
-
assert_equal(true, Sample[].empty?)
|
17
|
-
assert_equal(false, Sample['?'].empty?)
|
18
|
-
assert_equal(false, Sample['-'].empty?)
|
19
|
-
assert_equal(false, Sample['+'].empty?)
|
20
|
-
assert_equal(false, Sample['+ a b'].empty?)
|
21
|
-
assert_equal(false, Sample['+ a b', '- a'].empty?)
|
22
|
-
assert_equal(false, Sample['- a b'].empty?)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Tests Sample#size
|
26
|
-
def test_size_and_counts
|
27
|
-
s = Sample.new
|
28
|
-
assert_equal(0, s.size)
|
29
|
-
assert_equal(0, s.positive_count)
|
30
|
-
assert_equal(0, s.negative_count)
|
31
|
-
s << '+ a b'
|
32
|
-
assert_equal(1, s.size)
|
33
|
-
assert_equal(1, s.positive_count)
|
34
|
-
assert_equal(0, s.negative_count)
|
35
|
-
s << '+ a b'
|
36
|
-
assert_equal(2, s.size)
|
37
|
-
assert_equal(2, s.positive_count)
|
38
|
-
assert_equal(0, s.negative_count)
|
39
|
-
s << '+ a'
|
40
|
-
assert_equal(3, s.size)
|
41
|
-
assert_equal(3, s.positive_count)
|
42
|
-
assert_equal(0, s.negative_count)
|
43
|
-
s << '- a b c'
|
44
|
-
assert_equal(4, s.size)
|
45
|
-
assert_equal(3, s.positive_count)
|
46
|
-
assert_equal(1, s.negative_count)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_same_string_can_be_added_many_times
|
50
|
-
s = Sample.new
|
51
|
-
10.times {|i| s << "+ a b"}
|
52
|
-
assert_equal(10, s.size)
|
53
|
-
assert_equal(10, s.positive_count)
|
54
|
-
assert_equal(0, s.negative_count)
|
55
|
-
strings = s.collect{|s| s}
|
56
|
-
assert_equal 10, strings.size
|
57
|
-
end
|
58
|
-
|
59
|
-
# Tests Sample#<<
|
60
|
-
def test_append
|
61
|
-
s = Sample.new
|
62
|
-
assert_equal(s,s << '+',"Accepts empty string")
|
63
|
-
assert_equal(s,s << '+ a b a b a',"Accepts positive string")
|
64
|
-
assert_equal(s,s << '- a',"Accepts negative string")
|
65
|
-
assert_equal(s,s << '? a',"Accepts unlabeled string")
|
66
|
-
end
|
67
|
-
|
68
|
-
# Tests Sample#include? on every kind of arguments it announce
|
69
|
-
def test_append_accepts_arguments_it_annouce
|
70
|
-
expected = Sample[
|
71
|
-
'+ a b a b',
|
72
|
-
'+ a b',
|
73
|
-
'-',
|
74
|
-
'- a',
|
75
|
-
'+ a b a b a b'
|
76
|
-
]
|
77
|
-
s = Sample.new
|
78
|
-
s << '+ a b a b'
|
79
|
-
s << ['+ a b', '-']
|
80
|
-
s << InputString.new('a', false)
|
81
|
-
s << Sample['+ a b a b a b', '-']
|
82
|
-
assert_equal(expected,s)
|
83
|
-
end
|
84
|
-
|
85
|
-
# Tests that Sample#<< detects inconsistencies
|
86
|
-
# def test_append_detects_inconsistency
|
87
|
-
# s = Sample.new
|
88
|
-
# s << '+ a b'
|
89
|
-
# s << '+ a b a b'
|
90
|
-
# assert_raise InconsistencyError do
|
91
|
-
# s << '- a b a b'
|
92
|
-
# end
|
93
|
-
# end
|
94
|
-
|
95
|
-
# Tests that Sample#<< detects inconsistencies
|
96
|
-
def test_append_detects_real_inconsistencies_only
|
97
|
-
s = Sample.new
|
98
|
-
s << '+ a b'
|
99
|
-
s << '+ a b a b'
|
100
|
-
assert_nothing_raised do
|
101
|
-
s << '- b'
|
102
|
-
s << '- a'
|
103
|
-
s << '- a b a'
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# Tests each
|
108
|
-
def test_each
|
109
|
-
strings = ['+ a b a b', '+ a b', '+ a b', '- a', '+']
|
110
|
-
strings = strings.collect{|s| ADL::parse_string(s)}
|
111
|
-
s = Sample.new << strings
|
112
|
-
count = 0
|
113
|
-
s.each do |str|
|
114
|
-
assert_equal(true, strings.include?(str))
|
115
|
-
count += 1
|
116
|
-
end
|
117
|
-
assert_equal(strings.size, count)
|
118
|
-
end
|
119
|
-
|
120
|
-
# Tests each_positive
|
121
|
-
def test_each_positive
|
122
|
-
sample = Sample[
|
123
|
-
'+',
|
124
|
-
'- b',
|
125
|
-
'+ a b a b',
|
126
|
-
'- a b a a'
|
127
|
-
]
|
128
|
-
count = 0
|
129
|
-
sample.each_positive do |str|
|
130
|
-
assert str.positive?
|
131
|
-
count += 1
|
132
|
-
end
|
133
|
-
assert_equal 2, count
|
134
|
-
positives = sample.positive_enumerator.collect{|s| s}
|
135
|
-
assert_equal 2, positives.size
|
136
|
-
[s('+'), s('+ a b a b')].each do |str|
|
137
|
-
assert positives.include?(str)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
# Tests each_negative
|
142
|
-
def test_each_negative
|
143
|
-
sample = Sample[
|
144
|
-
'+',
|
145
|
-
'- b',
|
146
|
-
'+ a b a b',
|
147
|
-
'- a b a a'
|
148
|
-
]
|
149
|
-
count = 0
|
150
|
-
sample.each_negative do |str|
|
151
|
-
assert str.negative?
|
152
|
-
count += 1
|
153
|
-
end
|
154
|
-
assert_equal 2, count
|
155
|
-
negatives = sample.negative_enumerator.collect{|s| s}
|
156
|
-
assert_equal 2, negatives.size
|
157
|
-
[s('- b'), s('- a b a a')].each do |str|
|
158
|
-
assert negatives.include?(str)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# Tests Sample#include?
|
163
|
-
def test_include
|
164
|
-
strings = ['+ a b a b', '+ a b', '- a', '+']
|
165
|
-
s = Sample.new << strings
|
166
|
-
strings.each do |str|
|
167
|
-
assert_equal(true, s.include?(str))
|
168
|
-
end
|
169
|
-
assert_equal(true, s.include?(strings))
|
170
|
-
assert_equal(true, s.include?(s))
|
171
|
-
assert_equal(false, s.include?('+ a'))
|
172
|
-
assert_equal(false, s.include?('-'))
|
173
|
-
assert_equal(false, s.include?('+ a b a'))
|
174
|
-
end
|
175
|
-
|
176
|
-
# Tests Sample#include? on every kind of arguments it announce
|
177
|
-
def test_include_accepts_arguments_it_annouce
|
178
|
-
s = Sample.new << ['+ a b a b', '+ a b', '- a', '+']
|
179
|
-
assert_equal true, s.include?('+ a b a b')
|
180
|
-
assert_equal true, s.include?(InputString.new('a b a b',true))
|
181
|
-
assert_equal true, s.include?(ADL::parse_string('+ a b a b'))
|
182
|
-
assert_equal true, s.include?(['+ a b a b', '+ a b'])
|
183
|
-
assert_equal true, s.include?(s)
|
184
|
-
end
|
185
|
-
|
186
|
-
# Tests Sample#==
|
187
|
-
def test_equal
|
188
|
-
s1 = Sample['+ a b a b', '+', '- a']
|
189
|
-
s2 = Sample['+ a b a b', '+', '+ a']
|
190
|
-
assert_equal(true, s1==s1)
|
191
|
-
assert_equal(true, s2==s2)
|
192
|
-
assert_equal(false, s1==s2)
|
193
|
-
assert_equal(false, s1==Sample.new)
|
194
|
-
assert_equal(false, s2==Sample.new)
|
195
|
-
end
|
196
|
-
|
197
|
-
# Test the signature
|
198
|
-
def test_signature
|
199
|
-
s = Sample.new
|
200
|
-
assert_equal '', s.signature
|
201
|
-
s = Sample.new << ['+ a b a b', '+ a b', '- a', '+']
|
202
|
-
assert_equal '1101', s.signature
|
203
|
-
s = Sample.new << ['+ a b a b', '+ a b', '- a', '?']
|
204
|
-
assert_equal '110?', s.signature
|
205
|
-
s = Stamina::ADL.parse_sample <<-SAMPLE
|
206
|
-
+
|
207
|
-
+ a b
|
208
|
-
- a c
|
209
|
-
? a d
|
210
|
-
SAMPLE
|
211
|
-
assert_equal '110?', s.signature
|
212
|
-
end
|
213
|
-
|
214
|
-
def test_to_pta_on_empty_sample
|
215
|
-
empty = Stamina::ADL::parse_automaton <<-EOF
|
216
|
-
1 0
|
217
|
-
0 true false
|
218
|
-
EOF
|
219
|
-
assert_equivalent empty, Sample.new.to_pta
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_to_pta_on_lambda_accepting_sample
|
223
|
-
dfa = Stamina::ADL::parse_automaton <<-EOF
|
224
|
-
1 0
|
225
|
-
0 true true false
|
226
|
-
EOF
|
227
|
-
sample = Stamina::ADL::parse_sample <<-EOF
|
228
|
-
+
|
229
|
-
EOF
|
230
|
-
assert_equivalent dfa, sample.to_pta
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_to_pta_on_lambda_rejecting_sample
|
234
|
-
dfa = Stamina::ADL::parse_automaton <<-EOF
|
235
|
-
1 0
|
236
|
-
0 true false true
|
237
|
-
EOF
|
238
|
-
sample = Stamina::ADL::parse_sample <<-EOF
|
239
|
-
-
|
240
|
-
EOF
|
241
|
-
assert_equivalent dfa, sample.to_pta
|
242
|
-
end
|
243
|
-
|
244
|
-
def test_to_pta_respects_natural_ordering
|
245
|
-
dfa = Stamina::ADL::parse_automaton <<-EOF
|
246
|
-
3 2
|
247
|
-
0 true false
|
248
|
-
1 false true
|
249
|
-
2 false true
|
250
|
-
0 1 a
|
251
|
-
0 2 b
|
252
|
-
EOF
|
253
|
-
sample = Stamina::ADL::parse_sample <<-EOF
|
254
|
-
+ a
|
255
|
-
+ b
|
256
|
-
EOF
|
257
|
-
pta = sample.to_pta
|
258
|
-
assert_equivalent dfa, pta
|
259
|
-
assert_equal pta.ith_state(1), pta.dfa_reached("? a")
|
260
|
-
assert_equal pta.ith_state(2), pta.dfa_reached("? b")
|
261
|
-
end
|
262
|
-
|
263
|
-
def test_to_pta_on_realcase_example
|
264
|
-
dfa = Stamina::ADL::parse_automaton <<-EOF
|
265
|
-
5 4
|
266
|
-
0 true true
|
267
|
-
1 false true
|
268
|
-
2 false false true
|
269
|
-
3 false false true
|
270
|
-
4 false true
|
271
|
-
0 1 a
|
272
|
-
0 2 b
|
273
|
-
1 3 b
|
274
|
-
2 4 a
|
275
|
-
EOF
|
276
|
-
sample = Stamina::ADL::parse_sample <<-EOF
|
277
|
-
+
|
278
|
-
+ a
|
279
|
-
+ b a
|
280
|
-
- a b
|
281
|
-
- b
|
282
|
-
EOF
|
283
|
-
pta = sample.to_pta
|
284
|
-
assert_equivalent dfa, pta
|
285
|
-
assert_equal pta.ith_state(3), pta.dfa_reached("? a b")
|
286
|
-
assert_equal pta.ith_state(4), pta.dfa_reached("? b a")
|
287
|
-
end
|
288
|
-
|
289
|
-
end # class SampleTest
|
290
|
-
end # module Stamina
|