cw 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/Gemfile +11 -0
  4. data/LICENSE +21 -0
  5. data/README.md +21 -0
  6. data/Rakefile +1 -0
  7. data/audio/audio_output.wav +0 -0
  8. data/audio/audio_output.wav0000.mp3 +0 -0
  9. data/audio/dash.wav +0 -0
  10. data/audio/dot.wav +0 -0
  11. data/audio/e_space.wav +0 -0
  12. data/audio/space.wav +0 -0
  13. data/cw.gemspec +18 -0
  14. data/daily.rb +182 -0
  15. data/data/text/abbreviations.txt +1 -0
  16. data/data/text/common_words.txt +90 -0
  17. data/data/text/cw_conversation.txt +1 -0
  18. data/data/text/most_common_words.txt +1 -0
  19. data/data/text/progress.txt +1 -0
  20. data/data/text/q_codes.txt +1 -0
  21. data/data/text/tom_sawyer.txt +6477 -0
  22. data/example.rb +139 -0
  23. data/lib/cw.rb +111 -0
  24. data/lib/cw/alphabet.rb +29 -0
  25. data/lib/cw/audio_player.rb +63 -0
  26. data/lib/cw/book.rb +239 -0
  27. data/lib/cw/book_details.rb +47 -0
  28. data/lib/cw/cl.rb +112 -0
  29. data/lib/cw/cw_dsl.rb +211 -0
  30. data/lib/cw/cw_encoding.rb +56 -0
  31. data/lib/cw/cw_params.rb +29 -0
  32. data/lib/cw/cw_threads.rb +36 -0
  33. data/lib/cw/file_details.rb +13 -0
  34. data/lib/cw/key_input.rb +53 -0
  35. data/lib/cw/monitor.rb +36 -0
  36. data/lib/cw/monitor_keys.rb +37 -0
  37. data/lib/cw/numbers.rb +29 -0
  38. data/lib/cw/print.rb +137 -0
  39. data/lib/cw/process.rb +11 -0
  40. data/lib/cw/progress.rb +27 -0
  41. data/lib/cw/randomize.rb +73 -0
  42. data/lib/cw/repeat_word.rb +91 -0
  43. data/lib/cw/rss.rb +71 -0
  44. data/lib/cw/sentence.rb +78 -0
  45. data/lib/cw/speak.rb +11 -0
  46. data/lib/cw/spoken.rb +11 -0
  47. data/lib/cw/str.rb +67 -0
  48. data/lib/cw/stream.rb +161 -0
  49. data/lib/cw/test_letters.rb +52 -0
  50. data/lib/cw/test_words.rb +59 -0
  51. data/lib/cw/tester.rb +221 -0
  52. data/lib/cw/timing.rb +92 -0
  53. data/lib/cw/tone_generator.rb +225 -0
  54. data/lib/cw/voice.rb +16 -0
  55. data/lib/cw/words.rb +182 -0
  56. data/read_book.rb +33 -0
  57. data/test/run_tests_continuously.rb +4 -0
  58. data/test/test_cw.rb +527 -0
  59. data/test/test_stream.rb +401 -0
  60. metadata +102 -0
@@ -0,0 +1,401 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'minitest/autorun'
5
+ require 'minitest/pride'
6
+ require_relative '../lib/cw/stream'
7
+
8
+ # class TestStreamMatching < MiniTest::Test
9
+ # def setup
10
+ # @match = Match.new
11
+ # @match.words = %w(here are some words and here are just a few more!)
12
+ # @match.instance_variable_set :@words1,
13
+ # %w(here are some words and here are just a few more!)
14
+ # end
15
+ #
16
+ # def test_StreamMatching_exists
17
+ # assert_kind_of Match, @match
18
+ # end
19
+ #
20
+ # def test_next_returns_next_word
21
+ # assert_equal 'here ', @match.next_word
22
+ # end
23
+ #
24
+ # def test_next_returns_next_word1
25
+ # assert_equal 'here ', @match.next_word1
26
+ # end
27
+ #
28
+ # def test_load_words_loads_words_as_array_correctly
29
+ # @match.load_words %w(here are some words and here are just a few more!)
30
+ # assert_equal 'here', @match.words.first
31
+ # assert_equal 'more!', @match.words.last
32
+ # end
33
+ #
34
+ # def test_remove_upto_match_removes_first_word_if_matched_word
35
+ # assert_equal 'are some ', @match.remove_upto_match('here are some', 'here')
36
+ # end
37
+ #
38
+ # def test_truncate_actual_doesnt_generate_unnecessary_errors
39
+ # @match.instance_variable_set :@actual_string, 'here are some'
40
+ # @match.instance_variable_set :@attempt, 'here '
41
+ # assert_equal 'are some ', @match.truncate_actual
42
+ # assert_equal [], @match.instance_variable_get(:@errors)
43
+ # end
44
+ #
45
+ # def test_truncate_actual_generates_necessary_errors
46
+ # @match.instance_variable_set :@actual_string, 'here are some'
47
+ # @match.instance_variable_set :@attempt, 'are '
48
+ # assert_equal 'some ', @match.truncate_actual
49
+ # assert_equal ['here'], @match.instance_variable_get(:@errors)
50
+ # end
51
+ #
52
+ # def test_truncate_attempt
53
+ # @match.instance_variable_set :@attempt, 'here '
54
+ # assert_equal '', @match.truncate_attempt('here')
55
+ # end
56
+ #
57
+ # def test_have_actual_word_when_has_word
58
+ # @match.instance_variable_set :@actual_string, 'have '
59
+ # assert_equal true, @match.have_actual_word?
60
+ # end
61
+ #
62
+ # def test_have_attempt_word_when_has_word
63
+ # @match.instance_variable_set :@attempt, 'have '
64
+ # assert_equal true, @match.have_attempt_word?
65
+ # end
66
+ #
67
+ # def test_have_actual_word_when_havent_complete_word
68
+ # @match.instance_variable_set :@actual_string, 'haven'
69
+ # assert_equal false, @match.have_actual_word?
70
+ # end
71
+ #
72
+ # def test_have_attempt_word_when_havent_complete_word
73
+ # @match.instance_variable_set :@attempt, 'haven'
74
+ # assert_equal false, @match.have_attempt_word?
75
+ # end
76
+ #
77
+ # def test_actual_word_returns_first_complete_word
78
+ # @match.instance_variable_set :@actual_string, 'one two three '
79
+ # assert_equal 'one ', @match.actual_word
80
+ # end
81
+ #
82
+ # def test_attempt_word_returns_complete_word
83
+ # @match.instance_variable_set :@attempt, 'one two three '
84
+ # assert_equal 'one ', @match.attempt_word
85
+ # end
86
+ #
87
+ # def test_match_found_finds_match
88
+ # @match.instance_variable_set :@actual_string, 'one two three '
89
+ # assert_equal true, @match.match_found?('one ')
90
+ # end
91
+ #
92
+ # def test_match_found_refutes_invalid_match
93
+ # @match.instance_variable_set :@actual_string, 'one two three '
94
+ # assert_equal false, @match.match_found?('oxe ')
95
+ # end
96
+ #
97
+ # def test_mark_attempt
98
+ # @match.instance_variable_set :@actual_string, 'one two three '
99
+ # @match.instance_variable_set :@attempt, 'one '
100
+ # @match.mark_attempt
101
+ # assert_equal 'two three ', @match.instance_variable_get(:@actual_string)
102
+ # assert_equal '', @match.instance_variable_get(:@attempt)
103
+ # end
104
+ #
105
+ # def test_remove_upto_match_removes_first_2_words_if_matched_word_second
106
+ # assert_equal 'some ', @match.remove_upto_match('here are some', 'are')
107
+ # end
108
+ #
109
+ # def test_remove_upto_match_removes_all_words_if_matched_word_last
110
+ # assert_equal '', @match.remove_upto_match('here are some', 'some')
111
+ # end
112
+ #
113
+ # def test_enforce_max_word_lag_truncates_correctly
114
+ # @match.instance_variable_set(:@actual_string, 'one two three four ')
115
+ # @match.instance_variable_set(:@max_word_lag, 2)
116
+ # assert_equal 'four ', @match.enforce_max_word_lag
117
+ #
118
+ # @match.instance_variable_set(:@actual_string, 'one two three four ')
119
+ # @match.instance_variable_set(:@max_word_lag, 3)
120
+ # assert_equal 'three four ', @match.enforce_max_word_lag
121
+ #
122
+ # @match.instance_variable_set(:@actual_string, 'one two three four ')
123
+ # @match.instance_variable_set(:@max_word_lag, 4)
124
+ # assert_equal 'two three four ', @match.enforce_max_word_lag
125
+ # end
126
+ #
127
+ # def test_enforce_max_word_lag_returns_nil_where_truncation_unnecessary
128
+ # @match.instance_variable_set(:@actual_string, 'one two three four ')
129
+ # @match.instance_variable_set(:@max_word_lag, 5)
130
+ # assert_nil @match.enforce_max_word_lag
131
+ # end
132
+ #
133
+ # def test_mark_attempt
134
+ # @match.instance_variable_set(:@actual_string, 'one two three four ')
135
+ # @match.instance_variable_set(:@attempt, 'one ')
136
+ # @match.mark_attempt
137
+ # assert_equal 'two three four ', @match.instance_variable_get(:@actual_string)
138
+ #
139
+ # end
140
+ # end
141
+
142
+ class TestStream < MiniTest::Test
143
+
144
+ def setup
145
+ @stream = Stream.new
146
+ end
147
+
148
+ def test_assert
149
+ assert true
150
+ end
151
+
152
+ def test_add_adds_to_the_stream
153
+ @stream.add 'a'
154
+ assert_equal({0 => 'a'}, @stream.stream)
155
+ @stream.add 'tree'
156
+ assert_equal({0 => 'a', 1 => 'tree'}, @stream.stream)
157
+ end
158
+
159
+ def test_count
160
+ @stream.add 'a'
161
+ assert_equal 1, @stream.count
162
+ @stream.add 'tree'
163
+ assert_equal 2, @stream.count
164
+ assert_equal({0 => 'a', 1 => 'tree'}, @stream.stream)
165
+ end
166
+
167
+ def test_stream_element_can_be_marked_a_success
168
+ @stream.add 'a'
169
+ @stream.mark_success(0)
170
+ assert_equal({0 => true}, @stream.instance_variable_get(:@success))
171
+ end
172
+
173
+ def test_stream_element_can_be_marked_a_fail
174
+ @stream.add 'a'
175
+ @stream.mark_success(0)
176
+ @stream.add 'b'
177
+ @stream.mark_fail(1)
178
+ assert_equal({0 => true, 1 => false}, @stream.instance_variable_get(:@success))
179
+ end
180
+
181
+ def test_active_region_can_be_assigned
182
+ @stream.active_region = 4
183
+ assert_equal 4, @stream.active_region
184
+ end
185
+
186
+ def test_mark_inactive_region_fail_fails_unmarked_inactive_elements
187
+ @stream.add 'a'
188
+ @stream.add 'b'
189
+ @stream.add 'c'
190
+ @stream.add 'd'
191
+ @stream.active_region = 2
192
+ @stream.fail_unmarked_inactive_elements
193
+ assert_equal({0 => false, 1 => false, 2 => nil, 3 => nil}, @stream.instance_variable_get(:@success))
194
+ end
195
+
196
+ def test_mark_inactive_region_fail_doesnt_fail_successes
197
+ @stream.add 'a'
198
+ @stream.add 'b'
199
+ @stream.add 'c'
200
+ @stream.add 'd'
201
+ @stream.instance_variable_set(:@success, {0 => true, 1 => false})
202
+ @stream.active_region = 2
203
+ @stream.fail_unmarked_inactive_elements
204
+ assert_equal({0 => true, 1 => false}, @stream.instance_variable_get(:@success))
205
+ end
206
+
207
+ def test_mark_inactive_region_fail_doesnt_fail_when_no_stream
208
+ @stream.stream = {}
209
+ @stream.fail_unmarked_inactive_elements
210
+ end
211
+
212
+ def test_first_returns_first_element_in_stream
213
+ @stream.add 'a'
214
+ @stream.add 'b'
215
+ @stream.add 'c'
216
+ @stream.add 'd'
217
+ assert_equal 'a', @stream.first
218
+ end
219
+
220
+ def test_pop_returns_first_element_in_stream_and_removes_element
221
+ @stream.add 'a'
222
+ @stream.add 'b'
223
+ @stream.add 'c'
224
+ @stream.add 'd'
225
+ assert_equal({'a' => false}, @stream.pop)
226
+ assert_equal({1 => 'b', 2 => 'c', 3 => 'd'}, @stream.stream)
227
+
228
+ @stream.empty
229
+ @stream.add 'a'
230
+ assert_equal({'a' => false}, @stream.pop)
231
+ @stream.add 'b'
232
+ assert_equal({'b' => false}, @stream.pop)
233
+ @stream.add 'c'
234
+ assert_equal({'c' => false}, @stream.pop)
235
+ @stream.add 'd'
236
+ assert_equal({'d' => false}, @stream.pop)
237
+ assert_nil @stream.pop
238
+ assert_equal({}, @stream.stream)
239
+ end
240
+
241
+ def test_match_last_active_element_marks_correct_element
242
+ @stream.add 'a'
243
+ @stream.add 'b'
244
+ @stream.add 'c'
245
+ @stream.add 'd'
246
+ @stream.match_last_active_element('c')
247
+ assert_equal({0 => false, 1 => false, 2 => true, 3 => nil}, @stream.instance_variable_get(:@success))
248
+ end
249
+
250
+ def test_match_last_active_element_doesnt_unmark_correct_element
251
+ @stream.active_region = 2
252
+ @stream.add 'a'
253
+ @stream.add 'b'
254
+ @stream.add 'c'
255
+ @stream.add 'd'
256
+ @stream.match_last_active_element('c')
257
+ @stream.match_last_active_element('d')
258
+ assert_equal({0 => nil, 1 => nil, 2 => true, 3 => true}, @stream.instance_variable_get(:@success))
259
+ end
260
+
261
+ def test_match_last_active_element_doesnt_unmark_failed_element
262
+ @stream.add 'a'
263
+ @stream.add 'b'
264
+ @stream.add 'c'
265
+ @stream.add 'd'
266
+ @stream.match_last_active_element('d')
267
+ @stream.match_last_active_element('c')
268
+ assert_equal({0 => false, 1 => false, 2 => false, 3 => true}, @stream.instance_variable_get(:@success))
269
+ end
270
+
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.add 'a'
278
+ # @stream.add 'b'
279
+ # @stream.add 'c'
280
+ # @stream.add 'd'
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.add 'a'
288
+ # @stream.add 'b'
289
+ # @stream.add 'c'
290
+ # @stream.add 'd'
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.add 'a'
298
+ # @stream.add 'b'
299
+ # @stream.add 'c'
300
+ # @stream.add 'd'
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.add 'a'
311
+ # @stream.add 'b'
312
+ # @stream.add 'c'
313
+ # @stream.add 'd'
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.add 'a'
324
+ # @stream.add 'b'
325
+ # @stream.add 'c'
326
+ # @stream.add 'd'
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
331
+
332
+ def test_pop_next_marked_returns_correct_elements_where_last_only_matched
333
+ @stream.add 'a'
334
+ @stream.add 'b'
335
+ @stream.add 'c'
336
+ @stream.add 'd'
337
+ @stream.match_last_active_element('d')
338
+ assert_equal({'a' => false}, @stream.pop_next_marked)
339
+ assert_equal({'b' => false}, @stream.pop_next_marked)
340
+ assert_equal({'c' => false}, @stream.pop_next_marked)
341
+ assert_equal({'d' => true}, @stream.pop_next_marked)
342
+ assert_equal(nil, @stream.pop_next_marked)
343
+ end
344
+
345
+ def test_pop_next_marked_returns_correct_elements_where_penultimate_element_matched
346
+ @stream.add 'a'
347
+ @stream.add 'b'
348
+ @stream.add 'c'
349
+ @stream.add 'd'
350
+ @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)
354
+ assert_equal(nil, @stream.pop_next_marked)
355
+ assert_equal(nil, @stream.pop_next_marked)
356
+ end
357
+
358
+ def test_pop_next_marked_considers_active_region
359
+
360
+ @stream.active_region = 2
361
+ @stream.add 'a'
362
+ @stream.add 'b'
363
+ @stream.add 'c'
364
+ @stream.add 'd'
365
+ assert_equal({'a' => false}, @stream.pop_next_marked)
366
+ assert_equal({'b' => false}, @stream.pop_next_marked)
367
+ assert_equal(nil, @stream.pop_next_marked)
368
+ assert_equal(nil, @stream.pop_next_marked)
369
+
370
+ @stream.empty
371
+ @stream.active_region = 1
372
+ @stream.add 'a'
373
+ @stream.add 'b'
374
+ @stream.add 'c'
375
+ @stream.add 'd'
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)
379
+ assert_equal(nil, @stream.pop_next_marked)
380
+
381
+
382
+ @stream.empty
383
+ @stream.active_region = 2
384
+ @stream.add 'a'
385
+ @stream.add 'b'
386
+ @stream.add 'c'
387
+ @stream.add 'd'
388
+ @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)
392
+ assert_equal(nil, @stream.pop_next_marked)
393
+ @stream.add 'e'
394
+ @stream.add 'f'
395
+ @stream.match_last_active_element('e')
396
+ assert_equal({'d' => false}, @stream.pop_next_marked)
397
+ assert_equal({'e' => true}, @stream.pop_next_marked)
398
+ assert_equal(nil, @stream.pop_next_marked)
399
+ assert_equal({5 => 'f'}, @stream.stream)
400
+ end
401
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martyn Jago
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A ruby library to help learn and practice morse code
14
+ email:
15
+ - martyn.jago@btinternet.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - Gemfile
22
+ - LICENSE
23
+ - README.md
24
+ - Rakefile
25
+ - audio/audio_output.wav
26
+ - audio/audio_output.wav0000.mp3
27
+ - audio/dash.wav
28
+ - audio/dot.wav
29
+ - audio/e_space.wav
30
+ - audio/space.wav
31
+ - cw.gemspec
32
+ - daily.rb
33
+ - data/text/abbreviations.txt
34
+ - data/text/common_words.txt
35
+ - data/text/cw_conversation.txt
36
+ - data/text/most_common_words.txt
37
+ - data/text/progress.txt
38
+ - data/text/q_codes.txt
39
+ - data/text/tom_sawyer.txt
40
+ - example.rb
41
+ - lib/cw.rb
42
+ - lib/cw/alphabet.rb
43
+ - lib/cw/audio_player.rb
44
+ - lib/cw/book.rb
45
+ - lib/cw/book_details.rb
46
+ - lib/cw/cl.rb
47
+ - lib/cw/cw_dsl.rb
48
+ - lib/cw/cw_encoding.rb
49
+ - lib/cw/cw_params.rb
50
+ - lib/cw/cw_threads.rb
51
+ - lib/cw/file_details.rb
52
+ - lib/cw/key_input.rb
53
+ - lib/cw/monitor.rb
54
+ - lib/cw/monitor_keys.rb
55
+ - lib/cw/numbers.rb
56
+ - lib/cw/print.rb
57
+ - lib/cw/process.rb
58
+ - lib/cw/progress.rb
59
+ - lib/cw/randomize.rb
60
+ - lib/cw/repeat_word.rb
61
+ - lib/cw/rss.rb
62
+ - lib/cw/sentence.rb
63
+ - lib/cw/speak.rb
64
+ - lib/cw/spoken.rb
65
+ - lib/cw/str.rb
66
+ - lib/cw/stream.rb
67
+ - lib/cw/test_letters.rb
68
+ - lib/cw/test_words.rb
69
+ - lib/cw/tester.rb
70
+ - lib/cw/timing.rb
71
+ - lib/cw/tone_generator.rb
72
+ - lib/cw/voice.rb
73
+ - lib/cw/words.rb
74
+ - read_book.rb
75
+ - test/run_tests_continuously.rb
76
+ - test/test_cw.rb
77
+ - test/test_stream.rb
78
+ homepage: http://github.com/mjago/cw
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: CW tutor / exerciser
102
+ test_files: []