ellington 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -44
- data/lib/ellington/conductor.rb +16 -8
- data/lib/ellington/connection.rb +18 -3
- data/lib/ellington/errros.rb +6 -6
- data/lib/ellington/line.rb +19 -8
- data/lib/ellington/line_info.rb +2 -1
- data/lib/ellington/line_list.rb +6 -6
- data/lib/ellington/passenger.rb +6 -0
- data/lib/ellington/route.rb +28 -18
- data/lib/ellington/route_info.rb +1 -1
- data/lib/ellington/station.rb +6 -6
- data/lib/ellington/station_list.rb +4 -4
- data/lib/ellington/unique_type_array.rb +1 -4
- data/lib/ellington/version.rb +1 -1
- data/lib/ellington.rb +1 -1
- data/test/attendant_test.rb +5 -5
- data/test/conductor_test.rb +55 -26
- data/test/connection_test.rb +19 -0
- data/test/example.rb +51 -47
- data/test/line_info_test.rb +78 -0
- data/test/line_test.rb +60 -1
- data/test/logger_test.rb +20 -0
- data/test/passenger_test.rb +9 -0
- data/test/route_info_test.rb +63 -0
- data/test/route_test.rb +80 -0
- data/test/station_info_test.rb +31 -0
- data/test/station_test.rb +7 -7
- data/test/test_helper.rb +0 -1
- data/test/transition_info_test.rb +25 -0
- data/test/unique_type_array_test.rb +32 -0
- metadata +24 -14
data/test/example.rb
CHANGED
@@ -25,128 +25,128 @@ end
|
|
25
25
|
|
26
26
|
# stations -----------------------------------------------------------------
|
27
27
|
class Add10 < Ellington::Station
|
28
|
-
def engage(
|
28
|
+
def engage(number, options)
|
29
29
|
raise if rand(100) == 0
|
30
30
|
if rand(100) > 5
|
31
|
-
|
32
|
-
|
31
|
+
number.calc :+, 10
|
32
|
+
pass_passenger number
|
33
33
|
else
|
34
|
-
|
34
|
+
fail_passenger number
|
35
35
|
end
|
36
36
|
rescue
|
37
|
-
|
37
|
+
error_passenger number
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
class Add100 < Ellington::Station
|
42
|
-
def engage(
|
42
|
+
def engage(number, options)
|
43
43
|
raise if rand(100) == 0
|
44
44
|
if rand(100) > 5
|
45
|
-
|
46
|
-
|
45
|
+
number.calc :+, 100
|
46
|
+
pass_passenger number
|
47
47
|
else
|
48
|
-
|
48
|
+
fail_passenger number
|
49
49
|
end
|
50
50
|
rescue
|
51
|
-
|
51
|
+
error_passenger number
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
class Add1000 < Ellington::Station
|
56
|
-
def engage(
|
56
|
+
def engage(number, options)
|
57
57
|
raise if rand(100) == 0
|
58
58
|
if rand(100) > 5
|
59
|
-
|
60
|
-
|
59
|
+
number.calc :+, 1000
|
60
|
+
pass_passenger number
|
61
61
|
else
|
62
|
-
|
62
|
+
fail_passenger number
|
63
63
|
end
|
64
64
|
rescue
|
65
|
-
|
65
|
+
error_passenger number
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
class MultiplyBy10 < Ellington::Station
|
70
|
-
def engage(
|
70
|
+
def engage(number, options)
|
71
71
|
raise if rand(100) == 0
|
72
72
|
if rand(100) > 5
|
73
|
-
|
74
|
-
|
73
|
+
number.calc :*, 10
|
74
|
+
pass_passenger number
|
75
75
|
else
|
76
|
-
|
76
|
+
fail_passenger number
|
77
77
|
end
|
78
78
|
rescue
|
79
|
-
|
79
|
+
error_passenger number
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
class MultiplyBy100 < Ellington::Station
|
84
|
-
def engage(
|
84
|
+
def engage(number, options)
|
85
85
|
raise if rand(100) == 0
|
86
86
|
if rand(100) > 5
|
87
|
-
|
88
|
-
|
87
|
+
number.calc :*, 100
|
88
|
+
pass_passenger number
|
89
89
|
else
|
90
|
-
|
90
|
+
fail_passenger number
|
91
91
|
end
|
92
92
|
rescue
|
93
|
-
|
93
|
+
error_passenger number
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
class MultiplyBy1000 < Ellington::Station
|
98
|
-
def engage(
|
98
|
+
def engage(number, options)
|
99
99
|
raise if rand(100) == 0
|
100
100
|
if rand(100) > 5
|
101
|
-
|
102
|
-
|
101
|
+
number.calc :*, 1000
|
102
|
+
pass_passenger number
|
103
103
|
else
|
104
|
-
|
104
|
+
fail_passenger number
|
105
105
|
end
|
106
106
|
rescue
|
107
|
-
|
107
|
+
error_passenger number
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
111
|
class DivideBy10 < Ellington::Station
|
112
|
-
def engage(
|
112
|
+
def engage(number, options)
|
113
113
|
raise if rand(100) == 0
|
114
114
|
if rand(100) > 5
|
115
|
-
|
116
|
-
|
115
|
+
number.calc :/, 10.0
|
116
|
+
pass_passenger number
|
117
117
|
else
|
118
|
-
|
118
|
+
fail_passenger number
|
119
119
|
end
|
120
120
|
rescue
|
121
|
-
|
121
|
+
error_passenger number
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
125
|
class DivideBy100 < Ellington::Station
|
126
|
-
def engage(
|
126
|
+
def engage(number, options)
|
127
127
|
raise if rand(100) == 0
|
128
128
|
if rand(100) > 5
|
129
|
-
|
130
|
-
|
129
|
+
number.calc :/, 100.0
|
130
|
+
pass_passenger number
|
131
131
|
else
|
132
|
-
|
132
|
+
fail_passenger number
|
133
133
|
end
|
134
134
|
rescue
|
135
|
-
|
135
|
+
error_passenger number
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
139
|
class DivideBy1000 < Ellington::Station
|
140
|
-
def engage(
|
140
|
+
def engage(number, options)
|
141
141
|
raise if rand(100) == 0
|
142
142
|
if rand(100) > 5
|
143
|
-
|
144
|
-
|
143
|
+
number.calc :/, 1000.0
|
144
|
+
pass_passenger number
|
145
145
|
else
|
146
|
-
|
146
|
+
fail_passenger number
|
147
147
|
end
|
148
148
|
rescue
|
149
|
-
|
149
|
+
error_passenger number
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
@@ -184,8 +184,8 @@ class BasicMath < Ellington::Route
|
|
184
184
|
|
185
185
|
goal division.passed, multiplication.passed
|
186
186
|
|
187
|
-
connect_to division, :
|
188
|
-
connect_to multiplication, :
|
187
|
+
connect_to division, :if_any => addition.passed
|
188
|
+
connect_to multiplication, :if_any => addition.failed
|
189
189
|
|
190
190
|
log_passenger_attrs :original_value, :current_value
|
191
191
|
end
|
@@ -194,6 +194,7 @@ end
|
|
194
194
|
class NumberConductor < Ellington::Conductor
|
195
195
|
|
196
196
|
def gather_passengers
|
197
|
+
sleep 1
|
197
198
|
(0..999).to_a.sample(10).map do |num|
|
198
199
|
num = NumberWithHistory.new(num)
|
199
200
|
passenger = Ellington::Passenger.new(num, route)
|
@@ -209,4 +210,7 @@ if ENV["START"]
|
|
209
210
|
route = BasicMath.new
|
210
211
|
conductor = NumberConductor.new(route)
|
211
212
|
conductor.start
|
213
|
+
#conductor.wait
|
214
|
+
sleep 5
|
215
|
+
conductor.stop
|
212
216
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class LineInfoTest < MicroTest::Test
|
4
|
+
|
5
|
+
before do
|
6
|
+
@route = BasicMath.new
|
7
|
+
@line = @route.lines.first
|
8
|
+
@station = @line.stations.first
|
9
|
+
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), @route)
|
10
|
+
@options = { :foo => :bar }
|
11
|
+
@transition_info = Ellington::TransitionInfo.new(@passenger, @route.initial_state, @station.passed)
|
12
|
+
@station_info = Ellington::StationInfo.new(@station, @passenger, @transition_info, @options)
|
13
|
+
@line_info = Ellington::LineInfo.new(@line, @station_info)
|
14
|
+
end
|
15
|
+
|
16
|
+
test "line" do
|
17
|
+
assert @line_info.line == @line
|
18
|
+
end
|
19
|
+
|
20
|
+
test "station_info" do
|
21
|
+
assert @line_info.station_info == @station_info
|
22
|
+
end
|
23
|
+
|
24
|
+
test "station" do
|
25
|
+
assert @line_info.station == @station
|
26
|
+
end
|
27
|
+
|
28
|
+
test "passenger" do
|
29
|
+
assert @line_info.passenger == @passenger
|
30
|
+
end
|
31
|
+
|
32
|
+
test "transition" do
|
33
|
+
assert @line_info.transition == @transition_info
|
34
|
+
end
|
35
|
+
|
36
|
+
test "options" do
|
37
|
+
assert @line_info.options == @options
|
38
|
+
end
|
39
|
+
|
40
|
+
test "station_full_name" do
|
41
|
+
assert @line_info.station_full_name == "Add10::Addition::BasicMath"
|
42
|
+
end
|
43
|
+
|
44
|
+
test "log_message" do
|
45
|
+
assert @line_info.log_message == "[original_value:0] [current_value:0]"
|
46
|
+
end
|
47
|
+
|
48
|
+
test "log_message with station_completed pass" do
|
49
|
+
@passenger.current_state = @station.passed
|
50
|
+
expected = "[STATION COMPLETED] [PASS] [Add10::Addition::BasicMath] [original_value:0] [current_value:0]"
|
51
|
+
assert @line_info.log_message(:station_completed => true) == expected
|
52
|
+
end
|
53
|
+
|
54
|
+
test "log_message with station_completed fail" do
|
55
|
+
@passenger.current_state = @station.failed
|
56
|
+
expected = "[STATION COMPLETED] [FAIL] [Add10::Addition::BasicMath] [original_value:0] [current_value:0]"
|
57
|
+
assert @line_info.log_message(:station_completed => true) == expected
|
58
|
+
end
|
59
|
+
|
60
|
+
test "log_message with station_completed error" do
|
61
|
+
@passenger.current_state = @station.errored
|
62
|
+
expected = "[STATION COMPLETED] [ERROR] [Add10::Addition::BasicMath] [original_value:0] [current_value:0]"
|
63
|
+
assert @line_info.log_message(:station_completed => true) == expected
|
64
|
+
end
|
65
|
+
|
66
|
+
test "log_message with line_completed pass" do
|
67
|
+
@passenger.current_state = @line.stations.last.passed
|
68
|
+
expected = "[LINE COMPLETED] [PASS] [Addition::BasicMath] [original_value:0] [current_value:0]"
|
69
|
+
assert @line_info.log_message(:line_completed => true) == expected
|
70
|
+
end
|
71
|
+
|
72
|
+
test "log_message with line_completed fail" do
|
73
|
+
@passenger.current_state = @line.stations.last.failed
|
74
|
+
expected = "[LINE COMPLETED] [FAIL] [Addition::BasicMath] [original_value:0] [current_value:0]"
|
75
|
+
assert @line_info.log_message(:line_completed => true) == expected
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/test/line_test.rb
CHANGED
@@ -5,6 +5,28 @@ class LineTest < MicroTest::Test
|
|
5
5
|
before do
|
6
6
|
@route = BasicMath.new
|
7
7
|
@line = @route.lines.first
|
8
|
+
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), @route)
|
9
|
+
end
|
10
|
+
|
11
|
+
test "must declare stations" do
|
12
|
+
class NoStationsLine < Ellington::Line
|
13
|
+
end
|
14
|
+
begin
|
15
|
+
NoStationsLine.new
|
16
|
+
rescue Ellington::NoStationsDeclared => e
|
17
|
+
end
|
18
|
+
assert !e.nil?
|
19
|
+
end
|
20
|
+
|
21
|
+
test "must declare goal" do
|
22
|
+
class NoGoalLine < Ellington::Line
|
23
|
+
stations << Add10.new
|
24
|
+
end
|
25
|
+
begin
|
26
|
+
NoGoalLine.new
|
27
|
+
rescue Ellington::NoGoalDeclared => e
|
28
|
+
end
|
29
|
+
assert !e.nil?
|
8
30
|
end
|
9
31
|
|
10
32
|
test "stations on class" do
|
@@ -31,7 +53,7 @@ class LineTest < MicroTest::Test
|
|
31
53
|
|
32
54
|
test "stations are assigned line" do
|
33
55
|
@line.stations.each do |station|
|
34
|
-
assert station.line == @line
|
56
|
+
assert station.line == @line
|
35
57
|
end
|
36
58
|
end
|
37
59
|
|
@@ -92,4 +114,41 @@ class LineTest < MicroTest::Test
|
|
92
114
|
assert line.fail_target == expected
|
93
115
|
end
|
94
116
|
|
117
|
+
test "passed" do
|
118
|
+
assert @line.passed == ["PASS Add1000::Addition"]
|
119
|
+
end
|
120
|
+
|
121
|
+
test "state pass" do
|
122
|
+
@passenger.current_state = @line.passed.first
|
123
|
+
assert @line.state(@passenger) == "PASS"
|
124
|
+
end
|
125
|
+
|
126
|
+
test "failed" do
|
127
|
+
assert @line.failed == [
|
128
|
+
"PASS Add10::Addition",
|
129
|
+
"FAIL Add10::Addition",
|
130
|
+
"PASS Add100::Addition",
|
131
|
+
"FAIL Add100::Addition",
|
132
|
+
"FAIL Add1000::Addition"
|
133
|
+
]
|
134
|
+
end
|
135
|
+
|
136
|
+
test "state fail" do
|
137
|
+
@passenger.current_state = @line.failed.first
|
138
|
+
assert @line.state(@passenger) == "FAIL"
|
139
|
+
end
|
140
|
+
|
141
|
+
test "errored" do
|
142
|
+
assert @line.errored == [
|
143
|
+
"ERROR Add10::Addition",
|
144
|
+
"ERROR Add100::Addition",
|
145
|
+
"ERROR Add1000::Addition"
|
146
|
+
]
|
147
|
+
end
|
148
|
+
|
149
|
+
test "state error" do
|
150
|
+
@passenger.current_state = @line.errored.first
|
151
|
+
assert @line.state(@passenger) == "ERROR"
|
152
|
+
end
|
153
|
+
|
95
154
|
end
|
data/test/logger_test.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
class LoggerTest < MicroTest::Test
|
5
|
+
|
6
|
+
before do
|
7
|
+
@orig_logger = Ellington.logger
|
8
|
+
@logger = Logger.new(STDOUT)
|
9
|
+
Ellington.logger = @logger
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
Ellington.logger = @orig_logger
|
14
|
+
end
|
15
|
+
|
16
|
+
test "logger attr" do
|
17
|
+
assert Ellington.logger == @logger
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/test/passenger_test.rb
CHANGED
@@ -70,4 +70,13 @@ class PassengerTest < MicroTest::Test
|
|
70
70
|
assert watcher.info.new_state == "PASS Add10::Addition"
|
71
71
|
end
|
72
72
|
|
73
|
+
test "state_history" do
|
74
|
+
@passenger.lock
|
75
|
+
@passenger.current_state = @route.initial_state
|
76
|
+
@passenger.transition_to @route.lines[0].states.keys.first
|
77
|
+
@passenger.transition_to @route.lines[2].states.keys.first
|
78
|
+
@passenger.unlock
|
79
|
+
assert @passenger.state_history == ["PASS Add10::Addition", "PASS MultiplyBy10::Multiplication"]
|
80
|
+
end
|
81
|
+
|
73
82
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class RouteInfoTest < MicroTest::Test
|
4
|
+
|
5
|
+
before do
|
6
|
+
@route = BasicMath.new
|
7
|
+
@line = @route.lines.first
|
8
|
+
@station = @line.stations.first
|
9
|
+
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), @route)
|
10
|
+
@passenger.current_state = @route.lines.last.passed.first
|
11
|
+
@options = { :foo => :bar }
|
12
|
+
@transition_info = Ellington::TransitionInfo.new(@passenger, @route.initial_state, @station.passed)
|
13
|
+
@station_info = Ellington::StationInfo.new(@station, @passenger, @transition_info, @options)
|
14
|
+
@line_info = Ellington::LineInfo.new(@line, @station_info)
|
15
|
+
@route_info = Ellington::RouteInfo.new(@route, @line_info)
|
16
|
+
end
|
17
|
+
|
18
|
+
test "route" do
|
19
|
+
assert @route_info.route == @route
|
20
|
+
end
|
21
|
+
|
22
|
+
test "line" do
|
23
|
+
assert @route_info.line == @line
|
24
|
+
end
|
25
|
+
|
26
|
+
test "line_info" do
|
27
|
+
assert @route_info.line_info == @line_info
|
28
|
+
end
|
29
|
+
|
30
|
+
test "station_info" do
|
31
|
+
assert @route_info.station_info == @station_info
|
32
|
+
end
|
33
|
+
|
34
|
+
test "station" do
|
35
|
+
assert @route_info.station == @station
|
36
|
+
end
|
37
|
+
|
38
|
+
test "passenger" do
|
39
|
+
assert @route_info.passenger == @passenger
|
40
|
+
end
|
41
|
+
|
42
|
+
test "transition" do
|
43
|
+
assert @route_info.transition == @transition_info
|
44
|
+
end
|
45
|
+
|
46
|
+
test "options" do
|
47
|
+
assert @route_info.options == @options
|
48
|
+
end
|
49
|
+
|
50
|
+
test "station_full_name" do
|
51
|
+
assert @route_info.station_full_name == "Add10::Addition::BasicMath"
|
52
|
+
end
|
53
|
+
|
54
|
+
test "log_message route pass" do
|
55
|
+
assert @route_info.log_message == "[ROUTE COMPLETED] [PASS] [BasicMath] [original_value:0] [current_value:0]"
|
56
|
+
end
|
57
|
+
|
58
|
+
test "log_message route fail" do
|
59
|
+
@passenger.current_state = @station.failed
|
60
|
+
assert @route_info.log_message == "[ROUTE COMPLETED] [FAIL] [BasicMath] [original_value:0] [current_value:0]"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/test/route_test.rb
CHANGED
@@ -4,6 +4,28 @@ class RouteTest < MicroTest::Test
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
@route = BasicMath.new
|
7
|
+
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), @route)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "must declare lines" do
|
11
|
+
class NoLinesRoute < Ellington::Route
|
12
|
+
end
|
13
|
+
begin
|
14
|
+
NoLinesRoute.new
|
15
|
+
rescue Ellington::NoLinesDeclared => e
|
16
|
+
end
|
17
|
+
assert !e.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
test "must declare goal" do
|
21
|
+
class NoGoalRoute < Ellington::Route
|
22
|
+
lines << Addition.new
|
23
|
+
end
|
24
|
+
begin
|
25
|
+
NoGoalRoute.new
|
26
|
+
rescue Ellington::NoGoalDeclared => e
|
27
|
+
end
|
28
|
+
assert !e.nil?
|
7
29
|
end
|
8
30
|
|
9
31
|
test "lines on class" do
|
@@ -48,4 +70,62 @@ class RouteTest < MicroTest::Test
|
|
48
70
|
assert @route.connections.last.states == @route.lines[0].fail_target
|
49
71
|
end
|
50
72
|
|
73
|
+
test "passed" do
|
74
|
+
assert @route.passed == [
|
75
|
+
"PASS DivideBy1000::Division",
|
76
|
+
"PASS MultiplyBy1000::Multiplication"
|
77
|
+
]
|
78
|
+
end
|
79
|
+
|
80
|
+
test "state pass" do
|
81
|
+
@passenger.current_state = @route.passed.first
|
82
|
+
assert @route.state(@passenger) == "PASS"
|
83
|
+
end
|
84
|
+
|
85
|
+
test "failed" do
|
86
|
+
assert @route.failed == [
|
87
|
+
"PRE BasicMath",
|
88
|
+
"PASS Add10::Addition",
|
89
|
+
"FAIL Add10::Addition",
|
90
|
+
"PASS Add100::Addition",
|
91
|
+
"FAIL Add100::Addition",
|
92
|
+
"PASS Add1000::Addition",
|
93
|
+
"FAIL Add1000::Addition",
|
94
|
+
"PASS DivideBy10::Division",
|
95
|
+
"FAIL DivideBy10::Division",
|
96
|
+
"PASS DivideBy100::Division",
|
97
|
+
"FAIL DivideBy100::Division",
|
98
|
+
"FAIL DivideBy1000::Division",
|
99
|
+
"PASS MultiplyBy10::Multiplication",
|
100
|
+
"FAIL MultiplyBy10::Multiplication",
|
101
|
+
"PASS MultiplyBy100::Multiplication",
|
102
|
+
"FAIL MultiplyBy100::Multiplication",
|
103
|
+
"FAIL MultiplyBy1000::Multiplication"
|
104
|
+
]
|
105
|
+
end
|
106
|
+
|
107
|
+
test "state fail" do
|
108
|
+
@passenger.current_state = @route.failed.first
|
109
|
+
assert @route.state(@passenger) == "FAIL"
|
110
|
+
end
|
111
|
+
|
112
|
+
test "errored" do
|
113
|
+
assert @route.errored == [
|
114
|
+
"ERROR Add10::Addition",
|
115
|
+
"ERROR Add100::Addition",
|
116
|
+
"ERROR Add1000::Addition",
|
117
|
+
"ERROR DivideBy10::Division",
|
118
|
+
"ERROR DivideBy100::Division",
|
119
|
+
"ERROR DivideBy1000::Division",
|
120
|
+
"ERROR MultiplyBy10::Multiplication",
|
121
|
+
"ERROR MultiplyBy100::Multiplication",
|
122
|
+
"ERROR MultiplyBy1000::Multiplication"
|
123
|
+
]
|
124
|
+
end
|
125
|
+
|
126
|
+
test "state error" do
|
127
|
+
@passenger.current_state = @route.errored.first
|
128
|
+
assert @route.state(@passenger) == "ERROR"
|
129
|
+
end
|
130
|
+
|
51
131
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class StationInfoTest < MicroTest::Test
|
4
|
+
|
5
|
+
before do
|
6
|
+
@route = BasicMath.new
|
7
|
+
@line = @route.lines.first
|
8
|
+
@station = @line.stations.first
|
9
|
+
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), @route)
|
10
|
+
@options = { :foo => :bar }
|
11
|
+
@transition_info = Ellington::TransitionInfo.new(@passenger, @route.initial_state, @station.passed)
|
12
|
+
@station_info = Ellington::StationInfo.new(@station, @passenger, @transition_info, @options)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "station" do
|
16
|
+
assert @station_info.station == @station
|
17
|
+
end
|
18
|
+
|
19
|
+
test "passenger" do
|
20
|
+
assert @station_info.passenger == @passenger
|
21
|
+
end
|
22
|
+
|
23
|
+
test "transition" do
|
24
|
+
assert @station_info.transition == @transition_info
|
25
|
+
end
|
26
|
+
|
27
|
+
test "options" do
|
28
|
+
assert @station_info.options == @options
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/test/station_test.rb
CHANGED
@@ -61,19 +61,19 @@ class StationTest < MicroTest::Test
|
|
61
61
|
|
62
62
|
test "pass properly transitions passenger's state" do
|
63
63
|
@passenger.current_state = @route.initial_state
|
64
|
-
@station.
|
64
|
+
@station.pass_passenger @passenger
|
65
65
|
assert @passenger.current_state == @station.passed
|
66
66
|
end
|
67
67
|
|
68
68
|
test "fail properly transitions passenger's state" do
|
69
69
|
@passenger.current_state = @route.initial_state
|
70
|
-
@station.
|
70
|
+
@station.fail_passenger @passenger
|
71
71
|
assert @passenger.current_state == @station.failed
|
72
72
|
end
|
73
73
|
|
74
74
|
test "error properly transitions passenger's state" do
|
75
75
|
@passenger.current_state = @route.initial_state
|
76
|
-
@station.
|
76
|
+
@station.error_passenger @passenger
|
77
77
|
assert @passenger.current_state == @station.errored
|
78
78
|
end
|
79
79
|
|
@@ -91,8 +91,8 @@ class StationTest < MicroTest::Test
|
|
91
91
|
|
92
92
|
test "engage" do
|
93
93
|
@passenger.current_state = @route.initial_state
|
94
|
-
@station.engage(@passenger,
|
95
|
-
assert @passenger.current_state
|
94
|
+
@station.engage(@passenger, nil)
|
95
|
+
assert @passenger.current_state != @route.initial_state
|
96
96
|
end
|
97
97
|
|
98
98
|
test "observers are notified after a station completes" do
|
@@ -103,13 +103,13 @@ class StationTest < MicroTest::Test
|
|
103
103
|
end
|
104
104
|
@station.add_observer observer
|
105
105
|
@passenger.current_state = @route.initial_state
|
106
|
-
@station.call(@passenger
|
106
|
+
@station.call(@passenger)
|
107
107
|
assert observer.callbacks.length == 1
|
108
108
|
info = observer.callbacks.first
|
109
109
|
assert info.station == @station
|
110
110
|
assert info.passenger == @passenger
|
111
111
|
assert info.transition.old_state == @route.initial_state
|
112
|
-
assert info.transition.new_state
|
112
|
+
assert info.transition.new_state != @route.initial_state
|
113
113
|
end
|
114
114
|
|
115
115
|
end
|
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class TransitionInfoTest < MicroTest::Test
|
4
|
+
|
5
|
+
before do
|
6
|
+
@route = BasicMath.new
|
7
|
+
@line = @route.lines.first
|
8
|
+
@station = @line.stations.first
|
9
|
+
@passenger = Ellington::Passenger.new(NumberWithHistory.new(0), @route)
|
10
|
+
@transition_info = Ellington::TransitionInfo.new(@passenger, @route.initial_state, @station.passed)
|
11
|
+
end
|
12
|
+
|
13
|
+
test "passenger" do
|
14
|
+
assert @transition_info.passenger == @passenger
|
15
|
+
end
|
16
|
+
|
17
|
+
test "old_state" do
|
18
|
+
assert @transition_info.old_state == @route.initial_state
|
19
|
+
end
|
20
|
+
|
21
|
+
test "new_state" do
|
22
|
+
assert @transition_info.new_state == @station.passed
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class UniqueTypeArrayTest < MicroTest::Test
|
4
|
+
|
5
|
+
before do
|
6
|
+
@list = Ellington::UniqueTypeArray.new
|
7
|
+
end
|
8
|
+
|
9
|
+
test "accepts values of different types" do
|
10
|
+
@list.push 1
|
11
|
+
@list.push 1.0
|
12
|
+
@list.push true
|
13
|
+
@list.push "hi"
|
14
|
+
@list.push :foo
|
15
|
+
end
|
16
|
+
|
17
|
+
test "can only push 1 entry with the same type" do
|
18
|
+
@list.push 1
|
19
|
+
begin
|
20
|
+
@list.push 2
|
21
|
+
rescue Ellington::ListAlreadyContainsType => e
|
22
|
+
end
|
23
|
+
assert !e.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
test "contains_a?" do
|
27
|
+
@list.push :foo
|
28
|
+
assert @list.contains_a?(Symbol)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|