cw 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cw_config +18 -0
- data/.gitignore +10 -1
- data/LICENSE +2 -1
- data/README.md +212 -96
- data/Rakefile +15 -2
- data/VERSION +1 -1
- data/Vagrantfile +45 -0
- data/cw.gemspec +6 -1
- data/data/text/book_to_read.txt +4 -0
- data/data/text/english.txt +10000 -0
- data/example.rb +172 -106
- data/lib/cw.rb +10 -126
- data/lib/cw/alphabet.rb +53 -46
- data/lib/cw/audio_player.rb +83 -72
- data/lib/cw/book.rb +160 -185
- data/lib/cw/book_details.rb +38 -49
- data/lib/cw/cl.rb +101 -95
- data/lib/cw/common_words.rb +76 -0
- data/lib/cw/config.rb +50 -0
- data/lib/cw/current_word.rb +23 -24
- data/lib/cw/cw_dsl.rb +264 -131
- data/lib/cw/cw_encoding.rb +63 -69
- data/lib/cw/cw_stream.rb +86 -82
- data/lib/cw/cw_threads.rb +132 -22
- data/lib/cw/element.rb +60 -54
- data/lib/cw/file_details.rb +26 -11
- data/lib/cw/key_input.rb +53 -35
- data/lib/cw/numbers.rb +26 -19
- data/lib/cw/os.rb +13 -0
- data/lib/cw/play.rb +92 -0
- data/lib/cw/print.rb +102 -100
- data/lib/cw/process.rb +3 -0
- data/lib/cw/progress.rb +20 -17
- data/lib/cw/randomize.rb +56 -52
- data/lib/cw/repeat_word.rb +59 -66
- data/lib/cw/reveal.rb +32 -31
- data/lib/cw/rss.rb +52 -48
- data/lib/cw/sentence.rb +83 -76
- data/lib/cw/speak.rb +8 -4
- data/lib/cw/spoken.rb +8 -4
- data/lib/cw/str.rb +62 -30
- data/lib/cw/test_letters.rb +20 -28
- data/lib/cw/test_words.rb +25 -31
- data/lib/cw/tester.rb +219 -226
- data/lib/cw/text_helpers.rb +19 -15
- data/lib/cw/timing.rb +63 -67
- data/lib/cw/tone_generator.rb +176 -153
- data/lib/cw/tone_helpers.rb +15 -23
- data/lib/cw/voice.rb +12 -8
- data/lib/cw/words.rb +136 -106
- data/run_script_tests.rb +165 -0
- data/test/my_words.txt +1 -0
- data/test/test_common_words.rb +71 -0
- data/test/test_config.rb +98 -0
- data/test/test_current_word.rb +62 -0
- data/test/test_cw.rb +87 -120
- data/test/test_cw_threads.rb +123 -0
- data/test/test_filtering.rb +439 -0
- data/test/test_params.rb +28 -0
- data/test/test_play.rb +51 -0
- data/test/test_stream.rb +83 -83
- data/test/test_tester.rb +9 -27
- data/test/test_timing.rb +212 -0
- metadata +94 -12
- data/lib/cw/config_file.rb +0 -69
- data/lib/cw/monitor_keys.rb +0 -37
- data/lib/cw/params.rb +0 -104
data/test/test_params.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
$VERBOSE = nil #FIXME
|
3
|
+
SimpleCov.start
|
4
|
+
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'minitest/pride'
|
7
|
+
|
8
|
+
require_relative '../lib/cw'
|
9
|
+
|
10
|
+
class TestStr < MiniTest::Test
|
11
|
+
|
12
|
+
ROOT = File.expand_path File.dirname(__FILE__) + '/../'
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@str = CWG::Str.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_stringify
|
19
|
+
assert_equal('a, b', @str.stringify(['a','b']))
|
20
|
+
end
|
21
|
+
|
22
|
+
# def test_beginning_str
|
23
|
+
# cw = CW.new {
|
24
|
+
# no_run
|
25
|
+
# assert_equal '', @str.beginning_str
|
26
|
+
# }
|
27
|
+
# end
|
28
|
+
end
|
data/test/test_play.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
$VERBOSE = nil #FIXME
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/pride'
|
5
|
+
require_relative '../lib/cw'
|
6
|
+
|
7
|
+
class TestPlay < MiniTest::Test
|
8
|
+
|
9
|
+
ROOT = File.expand_path File.dirname(__FILE__) + '/../'
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@p = CWG::Play.new('words')
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
@cw = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_play_object_takes_a_word_parameter
|
20
|
+
play = CWG::Play.new('words object')
|
21
|
+
assert_equal 'words object', play.instance_variable_get('@words')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_audio_instantiates_AudioPlayer_object
|
25
|
+
assert_equal CWG::AudioPlayer, @p.audio.class
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_init_play_words_timeout_sets_start_play_time
|
29
|
+
@p.init_play_words_timeout
|
30
|
+
assert((Time.now - @p.instance_variable_get('@start_play_time')) < 1)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_init_play_words_timeout_sets_delay_play_time
|
34
|
+
@p.init_play_words_timeout
|
35
|
+
assert_equal 2.0, @p.instance_variable_get('@delay_play_time')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_start_sync
|
39
|
+
refute @p.start_sync?
|
40
|
+
@p.start_sync
|
41
|
+
assert @p.start_sync?
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_add_space
|
45
|
+
words = CWG::Words.new
|
46
|
+
words.assign ['some','words']
|
47
|
+
|
48
|
+
assert_equal 'some words ', @p.add_space(words)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/test/test_stream.rb
CHANGED
@@ -143,7 +143,7 @@ require_relative '../lib/cw/cw_stream'
|
|
143
143
|
class TestCwStream < MiniTest::Test
|
144
144
|
|
145
145
|
def setup
|
146
|
-
@stream = CwStream.new
|
146
|
+
@stream = CWG::CwStream.new
|
147
147
|
end
|
148
148
|
|
149
149
|
def teardown
|
@@ -154,31 +154,31 @@ class TestCwStream < MiniTest::Test
|
|
154
154
|
assert true
|
155
155
|
end
|
156
156
|
|
157
|
-
def
|
158
|
-
@stream.
|
157
|
+
def test_push_adds_to_the_stream
|
158
|
+
@stream.push 'a'
|
159
159
|
assert_equal({0 => 'a'}, @stream.stream)
|
160
|
-
@stream.
|
160
|
+
@stream.push 'tree'
|
161
161
|
assert_equal({0 => 'a', 1 => 'tree'}, @stream.stream)
|
162
162
|
end
|
163
163
|
|
164
164
|
def test_count
|
165
|
-
@stream.
|
165
|
+
@stream.push 'a'
|
166
166
|
assert_equal 1, @stream.count
|
167
|
-
@stream.
|
167
|
+
@stream.push 'tree'
|
168
168
|
assert_equal 2, @stream.count
|
169
169
|
assert_equal({0 => 'a', 1 => 'tree'}, @stream.stream)
|
170
170
|
end
|
171
171
|
|
172
172
|
def test_stream_element_can_be_marked_a_success
|
173
|
-
@stream.
|
173
|
+
@stream.push 'a'
|
174
174
|
@stream.mark_success(0)
|
175
175
|
assert_equal({0 => true}, @stream.instance_variable_get(:@success))
|
176
176
|
end
|
177
177
|
|
178
178
|
def test_stream_element_can_be_marked_a_fail
|
179
|
-
@stream.
|
179
|
+
@stream.push 'a'
|
180
180
|
@stream.mark_success(0)
|
181
|
-
@stream.
|
181
|
+
@stream.push 'b'
|
182
182
|
@stream.mark_fail(1)
|
183
183
|
assert_equal({0 => true, 1 => false}, @stream.instance_variable_get(:@success))
|
184
184
|
end
|
@@ -189,20 +189,20 @@ class TestCwStream < MiniTest::Test
|
|
189
189
|
end
|
190
190
|
|
191
191
|
def test_mark_inactive_region_fail_fails_unmarked_inactive_elements
|
192
|
-
@stream.
|
193
|
-
@stream.
|
194
|
-
@stream.
|
195
|
-
@stream.
|
192
|
+
@stream.push 'a'
|
193
|
+
@stream.push 'b'
|
194
|
+
@stream.push 'c'
|
195
|
+
@stream.push 'd'
|
196
196
|
@stream.active_region = 2
|
197
197
|
@stream.fail_unmarked_inactive_elements
|
198
198
|
assert_equal({0 => false, 1 => false, 2 => nil, 3 => nil}, @stream.instance_variable_get(:@success))
|
199
199
|
end
|
200
200
|
|
201
201
|
def test_mark_inactive_region_fail_doesnt_fail_successes
|
202
|
-
@stream.
|
203
|
-
@stream.
|
204
|
-
@stream.
|
205
|
-
@stream.
|
202
|
+
@stream.push 'a'
|
203
|
+
@stream.push 'b'
|
204
|
+
@stream.push 'c'
|
205
|
+
@stream.push 'd'
|
206
206
|
@stream.instance_variable_set(:@success, {0 => true, 1 => false})
|
207
207
|
@stream.active_region = 2
|
208
208
|
@stream.fail_unmarked_inactive_elements
|
@@ -215,60 +215,60 @@ class TestCwStream < MiniTest::Test
|
|
215
215
|
end
|
216
216
|
|
217
217
|
def test_first_returns_first_element_in_stream
|
218
|
-
@stream.
|
219
|
-
@stream.
|
220
|
-
@stream.
|
221
|
-
@stream.
|
218
|
+
@stream.push 'a'
|
219
|
+
@stream.push 'b'
|
220
|
+
@stream.push 'c'
|
221
|
+
@stream.push 'd'
|
222
222
|
assert_equal 'a', @stream.first
|
223
223
|
end
|
224
224
|
|
225
225
|
def test_pop_returns_first_element_in_stream_and_removes_element
|
226
|
-
@stream.
|
227
|
-
@stream.
|
228
|
-
@stream.
|
229
|
-
@stream.
|
226
|
+
@stream.push 'a'
|
227
|
+
@stream.push 'b'
|
228
|
+
@stream.push 'c'
|
229
|
+
@stream.push 'd'
|
230
230
|
assert_equal({:value => 'a', :success => false}, @stream.pop)
|
231
231
|
refute(@stream.pop[:success])
|
232
232
|
assert_equal({2 => 'c', 3 => 'd'}, @stream.stream)
|
233
233
|
|
234
234
|
@stream.empty
|
235
|
-
@stream.
|
235
|
+
@stream.push 'a'
|
236
236
|
refute(@stream.pop[:success])
|
237
|
-
@stream.
|
237
|
+
@stream.push 'b'
|
238
238
|
refute(@stream.pop[:success])
|
239
|
-
@stream.
|
239
|
+
@stream.push 'c'
|
240
240
|
refute(@stream.pop[:success])
|
241
|
-
@stream.
|
241
|
+
@stream.push 'd'
|
242
242
|
refute(@stream.pop[:success])
|
243
243
|
assert_nil @stream.pop
|
244
244
|
assert_equal({}, @stream.stream)
|
245
245
|
end
|
246
246
|
|
247
247
|
def test_match_last_active_element_marks_correct_element
|
248
|
-
@stream.
|
249
|
-
@stream.
|
250
|
-
@stream.
|
251
|
-
@stream.
|
248
|
+
@stream.push 'a'
|
249
|
+
@stream.push 'b'
|
250
|
+
@stream.push 'c'
|
251
|
+
@stream.push 'd'
|
252
252
|
@stream.match_last_active_element('c')
|
253
253
|
assert_equal({0 => false, 1 => false, 2 => true, 3 => nil}, @stream.instance_variable_get(:@success))
|
254
254
|
end
|
255
255
|
|
256
256
|
def test_match_last_active_element_doesnt_unmark_correct_element
|
257
257
|
@stream.active_region = 2
|
258
|
-
@stream.
|
259
|
-
@stream.
|
260
|
-
@stream.
|
261
|
-
@stream.
|
258
|
+
@stream.push 'a'
|
259
|
+
@stream.push 'b'
|
260
|
+
@stream.push 'c'
|
261
|
+
@stream.push 'd'
|
262
262
|
@stream.match_last_active_element('c')
|
263
263
|
@stream.match_last_active_element('d')
|
264
264
|
assert_equal({0 => nil, 1 => false, 2 => true, 3 => true}, @stream.instance_variable_get(:@success))
|
265
265
|
end
|
266
266
|
|
267
267
|
def test_match_last_active_element_doesnt_unmark_failed_element
|
268
|
-
@stream.
|
269
|
-
@stream.
|
270
|
-
@stream.
|
271
|
-
@stream.
|
268
|
+
@stream.push 'a'
|
269
|
+
@stream.push 'b'
|
270
|
+
@stream.push 'c'
|
271
|
+
@stream.push 'd'
|
272
272
|
@stream.match_last_active_element('d')
|
273
273
|
@stream.match_last_active_element('c')
|
274
274
|
assert_equal({0 => false, 1 => false, 2 => true, 3 => true}, @stream.instance_variable_get(:@success))
|
@@ -280,30 +280,30 @@ class TestCwStream < MiniTest::Test
|
|
280
280
|
# end
|
281
281
|
#
|
282
282
|
# def test_pop_marked_returns_up_to_marked_first_element
|
283
|
-
# @stream.
|
284
|
-
# @stream.
|
285
|
-
# @stream.
|
286
|
-
# @stream.
|
283
|
+
# @stream.push 'a'
|
284
|
+
# @stream.push 'b'
|
285
|
+
# @stream.push 'c'
|
286
|
+
# @stream.push 'd'
|
287
287
|
# @stream.match_last_active_element('a')
|
288
288
|
# assert_equal({0 => {'a' => true}}, @stream.pop_marked)
|
289
289
|
# assert_equal(nil, @stream.pop_marked)
|
290
290
|
# end
|
291
291
|
#
|
292
292
|
# def test_pop_marked_returns_up_to_marked_second_element
|
293
|
-
# @stream.
|
294
|
-
# @stream.
|
295
|
-
# @stream.
|
296
|
-
# @stream.
|
293
|
+
# @stream.push 'a'
|
294
|
+
# @stream.push 'b'
|
295
|
+
# @stream.push 'c'
|
296
|
+
# @stream.push 'd'
|
297
297
|
# @stream.match_last_active_element('b')
|
298
298
|
# assert_equal({0 => {'a' => false}, 1 => {'b' => true}}, @stream.pop_marked)
|
299
299
|
# assert_equal(nil, @stream.pop_marked)
|
300
300
|
# end
|
301
301
|
#
|
302
302
|
# def test_pop_marked_returns_up_to_marked_first_and_third_element
|
303
|
-
# @stream.
|
304
|
-
# @stream.
|
305
|
-
# @stream.
|
306
|
-
# @stream.
|
303
|
+
# @stream.push 'a'
|
304
|
+
# @stream.push 'b'
|
305
|
+
# @stream.push 'c'
|
306
|
+
# @stream.push 'd'
|
307
307
|
# @stream.match_last_active_element('a')
|
308
308
|
# @stream.match_last_active_element('c')
|
309
309
|
# assert_equal({0 => {'a' => true}, 1 => {'b' => false}, 2 => {'c' => true}}, @stream.pop_marked)
|
@@ -313,10 +313,10 @@ class TestCwStream < MiniTest::Test
|
|
313
313
|
# end
|
314
314
|
#
|
315
315
|
# def test_pop_marked_returns_inactive_unmarked_elements
|
316
|
-
# @stream.
|
317
|
-
# @stream.
|
318
|
-
# @stream.
|
319
|
-
# @stream.
|
316
|
+
# @stream.push 'a'
|
317
|
+
# @stream.push 'b'
|
318
|
+
# @stream.push 'c'
|
319
|
+
# @stream.push 'd'
|
320
320
|
# @stream.active_region = 2
|
321
321
|
# assert_equal({0 => {'a' => false}, 1 => {'b' => false}}, @stream.pop_marked)
|
322
322
|
# assert_equal(nil, @stream.pop_marked)
|
@@ -326,20 +326,20 @@ class TestCwStream < MiniTest::Test
|
|
326
326
|
#
|
327
327
|
# def test_pop_marked_returns_mix_of_active_and_inactive
|
328
328
|
# @stream.active_region = 2
|
329
|
-
# @stream.
|
330
|
-
# @stream.
|
331
|
-
# @stream.
|
332
|
-
# @stream.
|
329
|
+
# @stream.push 'a'
|
330
|
+
# @stream.push 'b'
|
331
|
+
# @stream.push 'c'
|
332
|
+
# @stream.push 'd'
|
333
333
|
# @stream.match_last_active_element('d')
|
334
334
|
# assert_equal({0 => {'a' => false}, 1 => {'b' => false}, 2 => {'c' => false}, 3 => {'d' => true}}, @stream.pop_marked)
|
335
335
|
# assert_equal(nil, @stream.pop_marked)
|
336
336
|
# end
|
337
337
|
|
338
338
|
def test_pop_next_marked_returns_correct_elements_where_last_only_matched
|
339
|
-
@stream.
|
340
|
-
@stream.
|
341
|
-
@stream.
|
342
|
-
@stream.
|
339
|
+
@stream.push 'a'
|
340
|
+
@stream.push 'b'
|
341
|
+
@stream.push 'c'
|
342
|
+
@stream.push 'd'
|
343
343
|
@stream.match_last_active_element('d')
|
344
344
|
refute(@stream.pop_next_marked[:success])
|
345
345
|
refute(@stream.pop_next_marked[:success])
|
@@ -349,10 +349,10 @@ class TestCwStream < MiniTest::Test
|
|
349
349
|
end
|
350
350
|
|
351
351
|
def test_pop_next_marked_returns_correct_elements_where_penultimate_element_matched
|
352
|
-
@stream.
|
353
|
-
@stream.
|
354
|
-
@stream.
|
355
|
-
@stream.
|
352
|
+
@stream.push 'a'
|
353
|
+
@stream.push 'b'
|
354
|
+
@stream.push 'c'
|
355
|
+
@stream.push 'd'
|
356
356
|
@stream.match_last_active_element('c')
|
357
357
|
assert_equal({:value => 'a', :success => false}, @stream.pop_next_marked)
|
358
358
|
assert_equal({:value => 'b', :success => false}, @stream.pop_next_marked)
|
@@ -364,10 +364,10 @@ class TestCwStream < MiniTest::Test
|
|
364
364
|
def test_pop_next_marked_considers_active_region
|
365
365
|
|
366
366
|
@stream.active_region = 2
|
367
|
-
@stream.
|
368
|
-
@stream.
|
369
|
-
@stream.
|
370
|
-
@stream.
|
367
|
+
@stream.push 'a'
|
368
|
+
@stream.push 'b'
|
369
|
+
@stream.push 'c'
|
370
|
+
@stream.push 'd'
|
371
371
|
assert_equal({:value => 'a', :success => false}, @stream.pop_next_marked)
|
372
372
|
assert_equal({:value => 'b', :success => false}, @stream.pop_next_marked)
|
373
373
|
assert_equal(nil, @stream.pop_next_marked)
|
@@ -375,10 +375,10 @@ class TestCwStream < MiniTest::Test
|
|
375
375
|
|
376
376
|
@stream.empty
|
377
377
|
@stream.active_region = 1
|
378
|
-
@stream.
|
379
|
-
@stream.
|
380
|
-
@stream.
|
381
|
-
@stream.
|
378
|
+
@stream.push 'a'
|
379
|
+
@stream.push 'b'
|
380
|
+
@stream.push 'c'
|
381
|
+
@stream.push 'd'
|
382
382
|
assert_equal({:value => 'a', :success => false}, @stream.pop_next_marked)
|
383
383
|
assert_equal({:value => 'b', :success => false}, @stream.pop_next_marked)
|
384
384
|
assert_equal({:value => 'c', :success => false}, @stream.pop_next_marked)
|
@@ -387,17 +387,17 @@ class TestCwStream < MiniTest::Test
|
|
387
387
|
|
388
388
|
@stream.empty
|
389
389
|
@stream.active_region = 2
|
390
|
-
@stream.
|
391
|
-
@stream.
|
392
|
-
@stream.
|
393
|
-
@stream.
|
390
|
+
@stream.push 'a'
|
391
|
+
@stream.push 'b'
|
392
|
+
@stream.push 'c'
|
393
|
+
@stream.push 'd'
|
394
394
|
@stream.match_last_active_element('c')
|
395
395
|
assert_equal({:value => 'a', :success => false}, @stream.pop_next_marked)
|
396
396
|
assert_equal({:value => 'b', :success => false}, @stream.pop_next_marked)
|
397
397
|
assert_equal({:value => 'c', :success => true}, @stream.pop_next_marked)
|
398
398
|
assert_equal(nil, @stream.pop_next_marked)
|
399
|
-
@stream.
|
400
|
-
@stream.
|
399
|
+
@stream.push 'e'
|
400
|
+
@stream.push 'f'
|
401
401
|
@stream.match_last_active_element('e')
|
402
402
|
assert_equal({:value => 'd', :success => false}, @stream.pop_next_marked)
|
403
403
|
assert_equal({:value => 'e', :success => true}, @stream.pop_next_marked)
|
data/test/test_tester.rb
CHANGED
@@ -6,19 +6,15 @@ require_relative '../lib/cw'
|
|
6
6
|
|
7
7
|
class TestTester < MiniTest::Test
|
8
8
|
|
9
|
-
# include Tester
|
10
|
-
|
11
9
|
ROOT = File.expand_path File.dirname(__FILE__) + '/../'
|
12
10
|
|
13
11
|
def setup
|
14
|
-
@object =
|
15
|
-
|
16
|
-
#''end @cw = CW.new
|
17
|
-
# @cw.pause
|
12
|
+
@object = CWG::Tester.new
|
13
|
+
|
18
14
|
end
|
19
15
|
|
20
16
|
def teardown
|
21
|
-
@
|
17
|
+
@object = nil
|
22
18
|
end
|
23
19
|
|
24
20
|
def test_whatever
|
@@ -26,37 +22,23 @@ class TestTester < MiniTest::Test
|
|
26
22
|
end
|
27
23
|
#
|
28
24
|
def test_quit?
|
29
|
-
@object.
|
30
|
-
assert_equal
|
25
|
+
@object.quit
|
26
|
+
assert_equal true, @object.quit?
|
31
27
|
end
|
32
28
|
|
33
29
|
def test_quit
|
34
|
-
|
30
|
+
CWG::Cfg.config.params["quit"] = false
|
31
|
+
refute @object.quit?
|
35
32
|
@object.quit
|
36
33
|
assert @object.quit?
|
37
34
|
end
|
38
35
|
|
39
|
-
def test_global_quit?
|
40
|
-
@object.instance_eval('@global_quit = :quit')
|
41
|
-
assert_equal :quit, @object.global_quit?
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_global_quit
|
45
|
-
assert_nil @object.global_quit?
|
46
|
-
@object.global_quit
|
47
|
-
assert @object.global_quit?
|
48
|
-
end
|
49
|
-
|
50
36
|
def test_print_instantiates_Print_object
|
51
|
-
assert_equal Print, @object.print.class
|
37
|
+
assert_equal CWG::Print, @object.print.class
|
52
38
|
end
|
53
39
|
|
54
40
|
def test_timing_instantiates_Timing_object
|
55
|
-
assert_equal Timing, @object.timing.class
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_audio_instantiates_AudioPlayer_object
|
59
|
-
assert_equal AudioPlayer, @object.audio.class
|
41
|
+
assert_equal CWG::Timing, @object.timing.class
|
60
42
|
end
|
61
43
|
|
62
44
|
end
|