cw 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.cw_config +18 -0
  3. data/.gitignore +10 -1
  4. data/LICENSE +2 -1
  5. data/README.md +212 -96
  6. data/Rakefile +15 -2
  7. data/VERSION +1 -1
  8. data/Vagrantfile +45 -0
  9. data/cw.gemspec +6 -1
  10. data/data/text/book_to_read.txt +4 -0
  11. data/data/text/english.txt +10000 -0
  12. data/example.rb +172 -106
  13. data/lib/cw.rb +10 -126
  14. data/lib/cw/alphabet.rb +53 -46
  15. data/lib/cw/audio_player.rb +83 -72
  16. data/lib/cw/book.rb +160 -185
  17. data/lib/cw/book_details.rb +38 -49
  18. data/lib/cw/cl.rb +101 -95
  19. data/lib/cw/common_words.rb +76 -0
  20. data/lib/cw/config.rb +50 -0
  21. data/lib/cw/current_word.rb +23 -24
  22. data/lib/cw/cw_dsl.rb +264 -131
  23. data/lib/cw/cw_encoding.rb +63 -69
  24. data/lib/cw/cw_stream.rb +86 -82
  25. data/lib/cw/cw_threads.rb +132 -22
  26. data/lib/cw/element.rb +60 -54
  27. data/lib/cw/file_details.rb +26 -11
  28. data/lib/cw/key_input.rb +53 -35
  29. data/lib/cw/numbers.rb +26 -19
  30. data/lib/cw/os.rb +13 -0
  31. data/lib/cw/play.rb +92 -0
  32. data/lib/cw/print.rb +102 -100
  33. data/lib/cw/process.rb +3 -0
  34. data/lib/cw/progress.rb +20 -17
  35. data/lib/cw/randomize.rb +56 -52
  36. data/lib/cw/repeat_word.rb +59 -66
  37. data/lib/cw/reveal.rb +32 -31
  38. data/lib/cw/rss.rb +52 -48
  39. data/lib/cw/sentence.rb +83 -76
  40. data/lib/cw/speak.rb +8 -4
  41. data/lib/cw/spoken.rb +8 -4
  42. data/lib/cw/str.rb +62 -30
  43. data/lib/cw/test_letters.rb +20 -28
  44. data/lib/cw/test_words.rb +25 -31
  45. data/lib/cw/tester.rb +219 -226
  46. data/lib/cw/text_helpers.rb +19 -15
  47. data/lib/cw/timing.rb +63 -67
  48. data/lib/cw/tone_generator.rb +176 -153
  49. data/lib/cw/tone_helpers.rb +15 -23
  50. data/lib/cw/voice.rb +12 -8
  51. data/lib/cw/words.rb +136 -106
  52. data/run_script_tests.rb +165 -0
  53. data/test/my_words.txt +1 -0
  54. data/test/test_common_words.rb +71 -0
  55. data/test/test_config.rb +98 -0
  56. data/test/test_current_word.rb +62 -0
  57. data/test/test_cw.rb +87 -120
  58. data/test/test_cw_threads.rb +123 -0
  59. data/test/test_filtering.rb +439 -0
  60. data/test/test_params.rb +28 -0
  61. data/test/test_play.rb +51 -0
  62. data/test/test_stream.rb +83 -83
  63. data/test/test_tester.rb +9 -27
  64. data/test/test_timing.rb +212 -0
  65. metadata +94 -12
  66. data/lib/cw/config_file.rb +0 -69
  67. data/lib/cw/monitor_keys.rb +0 -37
  68. data/lib/cw/params.rb +0 -104
@@ -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
@@ -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
@@ -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 test_add_word_adds_to_the_stream
158
- @stream.add_word 'a'
157
+ def test_push_adds_to_the_stream
158
+ @stream.push 'a'
159
159
  assert_equal({0 => 'a'}, @stream.stream)
160
- @stream.add_word 'tree'
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.add_word 'a'
165
+ @stream.push 'a'
166
166
  assert_equal 1, @stream.count
167
- @stream.add_word 'tree'
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.add_word 'a'
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.add_word 'a'
179
+ @stream.push 'a'
180
180
  @stream.mark_success(0)
181
- @stream.add_word 'b'
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.add_word 'a'
193
- @stream.add_word 'b'
194
- @stream.add_word 'c'
195
- @stream.add_word 'd'
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.add_word 'a'
203
- @stream.add_word 'b'
204
- @stream.add_word 'c'
205
- @stream.add_word 'd'
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.add_word 'a'
219
- @stream.add_word 'b'
220
- @stream.add_word 'c'
221
- @stream.add_word 'd'
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.add_word 'a'
227
- @stream.add_word 'b'
228
- @stream.add_word 'c'
229
- @stream.add_word 'd'
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.add_word 'a'
235
+ @stream.push 'a'
236
236
  refute(@stream.pop[:success])
237
- @stream.add_word 'b'
237
+ @stream.push 'b'
238
238
  refute(@stream.pop[:success])
239
- @stream.add_word 'c'
239
+ @stream.push 'c'
240
240
  refute(@stream.pop[:success])
241
- @stream.add_word 'd'
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.add_word 'a'
249
- @stream.add_word 'b'
250
- @stream.add_word 'c'
251
- @stream.add_word 'd'
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.add_word 'a'
259
- @stream.add_word 'b'
260
- @stream.add_word 'c'
261
- @stream.add_word 'd'
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.add_word 'a'
269
- @stream.add_word 'b'
270
- @stream.add_word 'c'
271
- @stream.add_word 'd'
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.add_word 'a'
284
- # @stream.add_word 'b'
285
- # @stream.add_word 'c'
286
- # @stream.add_word 'd'
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.add_word 'a'
294
- # @stream.add_word 'b'
295
- # @stream.add_word 'c'
296
- # @stream.add_word 'd'
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.add_word 'a'
304
- # @stream.add_word 'b'
305
- # @stream.add_word 'c'
306
- # @stream.add_word 'd'
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.add_word 'a'
317
- # @stream.add_word 'b'
318
- # @stream.add_word 'c'
319
- # @stream.add_word 'd'
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.add_word 'a'
330
- # @stream.add_word 'b'
331
- # @stream.add_word 'c'
332
- # @stream.add_word 'd'
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.add_word 'a'
340
- @stream.add_word 'b'
341
- @stream.add_word 'c'
342
- @stream.add_word 'd'
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.add_word 'a'
353
- @stream.add_word 'b'
354
- @stream.add_word 'c'
355
- @stream.add_word 'd'
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.add_word 'a'
368
- @stream.add_word 'b'
369
- @stream.add_word 'c'
370
- @stream.add_word 'd'
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.add_word 'a'
379
- @stream.add_word 'b'
380
- @stream.add_word 'c'
381
- @stream.add_word 'd'
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.add_word 'a'
391
- @stream.add_word 'b'
392
- @stream.add_word 'c'
393
- @stream.add_word 'd'
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.add_word 'e'
400
- @stream.add_word 'f'
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)
@@ -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 = Object.new
15
- @object.extend(Tester)
16
- #''end @cw = CW.new
17
- # @cw.pause
12
+ @object = CWG::Tester.new
13
+
18
14
  end
19
15
 
20
16
  def teardown
21
- @cw = nil
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.instance_eval('@quit = :quit')
30
- assert_equal :quit, @object.quit?
25
+ @object.quit
26
+ assert_equal true, @object.quit?
31
27
  end
32
28
 
33
29
  def test_quit
34
- assert_nil @object.quit?
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