cw 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +3 -0
- data/.travis.yml +3 -2
- data/README.md +6 -8
- data/Rakefile +5 -0
- data/classes.svg +145 -0
- data/classes.svg.dot +360 -0
- data/cw.gemspec +10 -9
- data/lib/cw.rb +6 -2
- data/lib/cw/audio_player.rb +2 -0
- data/lib/cw/book.rb +0 -27
- data/lib/cw/book_details.rb +27 -5
- data/lib/cw/current_word.rb +37 -0
- data/lib/cw/cw_dsl.rb +8 -7
- data/lib/cw/cw_params.rb +21 -0
- data/lib/cw/cw_stream.rb +3 -69
- data/lib/cw/element.rb +73 -0
- data/lib/cw/key_input.rb +1 -1
- data/lib/cw/repeat_word.rb +1 -0
- data/lib/cw/rss.rb +5 -15
- data/lib/cw/str.rb +9 -35
- data/lib/cw/tester.rb +33 -8
- data/lib/cw/text_helpers.rb +25 -0
- data/lib/cw/tone_generator.rb +1 -26
- data/lib/cw/tone_helpers.rb +33 -0
- data/lib/cw/words.rb +2 -54
- data/test/test_cw.rb +18 -11
- data/test/test_stream.rb +157 -151
- metadata +57 -52
- data/test/run_tests_continuously.rb +0 -4
data/lib/cw/rss.rb
CHANGED
@@ -4,11 +4,13 @@
|
|
4
4
|
|
5
5
|
class Rss
|
6
6
|
|
7
|
+
include TextHelpers
|
8
|
+
|
7
9
|
def sources
|
8
10
|
{
|
9
|
-
bbc:
|
10
|
-
reuters:
|
11
|
-
guardian:
|
11
|
+
bbc: 'http://feeds.bbci.co.uk/news/rss.xml',
|
12
|
+
reuters: 'http://feeds.reuters.com/Reuters/worldNews?format=xml',
|
13
|
+
guardian: 'http://www.theguardian.com/world/rss',
|
12
14
|
quotation: 'http://feeds.feedburner.com/quotationspage/qotd'
|
13
15
|
}
|
14
16
|
end
|
@@ -49,18 +51,6 @@ class Rss
|
|
49
51
|
@article_index || @article_index = 0
|
50
52
|
end
|
51
53
|
|
52
|
-
def cw_chars chr
|
53
|
-
chr.tr('^a-z0-9\.\,+', '')
|
54
|
-
end
|
55
|
-
|
56
|
-
def exclude_non_cw_chars word
|
57
|
-
temp = ''
|
58
|
-
word.split.each do |chr|
|
59
|
-
temp += chr if letter(chr)
|
60
|
-
end
|
61
|
-
temp
|
62
|
-
end
|
63
|
-
|
64
54
|
def next_article
|
65
55
|
temp = @rss_articles[article_index]
|
66
56
|
return unless temp
|
data/lib/cw/str.rb
CHANGED
@@ -4,19 +4,21 @@
|
|
4
4
|
|
5
5
|
class Str
|
6
6
|
|
7
|
+
include TextHelpers
|
8
|
+
|
7
9
|
def initialize
|
8
10
|
@seperator = ', '
|
9
11
|
end
|
10
12
|
|
11
13
|
def to_s
|
12
|
-
delim =
|
14
|
+
delim = Params.delim_str
|
13
15
|
[
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
shuffle_str,
|
18
|
-
word_count_str,
|
19
|
-
word_size_str,
|
16
|
+
Params.name + "\n",
|
17
|
+
delim,
|
18
|
+
Params.wpm_str,
|
19
|
+
Params.shuffle_str,
|
20
|
+
Params.word_count_str,
|
21
|
+
Params.word_size_str,
|
20
22
|
beginning_str,
|
21
23
|
ending_str,
|
22
24
|
delim
|
@@ -27,30 +29,6 @@ class Str
|
|
27
29
|
ary.join(@seperator)
|
28
30
|
end
|
29
31
|
|
30
|
-
def delim_str size
|
31
|
-
"#{'=' * size}\n"
|
32
|
-
end
|
33
|
-
|
34
|
-
def delim_std_str
|
35
|
-
tempsize = Params.name.size
|
36
|
-
delim_str tempsize
|
37
|
-
end
|
38
|
-
|
39
|
-
def shuffle_str
|
40
|
-
shuffle = Params.shuffle
|
41
|
-
shuffle ? "Shuffle: #{shuffle ? 'yes' : 'no'}\n" : nil
|
42
|
-
end
|
43
|
-
|
44
|
-
def word_count_str
|
45
|
-
wc = Params.word_count
|
46
|
-
wc ? "Word count: #{wc}\n" : nil
|
47
|
-
end
|
48
|
-
|
49
|
-
def word_size_str
|
50
|
-
size = Params.size
|
51
|
-
size ? "Word size: #{size}\n" : nil
|
52
|
-
end
|
53
|
-
|
54
32
|
def beginning_str
|
55
33
|
beginning = Params.begin
|
56
34
|
beginning ? "Beginning: #{stringify beginning}\n" : nil
|
@@ -61,8 +39,4 @@ class Str
|
|
61
39
|
ending ? "Ending: #{stringify ending}\n" : nil
|
62
40
|
end
|
63
41
|
|
64
|
-
def wpm_str
|
65
|
-
"WPM: #{Params.wpm}\n"
|
66
|
-
end
|
67
|
-
|
68
42
|
end
|
data/lib/cw/tester.rb
CHANGED
@@ -51,22 +51,47 @@ module Tester
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
def do_events
|
55
|
+
sleep 0.005
|
56
|
+
end
|
57
|
+
|
58
|
+
def process_letters letr
|
59
|
+
loop do
|
60
|
+
do_events
|
61
|
+
if self.class == Book
|
62
|
+
process_space_maybe(letr) unless @book_details.args[:output] == :letter
|
63
|
+
process_word_maybe
|
64
|
+
break if change_repeat_or_quit?
|
65
|
+
break if timing.char_delay_timeout?
|
66
|
+
else
|
61
67
|
process_space_maybe(letr) if(self.class == TestWords)
|
62
68
|
process_word_maybe
|
63
69
|
break if timing.char_delay_timeout?
|
64
70
|
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def process_words words
|
75
|
+
book_class = (self.class == Book)
|
76
|
+
(words.to_s + space).each_char do |letr|
|
77
|
+
process_letter letr
|
78
|
+
if book_class
|
79
|
+
stream.add_char(letr) if @book_details.args[:output] == :letter
|
80
|
+
else
|
81
|
+
stream.add_char(letr) if(self.class == TestLetters)
|
82
|
+
end
|
83
|
+
process_letters letr
|
65
84
|
print.prn letr if print_letters?
|
66
|
-
break if
|
85
|
+
break if(book_class && change_repeat_or_quit?)
|
86
|
+
break if ((! book_class) && quit?)
|
67
87
|
end
|
68
88
|
end
|
69
89
|
|
90
|
+
def print_words words
|
91
|
+
timing.init_char_timer
|
92
|
+
process_words words
|
93
|
+
end
|
94
|
+
|
70
95
|
def process_word_maybe
|
71
96
|
print_marked_maybe
|
72
97
|
process_input_word_maybe
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module TextHelpers
|
4
|
+
|
5
|
+
def letter_group
|
6
|
+
(97..122).to_a
|
7
|
+
end
|
8
|
+
|
9
|
+
def number_group
|
10
|
+
(48..57).to_a
|
11
|
+
end
|
12
|
+
|
13
|
+
def cw_chars chr
|
14
|
+
chr.tr('^a-z0-9\.\,+', '')
|
15
|
+
end
|
16
|
+
|
17
|
+
def exclude_non_cw_chars word
|
18
|
+
temp = ''
|
19
|
+
word.split.each do |chr|
|
20
|
+
temp += chr if letter(chr)
|
21
|
+
end
|
22
|
+
temp
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/cw/tone_generator.rb
CHANGED
@@ -4,12 +4,7 @@ require 'wavefile'
|
|
4
4
|
|
5
5
|
class ToneGenerator
|
6
6
|
|
7
|
-
|
8
|
-
DOT_FILENAME = HERE + "audio/dot.wav"
|
9
|
-
DASH_FILENAME = HERE + "audio/dash.wav"
|
10
|
-
SPACE_FILENAME = HERE + "audio/space.wav"
|
11
|
-
E_SPACE_FILENAME = HERE + "audio/e_space.wav"
|
12
|
-
TWO_PI = 2 * Math::PI
|
7
|
+
include ToneHelpers
|
13
8
|
|
14
9
|
def initialize
|
15
10
|
@max_amplitude = 0.5
|
@@ -24,10 +19,6 @@ class ToneGenerator
|
|
24
19
|
@encoding ||= CwEncoding.new
|
25
20
|
end
|
26
21
|
|
27
|
-
def convert_words wrds
|
28
|
-
wrds.to_array.collect{ |wrd| wrd.delete("\n")}
|
29
|
-
end
|
30
|
-
|
31
22
|
def progress
|
32
23
|
@progress ||= Progress.new('Compiling')
|
33
24
|
end
|
@@ -40,10 +31,6 @@ class ToneGenerator
|
|
40
31
|
write_word_parts
|
41
32
|
end
|
42
33
|
|
43
|
-
def play_filename
|
44
|
-
HERE + "audio/#{Params.audio_filename}"
|
45
|
-
end
|
46
|
-
|
47
34
|
def play
|
48
35
|
cmd = play_command + ' ' + play_filename
|
49
36
|
@pid = ! @dry_run ? Process.spawn(cmd) : cmd
|
@@ -63,10 +50,6 @@ class ToneGenerator
|
|
63
50
|
:spb => (@sample_rate * 1.2 / @effective_wpm).to_i }}
|
64
51
|
end
|
65
52
|
|
66
|
-
def generate_space number_of_samples
|
67
|
-
[].fill(0.0, 0, number_of_samples)
|
68
|
-
end
|
69
|
-
|
70
53
|
def filter_maybe(size, count)
|
71
54
|
ramp = 0.05
|
72
55
|
ramp_point = @max_amplitude / ramp
|
@@ -110,10 +93,6 @@ class ToneGenerator
|
|
110
93
|
end
|
111
94
|
end
|
112
95
|
|
113
|
-
def space_sample? ele
|
114
|
-
ele == :space || ele == :e_space
|
115
|
-
end
|
116
|
-
|
117
96
|
def generate_samples ele
|
118
97
|
return generate_space(data[ele][:spb]) if space_sample? ele
|
119
98
|
generate_tone(data[ele][:spb]) unless space_sample? ele
|
@@ -132,10 +111,6 @@ class ToneGenerator
|
|
132
111
|
(@effective_wpm == @wpm) ? space : e_space
|
133
112
|
end
|
134
113
|
|
135
|
-
def last_element? idx, chr
|
136
|
-
idx == chr.size - 1
|
137
|
-
end
|
138
|
-
|
139
114
|
def push_enc chr
|
140
115
|
arry = []
|
141
116
|
chr.each_with_index do |c,idx|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Module ToneHelpers provides helper methods for ToneGenerator
|
2
|
+
|
3
|
+
module ToneHelpers
|
4
|
+
|
5
|
+
TWO_PI = 2 * Math::PI
|
6
|
+
HERE = File.dirname(__FILE__) + '/../../'
|
7
|
+
DOT_FILENAME = HERE + "audio/dot.wav"
|
8
|
+
DASH_FILENAME = HERE + "audio/dash.wav"
|
9
|
+
SPACE_FILENAME = HERE + "audio/space.wav"
|
10
|
+
E_SPACE_FILENAME = HERE + "audio/e_space.wav"
|
11
|
+
|
12
|
+
# :reek: exclude from UtilityFunction
|
13
|
+
def play_filename
|
14
|
+
HERE + "audio/#{Params.audio_filename}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def convert_words wrds
|
18
|
+
wrds.to_array.collect{ |wrd| wrd.delete("\n")}
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_space number_of_samples
|
22
|
+
[].fill(0.0, 0, number_of_samples)
|
23
|
+
end
|
24
|
+
|
25
|
+
def space_sample? ele
|
26
|
+
ele == :space || ele == :e_space
|
27
|
+
end
|
28
|
+
|
29
|
+
def last_element? idx, chr
|
30
|
+
idx == chr.size - 1
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/cw/words.rb
CHANGED
@@ -1,55 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
class CurrentWord
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@current_word = ''
|
7
|
-
end
|
8
|
-
|
9
|
-
def current_word
|
10
|
-
@current_word ||= String.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def push_letter letr
|
14
|
-
@current_word += letr
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_s
|
18
|
-
@current_word
|
19
|
-
end
|
20
|
-
|
21
|
-
def clear
|
22
|
-
@current_word.clear
|
23
|
-
@current_word = ''
|
24
|
-
end
|
25
|
-
|
26
|
-
def strip
|
27
|
-
@current_word.strip!
|
28
|
-
end
|
29
|
-
|
30
|
-
def process_letter letr
|
31
|
-
letr.downcase!
|
32
|
-
push_letter letr
|
33
|
-
end
|
34
|
-
|
35
|
-
def cw_chars chr
|
36
|
-
chr.tr('^a-z0-9\.\,+', '')
|
37
|
-
end
|
38
|
-
|
39
|
-
def exclude_non_cw_chars word
|
40
|
-
temp = ''
|
41
|
-
word.split.each do |chr|
|
42
|
-
temp += chr if letter(chr)
|
43
|
-
end
|
44
|
-
temp
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
3
|
#class Words deals with words
|
50
4
|
|
51
5
|
class Words
|
52
6
|
|
7
|
+
include TextHelpers
|
8
|
+
|
53
9
|
def load(filename)
|
54
10
|
File.open(filename, 'r') do |file|
|
55
11
|
@words = file.read.split
|
@@ -144,14 +100,6 @@ class Words
|
|
144
100
|
@words.reverse!
|
145
101
|
end
|
146
102
|
|
147
|
-
def letter_group
|
148
|
-
(97..122).to_a
|
149
|
-
end
|
150
|
-
|
151
|
-
def number_group
|
152
|
-
(48..57).to_a
|
153
|
-
end
|
154
|
-
|
155
103
|
def letters_numbers
|
156
104
|
letter_group.push( * number_group)
|
157
105
|
end
|
data/test/test_cw.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'simplecov'
|
2
|
+
$VERBOSE = nil #FIXME
|
2
3
|
SimpleCov.start
|
3
4
|
|
4
5
|
require 'minitest/autorun'
|
@@ -10,10 +11,8 @@ class TestCW < MiniTest::Test
|
|
10
11
|
ROOT = File.expand_path File.dirname(__FILE__) + '/../'
|
11
12
|
|
12
13
|
def setup
|
13
|
-
@cw = CW.new
|
14
|
-
|
15
|
-
pause
|
16
|
-
end
|
14
|
+
@cw = CW.new
|
15
|
+
@cw.pause
|
17
16
|
end
|
18
17
|
|
19
18
|
def teardown
|
@@ -287,7 +286,9 @@ Ending: x
|
|
287
286
|
|
288
287
|
def test_random_letters_returns_random_letters
|
289
288
|
@cw.random_letters
|
290
|
-
@cw.words.each { |w|
|
289
|
+
@cw.words.each { |w|
|
290
|
+
assert_match(/^(?=.*\D)[-\w]+$/, w)
|
291
|
+
}
|
291
292
|
end
|
292
293
|
|
293
294
|
def test_random_numbers_can_take_size_and_count_option
|
@@ -298,24 +299,30 @@ Ending: x
|
|
298
299
|
|
299
300
|
def test_random_numbers_returns_random_numbers
|
300
301
|
@cw.random_numbers
|
301
|
-
@cw.words.each { |w|
|
302
|
+
@cw.words.each { |w|
|
303
|
+
assert_match(/\A[-+]?\d+\z/ , w)
|
304
|
+
}
|
302
305
|
end
|
303
306
|
|
304
307
|
def test_random_letters_numbers_can_take_size_and_count_option
|
305
308
|
@cw.random_letters_numbers(count: 3, size: 4)
|
306
309
|
assert_equal 3, @cw.words.size
|
307
|
-
@cw.words.each { |w|
|
310
|
+
@cw.words.each { |w|
|
311
|
+
assert_equal 4, w.length
|
312
|
+
}
|
308
313
|
end
|
309
314
|
|
310
315
|
def test_random_letters_numbers_includes_letter
|
311
316
|
@cw.random_letters_numbers
|
312
|
-
@cw.words.each { |w|
|
317
|
+
@cw.words.each { |w|
|
318
|
+
assert_match( /[a-zA-Z]+/, w)
|
319
|
+
}
|
313
320
|
end
|
314
321
|
|
315
322
|
def test_random_letters_numbers_includes_number
|
316
323
|
@cw.random_letters_numbers
|
317
324
|
@cw.words.each do |w|
|
318
|
-
assert_match
|
325
|
+
assert_match(/[0-9]+/, w)
|
319
326
|
end
|
320
327
|
end
|
321
328
|
|
@@ -341,7 +348,7 @@ Ending: x
|
|
341
348
|
assert_equal 'tsal neht tsrif', @cw.words
|
342
349
|
end
|
343
350
|
|
344
|
-
#
|
351
|
+
#FIXME
|
345
352
|
# def test_convert_generates_correct_command_for_default
|
346
353
|
# @cw.dry_run = true
|
347
354
|
# @cw.words = "some words"
|
@@ -388,7 +395,7 @@ Ending: x
|
|
388
395
|
assert @cw.method(:words_no_shorter_than), @cw.method(:no_shorter_than)
|
389
396
|
assert @cw.method(:random_alphanumeric), @cw.method(:random_letters_numbers)
|
390
397
|
assert @cw.method(:comment), @cw.method(:name)
|
391
|
-
assert @cw.method(:no_run), @cw.method(:pause)
|
398
|
+
assert @cw.method(:no_run), @cw.method(:pause)
|
392
399
|
end
|
393
400
|
|
394
401
|
def test_set_wpm_param
|
data/test/test_stream.rb
CHANGED
@@ -3,7 +3,8 @@ SimpleCov.start
|
|
3
3
|
|
4
4
|
require 'minitest/autorun'
|
5
5
|
require 'minitest/pride'
|
6
|
-
require_relative '../lib/cw/
|
6
|
+
require_relative '../lib/cw/element'
|
7
|
+
require_relative '../lib/cw/cw_stream'
|
7
8
|
|
8
9
|
# class TestStreamMatching < MiniTest::Test
|
9
10
|
# def setup
|
@@ -145,35 +146,39 @@ class TestCwStream < MiniTest::Test
|
|
145
146
|
@stream = CwStream.new
|
146
147
|
end
|
147
148
|
|
149
|
+
def teardown
|
150
|
+
@stream = nil
|
151
|
+
end
|
152
|
+
|
148
153
|
def test_assert
|
149
154
|
assert true
|
150
155
|
end
|
151
156
|
|
152
|
-
def
|
153
|
-
@stream.
|
157
|
+
def test_add_word_adds_to_the_stream
|
158
|
+
@stream.add_word 'a'
|
154
159
|
assert_equal({0 => 'a'}, @stream.stream)
|
155
|
-
@stream.
|
160
|
+
@stream.add_word 'tree'
|
156
161
|
assert_equal({0 => 'a', 1 => 'tree'}, @stream.stream)
|
157
162
|
end
|
158
163
|
|
159
164
|
def test_count
|
160
|
-
@stream.
|
165
|
+
@stream.add_word 'a'
|
161
166
|
assert_equal 1, @stream.count
|
162
|
-
@stream.
|
167
|
+
@stream.add_word 'tree'
|
163
168
|
assert_equal 2, @stream.count
|
164
169
|
assert_equal({0 => 'a', 1 => 'tree'}, @stream.stream)
|
165
170
|
end
|
166
171
|
|
167
172
|
def test_stream_element_can_be_marked_a_success
|
168
|
-
@stream.
|
173
|
+
@stream.add_word 'a'
|
169
174
|
@stream.mark_success(0)
|
170
175
|
assert_equal({0 => true}, @stream.instance_variable_get(:@success))
|
171
176
|
end
|
172
177
|
|
173
178
|
def test_stream_element_can_be_marked_a_fail
|
174
|
-
@stream.
|
179
|
+
@stream.add_word 'a'
|
175
180
|
@stream.mark_success(0)
|
176
|
-
@stream.
|
181
|
+
@stream.add_word 'b'
|
177
182
|
@stream.mark_fail(1)
|
178
183
|
assert_equal({0 => true, 1 => false}, @stream.instance_variable_get(:@success))
|
179
184
|
end
|
@@ -184,24 +189,24 @@ class TestCwStream < MiniTest::Test
|
|
184
189
|
end
|
185
190
|
|
186
191
|
def test_mark_inactive_region_fail_fails_unmarked_inactive_elements
|
187
|
-
@stream.
|
188
|
-
@stream.
|
189
|
-
@stream.
|
190
|
-
@stream.
|
192
|
+
@stream.add_word 'a'
|
193
|
+
@stream.add_word 'b'
|
194
|
+
@stream.add_word 'c'
|
195
|
+
@stream.add_word 'd'
|
191
196
|
@stream.active_region = 2
|
192
197
|
@stream.fail_unmarked_inactive_elements
|
193
198
|
assert_equal({0 => false, 1 => false, 2 => nil, 3 => nil}, @stream.instance_variable_get(:@success))
|
194
199
|
end
|
195
200
|
|
196
201
|
def test_mark_inactive_region_fail_doesnt_fail_successes
|
197
|
-
@stream.
|
198
|
-
@stream.
|
199
|
-
@stream.
|
200
|
-
@stream.
|
202
|
+
@stream.add_word 'a'
|
203
|
+
@stream.add_word 'b'
|
204
|
+
@stream.add_word 'c'
|
205
|
+
@stream.add_word 'd'
|
201
206
|
@stream.instance_variable_set(:@success, {0 => true, 1 => false})
|
202
207
|
@stream.active_region = 2
|
203
208
|
@stream.fail_unmarked_inactive_elements
|
204
|
-
|
209
|
+
assert_equal({0 => true, 1 => false}, @stream.instance_variable_get(:@success))
|
205
210
|
end
|
206
211
|
|
207
212
|
def test_mark_inactive_region_fail_doesnt_fail_when_no_stream
|
@@ -210,147 +215,148 @@ class TestCwStream < MiniTest::Test
|
|
210
215
|
end
|
211
216
|
|
212
217
|
def test_first_returns_first_element_in_stream
|
213
|
-
@stream.
|
214
|
-
@stream.
|
215
|
-
@stream.
|
216
|
-
@stream.
|
218
|
+
@stream.add_word 'a'
|
219
|
+
@stream.add_word 'b'
|
220
|
+
@stream.add_word 'c'
|
221
|
+
@stream.add_word 'd'
|
217
222
|
assert_equal 'a', @stream.first
|
218
223
|
end
|
219
224
|
|
220
225
|
def test_pop_returns_first_element_in_stream_and_removes_element
|
221
|
-
@stream.
|
222
|
-
@stream.
|
223
|
-
@stream.
|
224
|
-
@stream.
|
225
|
-
assert_equal({'a' => false}, @stream.pop)
|
226
|
-
|
226
|
+
@stream.add_word 'a'
|
227
|
+
@stream.add_word 'b'
|
228
|
+
@stream.add_word 'c'
|
229
|
+
@stream.add_word 'd'
|
230
|
+
assert_equal({:value => 'a', :success => false}, @stream.pop)
|
231
|
+
refute(@stream.pop[:success])
|
232
|
+
assert_equal({2 => 'c', 3 => 'd'}, @stream.stream)
|
227
233
|
|
228
234
|
@stream.empty
|
229
|
-
@stream.
|
230
|
-
|
231
|
-
@stream.
|
232
|
-
|
233
|
-
@stream.
|
234
|
-
|
235
|
-
@stream.
|
236
|
-
|
235
|
+
@stream.add_word 'a'
|
236
|
+
refute(@stream.pop[:success])
|
237
|
+
@stream.add_word 'b'
|
238
|
+
refute(@stream.pop[:success])
|
239
|
+
@stream.add_word 'c'
|
240
|
+
refute(@stream.pop[:success])
|
241
|
+
@stream.add_word 'd'
|
242
|
+
refute(@stream.pop[:success])
|
237
243
|
assert_nil @stream.pop
|
238
244
|
assert_equal({}, @stream.stream)
|
239
245
|
end
|
240
246
|
|
241
247
|
def test_match_last_active_element_marks_correct_element
|
242
|
-
@stream.
|
243
|
-
@stream.
|
244
|
-
@stream.
|
245
|
-
@stream.
|
248
|
+
@stream.add_word 'a'
|
249
|
+
@stream.add_word 'b'
|
250
|
+
@stream.add_word 'c'
|
251
|
+
@stream.add_word 'd'
|
246
252
|
@stream.match_last_active_element('c')
|
247
253
|
assert_equal({0 => false, 1 => false, 2 => true, 3 => nil}, @stream.instance_variable_get(:@success))
|
248
|
-
|
254
|
+
end
|
249
255
|
|
250
256
|
def test_match_last_active_element_doesnt_unmark_correct_element
|
251
257
|
@stream.active_region = 2
|
252
|
-
@stream.
|
253
|
-
@stream.
|
254
|
-
@stream.
|
255
|
-
@stream.
|
258
|
+
@stream.add_word 'a'
|
259
|
+
@stream.add_word 'b'
|
260
|
+
@stream.add_word 'c'
|
261
|
+
@stream.add_word 'd'
|
256
262
|
@stream.match_last_active_element('c')
|
257
263
|
@stream.match_last_active_element('d')
|
258
|
-
assert_equal({0 => nil, 1 =>
|
259
|
-
|
264
|
+
assert_equal({0 => nil, 1 => false, 2 => true, 3 => true}, @stream.instance_variable_get(:@success))
|
265
|
+
end
|
260
266
|
|
261
267
|
def test_match_last_active_element_doesnt_unmark_failed_element
|
262
|
-
@stream.
|
263
|
-
@stream.
|
264
|
-
@stream.
|
265
|
-
@stream.
|
268
|
+
@stream.add_word 'a'
|
269
|
+
@stream.add_word 'b'
|
270
|
+
@stream.add_word 'c'
|
271
|
+
@stream.add_word 'd'
|
266
272
|
@stream.match_last_active_element('d')
|
267
273
|
@stream.match_last_active_element('c')
|
268
|
-
assert_equal({0 => false, 1 => false, 2 =>
|
274
|
+
assert_equal({0 => false, 1 => false, 2 => true, 3 => true}, @stream.instance_variable_get(:@success))
|
269
275
|
end
|
270
276
|
|
271
|
-
# def test_pop_marked_returns_nil_for_empty_stream
|
272
|
-
# assert_equal(nil, @stream.pop_marked)
|
273
|
-
# assert_equal(nil, @stream.pop_marked)
|
274
|
-
# end
|
275
|
-
#
|
276
|
-
# def test_pop_marked_returns_up_to_marked_first_element
|
277
|
-
# @stream.
|
278
|
-
# @stream.
|
279
|
-
# @stream.
|
280
|
-
# @stream.
|
281
|
-
# @stream.match_last_active_element('a')
|
282
|
-
# assert_equal({0 => {'a' => true}}, @stream.pop_marked)
|
283
|
-
# assert_equal(nil, @stream.pop_marked)
|
284
|
-
# end
|
285
|
-
#
|
286
|
-
# def test_pop_marked_returns_up_to_marked_second_element
|
287
|
-
# @stream.
|
288
|
-
# @stream.
|
289
|
-
# @stream.
|
290
|
-
# @stream.
|
291
|
-
# @stream.match_last_active_element('b')
|
292
|
-
# assert_equal({0 => {'a' => false}, 1 => {'b' => true}}, @stream.pop_marked)
|
293
|
-
# assert_equal(nil, @stream.pop_marked)
|
294
|
-
# end
|
295
|
-
#
|
296
|
-
# def test_pop_marked_returns_up_to_marked_first_and_third_element
|
297
|
-
# @stream.
|
298
|
-
# @stream.
|
299
|
-
# @stream.
|
300
|
-
# @stream.
|
301
|
-
# @stream.match_last_active_element('a')
|
302
|
-
# @stream.match_last_active_element('c')
|
303
|
-
# assert_equal({0 => {'a' => true}, 1 => {'b' => false}, 2 => {'c' => true}}, @stream.pop_marked)
|
304
|
-
# assert_equal(nil, @stream.pop_marked)
|
305
|
-
# @stream.match_last_active_element('d')
|
306
|
-
# assert_equal({3 => {'d' => true}}, @stream.pop_marked)
|
307
|
-
# end
|
308
|
-
#
|
309
|
-
# def test_pop_marked_returns_inactive_unmarked_elements
|
310
|
-
# @stream.
|
311
|
-
# @stream.
|
312
|
-
# @stream.
|
313
|
-
# @stream.
|
314
|
-
# @stream.active_region = 2
|
315
|
-
# assert_equal({0 => {'a' => false}, 1 => {'b' => false}}, @stream.pop_marked)
|
316
|
-
# assert_equal(nil, @stream.pop_marked)
|
317
|
-
# @stream.match_last_active_element('d')
|
318
|
-
# assert_equal({2 => {'c' => false}, 3 => {'d' => true}}, @stream.pop_marked)
|
319
|
-
# end
|
320
|
-
#
|
321
|
-
# def test_pop_marked_returns_mix_of_active_and_inactive
|
322
|
-
# @stream.active_region = 2
|
323
|
-
# @stream.
|
324
|
-
# @stream.
|
325
|
-
# @stream.
|
326
|
-
# @stream.
|
327
|
-
# @stream.match_last_active_element('d')
|
328
|
-
# assert_equal({0 => {'a' => false}, 1 => {'b' => false}, 2 => {'c' => false}, 3 => {'d' => true}}, @stream.pop_marked)
|
329
|
-
# assert_equal(nil, @stream.pop_marked)
|
330
|
-
# end
|
277
|
+
# def test_pop_marked_returns_nil_for_empty_stream
|
278
|
+
# assert_equal(nil, @stream.pop_marked)
|
279
|
+
# assert_equal(nil, @stream.pop_marked)
|
280
|
+
# end
|
281
|
+
#
|
282
|
+
# def test_pop_marked_returns_up_to_marked_first_element
|
283
|
+
# @stream.add_word 'a'
|
284
|
+
# @stream.add_word 'b'
|
285
|
+
# @stream.add_word 'c'
|
286
|
+
# @stream.add_word 'd'
|
287
|
+
# @stream.match_last_active_element('a')
|
288
|
+
# assert_equal({0 => {'a' => true}}, @stream.pop_marked)
|
289
|
+
# assert_equal(nil, @stream.pop_marked)
|
290
|
+
# end
|
291
|
+
#
|
292
|
+
# def test_pop_marked_returns_up_to_marked_second_element
|
293
|
+
# @stream.add_word 'a'
|
294
|
+
# @stream.add_word 'b'
|
295
|
+
# @stream.add_word 'c'
|
296
|
+
# @stream.add_word 'd'
|
297
|
+
# @stream.match_last_active_element('b')
|
298
|
+
# assert_equal({0 => {'a' => false}, 1 => {'b' => true}}, @stream.pop_marked)
|
299
|
+
# assert_equal(nil, @stream.pop_marked)
|
300
|
+
# end
|
301
|
+
#
|
302
|
+
# def test_pop_marked_returns_up_to_marked_first_and_third_element
|
303
|
+
# @stream.add_word 'a'
|
304
|
+
# @stream.add_word 'b'
|
305
|
+
# @stream.add_word 'c'
|
306
|
+
# @stream.add_word 'd'
|
307
|
+
# @stream.match_last_active_element('a')
|
308
|
+
# @stream.match_last_active_element('c')
|
309
|
+
# assert_equal({0 => {'a' => true}, 1 => {'b' => false}, 2 => {'c' => true}}, @stream.pop_marked)
|
310
|
+
# assert_equal(nil, @stream.pop_marked)
|
311
|
+
# @stream.match_last_active_element('d')
|
312
|
+
# assert_equal({3 => {'d' => true}}, @stream.pop_marked)
|
313
|
+
# end
|
314
|
+
#
|
315
|
+
# def test_pop_marked_returns_inactive_unmarked_elements
|
316
|
+
# @stream.add_word 'a'
|
317
|
+
# @stream.add_word 'b'
|
318
|
+
# @stream.add_word 'c'
|
319
|
+
# @stream.add_word 'd'
|
320
|
+
# @stream.active_region = 2
|
321
|
+
# assert_equal({0 => {'a' => false}, 1 => {'b' => false}}, @stream.pop_marked)
|
322
|
+
# assert_equal(nil, @stream.pop_marked)
|
323
|
+
# @stream.match_last_active_element('d')
|
324
|
+
# assert_equal({2 => {'c' => false}, 3 => {'d' => true}}, @stream.pop_marked)
|
325
|
+
# end
|
326
|
+
#
|
327
|
+
# def test_pop_marked_returns_mix_of_active_and_inactive
|
328
|
+
# @stream.active_region = 2
|
329
|
+
# @stream.add_word 'a'
|
330
|
+
# @stream.add_word 'b'
|
331
|
+
# @stream.add_word 'c'
|
332
|
+
# @stream.add_word 'd'
|
333
|
+
# @stream.match_last_active_element('d')
|
334
|
+
# assert_equal({0 => {'a' => false}, 1 => {'b' => false}, 2 => {'c' => false}, 3 => {'d' => true}}, @stream.pop_marked)
|
335
|
+
# assert_equal(nil, @stream.pop_marked)
|
336
|
+
# end
|
331
337
|
|
332
338
|
def test_pop_next_marked_returns_correct_elements_where_last_only_matched
|
333
|
-
@stream.
|
334
|
-
@stream.
|
335
|
-
@stream.
|
336
|
-
@stream.
|
339
|
+
@stream.add_word 'a'
|
340
|
+
@stream.add_word 'b'
|
341
|
+
@stream.add_word 'c'
|
342
|
+
@stream.add_word 'd'
|
337
343
|
@stream.match_last_active_element('d')
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
344
|
+
refute(@stream.pop_next_marked[:success])
|
345
|
+
refute(@stream.pop_next_marked[:success])
|
346
|
+
refute(@stream.pop_next_marked[:success])
|
347
|
+
assert(@stream.pop_next_marked[:success])
|
342
348
|
assert_equal(nil, @stream.pop_next_marked)
|
343
349
|
end
|
344
350
|
|
345
351
|
def test_pop_next_marked_returns_correct_elements_where_penultimate_element_matched
|
346
|
-
@stream.
|
347
|
-
@stream.
|
348
|
-
@stream.
|
349
|
-
@stream.
|
352
|
+
@stream.add_word 'a'
|
353
|
+
@stream.add_word 'b'
|
354
|
+
@stream.add_word 'c'
|
355
|
+
@stream.add_word 'd'
|
350
356
|
@stream.match_last_active_element('c')
|
351
|
-
assert_equal({'a' => false}, @stream.pop_next_marked)
|
352
|
-
assert_equal({'b' => false}, @stream.pop_next_marked)
|
353
|
-
assert_equal({'c' => true}, @stream.pop_next_marked)
|
357
|
+
assert_equal({:value => 'a', :success => false}, @stream.pop_next_marked)
|
358
|
+
assert_equal({:value => 'b', :success => false}, @stream.pop_next_marked)
|
359
|
+
assert_equal({:value => 'c', :success => true}, @stream.pop_next_marked)
|
354
360
|
assert_equal(nil, @stream.pop_next_marked)
|
355
361
|
assert_equal(nil, @stream.pop_next_marked)
|
356
362
|
end
|
@@ -358,43 +364,43 @@ class TestCwStream < MiniTest::Test
|
|
358
364
|
def test_pop_next_marked_considers_active_region
|
359
365
|
|
360
366
|
@stream.active_region = 2
|
361
|
-
@stream.
|
362
|
-
@stream.
|
363
|
-
@stream.
|
364
|
-
@stream.
|
365
|
-
assert_equal({'a' => false}, @stream.pop_next_marked)
|
366
|
-
assert_equal({'b' => false}, @stream.pop_next_marked)
|
367
|
+
@stream.add_word 'a'
|
368
|
+
@stream.add_word 'b'
|
369
|
+
@stream.add_word 'c'
|
370
|
+
@stream.add_word 'd'
|
371
|
+
assert_equal({:value => 'a', :success => false}, @stream.pop_next_marked)
|
372
|
+
assert_equal({:value => 'b', :success => false}, @stream.pop_next_marked)
|
367
373
|
assert_equal(nil, @stream.pop_next_marked)
|
368
374
|
assert_equal(nil, @stream.pop_next_marked)
|
369
375
|
|
370
376
|
@stream.empty
|
371
377
|
@stream.active_region = 1
|
372
|
-
@stream.
|
373
|
-
@stream.
|
374
|
-
@stream.
|
375
|
-
@stream.
|
376
|
-
assert_equal({'a' => false}, @stream.pop_next_marked)
|
377
|
-
assert_equal({'b' => false}, @stream.pop_next_marked)
|
378
|
-
assert_equal({'c' => false}, @stream.pop_next_marked)
|
378
|
+
@stream.add_word 'a'
|
379
|
+
@stream.add_word 'b'
|
380
|
+
@stream.add_word 'c'
|
381
|
+
@stream.add_word 'd'
|
382
|
+
assert_equal({:value => 'a', :success => false}, @stream.pop_next_marked)
|
383
|
+
assert_equal({:value => 'b', :success => false}, @stream.pop_next_marked)
|
384
|
+
assert_equal({:value => 'c', :success => false}, @stream.pop_next_marked)
|
379
385
|
assert_equal(nil, @stream.pop_next_marked)
|
380
386
|
|
381
387
|
|
382
388
|
@stream.empty
|
383
389
|
@stream.active_region = 2
|
384
|
-
@stream.
|
385
|
-
@stream.
|
386
|
-
@stream.
|
387
|
-
@stream.
|
390
|
+
@stream.add_word 'a'
|
391
|
+
@stream.add_word 'b'
|
392
|
+
@stream.add_word 'c'
|
393
|
+
@stream.add_word 'd'
|
388
394
|
@stream.match_last_active_element('c')
|
389
|
-
assert_equal({'a' => false}, @stream.pop_next_marked)
|
390
|
-
assert_equal({'b' => false}, @stream.pop_next_marked)
|
391
|
-
assert_equal({'c' => true}, @stream.pop_next_marked)
|
395
|
+
assert_equal({:value => 'a', :success => false}, @stream.pop_next_marked)
|
396
|
+
assert_equal({:value => 'b', :success => false}, @stream.pop_next_marked)
|
397
|
+
assert_equal({:value => 'c', :success => true}, @stream.pop_next_marked)
|
392
398
|
assert_equal(nil, @stream.pop_next_marked)
|
393
|
-
@stream.
|
394
|
-
@stream.
|
399
|
+
@stream.add_word 'e'
|
400
|
+
@stream.add_word 'f'
|
395
401
|
@stream.match_last_active_element('e')
|
396
|
-
assert_equal({'d' => false}, @stream.pop_next_marked)
|
397
|
-
assert_equal({'e' => true}, @stream.pop_next_marked)
|
402
|
+
assert_equal({:value => 'd', :success => false}, @stream.pop_next_marked)
|
403
|
+
assert_equal({:value => 'e', :success => true}, @stream.pop_next_marked)
|
398
404
|
assert_equal(nil, @stream.pop_next_marked)
|
399
405
|
assert_equal({5 => 'f'}, @stream.stream)
|
400
406
|
end
|