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.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/Gemfile +11 -0
- data/LICENSE +21 -0
- data/README.md +21 -0
- data/Rakefile +1 -0
- data/audio/audio_output.wav +0 -0
- data/audio/audio_output.wav0000.mp3 +0 -0
- data/audio/dash.wav +0 -0
- data/audio/dot.wav +0 -0
- data/audio/e_space.wav +0 -0
- data/audio/space.wav +0 -0
- data/cw.gemspec +18 -0
- data/daily.rb +182 -0
- data/data/text/abbreviations.txt +1 -0
- data/data/text/common_words.txt +90 -0
- data/data/text/cw_conversation.txt +1 -0
- data/data/text/most_common_words.txt +1 -0
- data/data/text/progress.txt +1 -0
- data/data/text/q_codes.txt +1 -0
- data/data/text/tom_sawyer.txt +6477 -0
- data/example.rb +139 -0
- data/lib/cw.rb +111 -0
- data/lib/cw/alphabet.rb +29 -0
- data/lib/cw/audio_player.rb +63 -0
- data/lib/cw/book.rb +239 -0
- data/lib/cw/book_details.rb +47 -0
- data/lib/cw/cl.rb +112 -0
- data/lib/cw/cw_dsl.rb +211 -0
- data/lib/cw/cw_encoding.rb +56 -0
- data/lib/cw/cw_params.rb +29 -0
- data/lib/cw/cw_threads.rb +36 -0
- data/lib/cw/file_details.rb +13 -0
- data/lib/cw/key_input.rb +53 -0
- data/lib/cw/monitor.rb +36 -0
- data/lib/cw/monitor_keys.rb +37 -0
- data/lib/cw/numbers.rb +29 -0
- data/lib/cw/print.rb +137 -0
- data/lib/cw/process.rb +11 -0
- data/lib/cw/progress.rb +27 -0
- data/lib/cw/randomize.rb +73 -0
- data/lib/cw/repeat_word.rb +91 -0
- data/lib/cw/rss.rb +71 -0
- data/lib/cw/sentence.rb +78 -0
- data/lib/cw/speak.rb +11 -0
- data/lib/cw/spoken.rb +11 -0
- data/lib/cw/str.rb +67 -0
- data/lib/cw/stream.rb +161 -0
- data/lib/cw/test_letters.rb +52 -0
- data/lib/cw/test_words.rb +59 -0
- data/lib/cw/tester.rb +221 -0
- data/lib/cw/timing.rb +92 -0
- data/lib/cw/tone_generator.rb +225 -0
- data/lib/cw/voice.rb +16 -0
- data/lib/cw/words.rb +182 -0
- data/read_book.rb +33 -0
- data/test/run_tests_continuously.rb +4 -0
- data/test/test_cw.rb +527 -0
- data/test/test_stream.rb +401 -0
- metadata +102 -0
data/lib/cw/voice.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#class Speak speaks with a voice
|
4
|
+
|
5
|
+
class Voice
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def say words, rate = 300, voice = 'bruce'
|
12
|
+
system("say #{words} -ospoken.wave -r#{rate} -v#{voice}")
|
13
|
+
system("afplay spoken.wave")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/cw/words.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
# encoding: utf-8
|
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
|
+
#class Words deals with words
|
50
|
+
|
51
|
+
class Words
|
52
|
+
|
53
|
+
def load(filename)
|
54
|
+
File.open(filename, 'r') do |file|
|
55
|
+
@words = file.read.split
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def double_words
|
60
|
+
puts 'here'
|
61
|
+
temp = []
|
62
|
+
@words.each do |wrd|
|
63
|
+
2.times { temp.push wrd }
|
64
|
+
end
|
65
|
+
@words = temp
|
66
|
+
end
|
67
|
+
|
68
|
+
def shuffle
|
69
|
+
@words.shuffle!
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_array
|
73
|
+
@words
|
74
|
+
end
|
75
|
+
|
76
|
+
def all
|
77
|
+
@words
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_s
|
81
|
+
@words.join(' ')
|
82
|
+
end
|
83
|
+
|
84
|
+
def add words
|
85
|
+
@words = words
|
86
|
+
end
|
87
|
+
|
88
|
+
def exist?
|
89
|
+
@words
|
90
|
+
end
|
91
|
+
|
92
|
+
def word_size(size)
|
93
|
+
@words = @words.select{|wrd| wrd.size == size}
|
94
|
+
end
|
95
|
+
|
96
|
+
def beginning_with_letter(letr)
|
97
|
+
@words.select{|wrd| wrd.start_with?(letr)}
|
98
|
+
end
|
99
|
+
|
100
|
+
def beginning_with(* letters)
|
101
|
+
@words = letters.flatten.collect{|letr| beginning_with_letter(letr)}.flatten
|
102
|
+
end
|
103
|
+
|
104
|
+
def ending_with_letter(letr)
|
105
|
+
@words.select{|wrd| wrd.end_with?(letr)}
|
106
|
+
end
|
107
|
+
|
108
|
+
def ending_with(* letters)
|
109
|
+
@words = letters.flatten.collect{|letr| ending_with_letter(letr)}.flatten
|
110
|
+
end
|
111
|
+
|
112
|
+
def count word_count
|
113
|
+
@words = @words.take(word_count)
|
114
|
+
end
|
115
|
+
|
116
|
+
def including_letter(letr)
|
117
|
+
@words.select{|wrd| wrd.include?(letr)}
|
118
|
+
end
|
119
|
+
|
120
|
+
def including(* letters)
|
121
|
+
@words = letters.flatten.collect{|letr| including_letter(letr)}.flatten
|
122
|
+
end
|
123
|
+
|
124
|
+
def no_longer_than(max)
|
125
|
+
@words = @words.select{|wrd| wrd.size <= max}
|
126
|
+
end
|
127
|
+
|
128
|
+
def no_shorter_than(min)
|
129
|
+
@words = @words.select{|wrd| wrd.size >= min}
|
130
|
+
end
|
131
|
+
|
132
|
+
def assign(words)
|
133
|
+
words.kind_of?(String) ?
|
134
|
+
@words = words.split(/\s+/) :
|
135
|
+
@words = words
|
136
|
+
end
|
137
|
+
|
138
|
+
def collect_words
|
139
|
+
@words.each{ |word| ' ' + word }.
|
140
|
+
collect{|wrd| wrd}.join(' ')
|
141
|
+
end
|
142
|
+
|
143
|
+
def reverse
|
144
|
+
@words.reverse!
|
145
|
+
end
|
146
|
+
|
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
|
+
def letters_numbers
|
156
|
+
letter_group.push( * number_group)
|
157
|
+
end
|
158
|
+
|
159
|
+
def random_letters(options = {})
|
160
|
+
@words = Randomize.new(options, letter_group).generate
|
161
|
+
end
|
162
|
+
|
163
|
+
def random_numbers(options = {})
|
164
|
+
@words = Randomize.new(options, number_group).generate
|
165
|
+
end
|
166
|
+
|
167
|
+
def random_letters_numbers(options = {})
|
168
|
+
@words = Randomize.new(options, letters_numbers.shuffle).generate
|
169
|
+
end
|
170
|
+
|
171
|
+
def alphabet(options = {reverse: nil})
|
172
|
+
@words = [Alphabet.new(options).generate]
|
173
|
+
end
|
174
|
+
|
175
|
+
def numbers(options = {reverse: nil})
|
176
|
+
@words = [Numbers.new(options).generate]
|
177
|
+
end
|
178
|
+
|
179
|
+
def numbers_spoken()
|
180
|
+
|
181
|
+
end
|
182
|
+
end
|
data/read_book.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
now = Time.now
|
4
|
+
|
5
|
+
require_relative 'lib/cw'
|
6
|
+
|
7
|
+
speed = 20
|
8
|
+
|
9
|
+
CW.new do
|
10
|
+
wpm speed
|
11
|
+
play_book output: :letter, duration: 10
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
seconds = (Time.now - now).to_i
|
16
|
+
|
17
|
+
if seconds == 0
|
18
|
+
puts 'No tests run!'
|
19
|
+
else
|
20
|
+
minutes = 0
|
21
|
+
if seconds >= 60
|
22
|
+
minutes = (seconds / 60).to_i
|
23
|
+
seconds = seconds % 60
|
24
|
+
end
|
25
|
+
print "Daily run completed in "
|
26
|
+
print "#{minutes} minute" if minutes > 0
|
27
|
+
print 's' if minutes > 1
|
28
|
+
print ', ' if((seconds > 0) && (minutes > 0))
|
29
|
+
print "#{seconds} second" if seconds > 0
|
30
|
+
print 's' if seconds > 1
|
31
|
+
puts '.'
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,4 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
system "rerun test/test_cw.rb -c --no-growl -n cw --pattern \"*.{rb}\""
|
4
|
+
system "reek lib/cw.rb lib/cw/words.rb lib/cw/alphabet.rb lib/cw/randomize.rb lib/cw/cw_dsl.rb lib/cw/str.rb lib/cw/cl.rb lib/cw/alphabet.rb lib/cw/cw_encode.rb lib/cw/cw_params.rb "
|
data/test/test_cw.rb
ADDED
@@ -0,0 +1,527 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'minitest/pride'
|
6
|
+
require_relative '../lib/cw'
|
7
|
+
|
8
|
+
class TestCW < MiniTest::Test
|
9
|
+
|
10
|
+
ROOT = File.expand_path File.dirname(__FILE__) + '/../'
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@cw = CW.new do
|
14
|
+
words = 'one two three'
|
15
|
+
pause
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
@cw = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_true
|
24
|
+
assert true
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_cw_class
|
28
|
+
assert_equal CW, @cw.class
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_name_is_unnamed_if_unnamed
|
32
|
+
assert_equal 'unnamed', @cw.name
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_name_can_be_set
|
36
|
+
@cw.name 'testing'
|
37
|
+
assert_equal 'testing', @cw.name
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_loads_words_by_default
|
41
|
+
assert_equal ["the", "of", "and", "a", "to"] , @cw.words.first(5)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_dictionary_defaults_to_COMMON_WORDS
|
45
|
+
temp = nil
|
46
|
+
CW.new {
|
47
|
+
pause
|
48
|
+
temp = Params.dictionary
|
49
|
+
}
|
50
|
+
assert_equal File.expand_path(ROOT + '/txt/common_words.txt'), File.expand_path(temp)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_CW_takes_a_block
|
54
|
+
CW.new {
|
55
|
+
pause
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_dont_load_common_words_if_passed_in_block
|
60
|
+
cw = CW.new {
|
61
|
+
pause
|
62
|
+
}
|
63
|
+
cw.words = ["some", "words"]
|
64
|
+
assert_equal ["some", "words"], cw.words
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_word_filename_defaults_to_words
|
68
|
+
cw = CW.new {
|
69
|
+
pause
|
70
|
+
}
|
71
|
+
cw.words = ["some", "words"]
|
72
|
+
assert_equal ["some","words"], cw.words
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_no_run_aliases_pause
|
76
|
+
time = Time.now
|
77
|
+
cw = CW.new {
|
78
|
+
no_run
|
79
|
+
}
|
80
|
+
cw.words = ["some", " words"]
|
81
|
+
assert (Time.now - time) < 1
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_default_mp3_filename_is_mp3_output
|
85
|
+
temp = nil
|
86
|
+
cw = CW.new {
|
87
|
+
no_run
|
88
|
+
temp = Params.mp3_filename
|
89
|
+
}
|
90
|
+
assert_equal "mp3_output", temp
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_reload_reloads_dictionary
|
94
|
+
cw = CW.new {
|
95
|
+
pause
|
96
|
+
}
|
97
|
+
cw.words = ["some", "words"]
|
98
|
+
assert_equal ["some", "words"], cw.words
|
99
|
+
cw.reload
|
100
|
+
assert_equal ["the", "of", "and", "a", "to"] , cw.words.first(5)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_load_common_words_loads_common_words
|
104
|
+
cw = CW.new {
|
105
|
+
pause
|
106
|
+
}
|
107
|
+
cw.words = ["some", "words"]
|
108
|
+
assert_equal ["some", "words"], cw.words
|
109
|
+
cw.load_common_words
|
110
|
+
assert_equal ["the", "of", "and", "a", "to"] , cw.words.first(5)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_load_words_loads_passed_filename
|
114
|
+
temp = Tempfile.new("words.tmp")
|
115
|
+
temp << "some words"
|
116
|
+
temp.close
|
117
|
+
@cw.load_words(temp)
|
118
|
+
assert_equal ["some", "words"], @cw.words
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_reload_reuploads_new_words_ie_dictionary_updated
|
122
|
+
temp = Tempfile.new("words.tmp")
|
123
|
+
temp << "some more words"
|
124
|
+
temp.close
|
125
|
+
@cw.load_words(temp)
|
126
|
+
assert_equal ["some", "more", "words"], @cw.words
|
127
|
+
@cw.words = ''
|
128
|
+
@cw.reload
|
129
|
+
assert_equal ["some", "more", "words"], @cw.words
|
130
|
+
@cw.load_common_words
|
131
|
+
assert_equal ["the", "of", "and", "a", "to"] , @cw.words.first(5)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_to_s_outputs_test_run_header_if_paused
|
135
|
+
temp = %q(
|
136
|
+
unnamed
|
137
|
+
=======
|
138
|
+
WPM: 25
|
139
|
+
=======
|
140
|
+
)
|
141
|
+
assert_equal temp, @cw.to_s
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_to_s_outputs_relevant_params_if_set
|
145
|
+
temp = %q(
|
146
|
+
unnamed
|
147
|
+
=======
|
148
|
+
WPM: 25
|
149
|
+
Shuffle: yes
|
150
|
+
Word count: 2
|
151
|
+
Word size: 3
|
152
|
+
Beginning: l
|
153
|
+
Ending: x
|
154
|
+
=======
|
155
|
+
)
|
156
|
+
@cw.shuffle
|
157
|
+
@cw.word_count 2
|
158
|
+
@cw.word_size 3
|
159
|
+
@cw.ending_with('x')
|
160
|
+
@cw.beginning_with('l')
|
161
|
+
assert_equal temp, @cw.to_s
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_wpm_defaults_to_25_if_unset
|
165
|
+
assert_equal 25, @cw.wpm
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_effective_wpm_defaults_to_nil
|
169
|
+
assert_nil @cw.effective_wpm
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_wpm_is_settable
|
173
|
+
wpm = rand(50)
|
174
|
+
@cw.wpm wpm
|
175
|
+
assert_equal wpm, @cw.wpm
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_effective_wpm_is_settable
|
179
|
+
effective_wpm = rand(50)
|
180
|
+
@cw.effective_wpm effective_wpm
|
181
|
+
assert_equal effective_wpm, @cw.effective_wpm
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_word_spacing_is_settable_and_readable
|
185
|
+
word_spacing = rand(50)
|
186
|
+
@cw.word_spacing word_spacing
|
187
|
+
assert_equal word_spacing, @cw.word_spacing
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_shuffle_shuffles_words
|
191
|
+
@cw.shuffle
|
192
|
+
refute_equal ["the", "of", "and", "a", "to"] , @cw.words.first(5)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_no_shuffle_doesnt_shuffle
|
196
|
+
@cw.no_shuffle
|
197
|
+
assert_equal ["the", "of", "and", "a", "to"] , @cw.words.first(5)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_word_size_returns_words_of_such_size
|
201
|
+
@cw.word_size 2
|
202
|
+
assert_equal ["of", "to", "in", "is", "it"] , @cw.words.first(5)
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_beginning_with_returns_words_beginning_with_letter
|
206
|
+
@cw.beginning_with 'l'
|
207
|
+
assert_equal ["like", "look", "long", "little", "large"] , @cw.words.first(5)
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_beginning_with_will_take_two_letters
|
211
|
+
@cw.beginning_with 'q','b'
|
212
|
+
assert_equal ["question", "quickly", "quite", "quiet", "be", "by"] ,
|
213
|
+
@cw.words.first(6)
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_ending_with_returns_words_ending_with_letter
|
217
|
+
@cw.ending_with 'l'
|
218
|
+
assert_equal ["all", "will", "call", "oil", "well"] , @cw.words.first(5)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_ending_with_will_take_two_letters
|
222
|
+
@cw.ending_with 'x', 'a'
|
223
|
+
assert_equal ["box", "six", "suffix", "a", "America", "sea"] ,
|
224
|
+
@cw.words.first(6)
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_word_count_returns_x_words
|
228
|
+
@cw.word_count 3
|
229
|
+
assert_equal ["the", "of", "and"] , @cw.words
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_including_returns_words_including_letter
|
233
|
+
@cw.including 'l'
|
234
|
+
assert_equal ["all", "will", "would", "like", "look"] , @cw.words.first(5)
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_including_will_take_two_letters
|
238
|
+
@cw.including 'q', 'a'
|
239
|
+
assert_equal ["question", "quickly", "equation", "square", "quite", "quiet", "equal", "and"] ,@cw.words.first(8)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_no_longer_than_will_return_words_no_longer_than_x
|
243
|
+
@cw.no_longer_than 4
|
244
|
+
assert_equal ["the", "of", "and", "a", "to"] , @cw.words.first(5)
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_no_shorter_than_will_return_words_no_shorter_than_x
|
248
|
+
@cw.no_shorter_than 4
|
249
|
+
assert_equal ["that", "with", "they", "this", "have"] , @cw.words.first(5)
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_assign_words_converts_space_seperated_string_to_array
|
253
|
+
@cw.assign_words "one two\nthree \tfour"
|
254
|
+
assert_equal ["one", "two", "three", "four"] , @cw.words
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_assign_words_passes_in_an_array_of_words_as_is
|
258
|
+
@cw.assign_words ["one", "two", "three", "four"]
|
259
|
+
assert_equal ["one", "two", "three", "four"] , @cw.words
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_random_letters_returns_words_of_size_4_by_default
|
263
|
+
@cw.random_letters
|
264
|
+
@cw.words.each { |w| assert_equal 4, w.length}
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_random_letters_returns_word_count_of_50_by_default
|
268
|
+
@cw.random_letters
|
269
|
+
assert_equal 50, @cw.words.size
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_random_letters_can_take_size_option
|
273
|
+
@cw.random_letters(size: 5)
|
274
|
+
@cw.words.each { |w| assert_equal 5, w.length}
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_random_letters_can_take_count_option
|
278
|
+
@cw.random_letters(count: 5)
|
279
|
+
assert_equal 5, @cw.words.size
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_random_letters_can_take_size_and_count_option
|
283
|
+
@cw.random_letters(count: 3, size: 4)
|
284
|
+
assert_equal 3, @cw.words.size
|
285
|
+
@cw.words.each { |w| assert_equal 4, w.length}
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_random_letters_returns_random_letters
|
289
|
+
@cw.random_letters
|
290
|
+
@cw.words.each { |w| assert_match /^(?=.*\D)[-\w]+$/, w }
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_random_numbers_can_take_size_and_count_option
|
294
|
+
@cw.random_numbers(count: 3, size: 4)
|
295
|
+
assert_equal 3, @cw.words.size
|
296
|
+
@cw.words.each { |w| assert_equal 4, w.length}
|
297
|
+
end
|
298
|
+
|
299
|
+
# def test_random_numbers_returns_random_numbers
|
300
|
+
# @cw.random_numbers
|
301
|
+
# @cw.words.each { |w| assert_match /\A[-+]?\d+\z/ , w }
|
302
|
+
# end
|
303
|
+
|
304
|
+
def test_random_letters_numbers_can_take_size_and_count_option
|
305
|
+
@cw.random_letters_numbers(count: 3, size: 4)
|
306
|
+
assert_equal 3, @cw.words.size
|
307
|
+
@cw.words.each { |w| assert_equal 4, w.length}
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_random_letters_numbers_includes_letter
|
311
|
+
@cw.random_letters_numbers
|
312
|
+
@cw.words.each { |w| assert_match /[a-zA-Z]+/, w}
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_random_letters_numbers_includes_number
|
316
|
+
@cw.random_letters_numbers
|
317
|
+
@cw.words.each do |w|
|
318
|
+
assert_match /[0-9]+/, w
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_alphabet_generates_alphabet
|
323
|
+
@cw.alphabet
|
324
|
+
assert_equal ["abcdefghijklmnopqrstuvwxyz"], @cw.words
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_alphabet_generates_reversed_alphabet
|
328
|
+
@cw.alphabet(reverse: true)
|
329
|
+
assert_equal ['zyxwvutsrqponmlkjihgfedcba'], @cw.words
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_alphabet_shuffles_alphabet
|
333
|
+
@cw.alphabet(shuffle: true)
|
334
|
+
refute_equal ["abcdefghijklmnopqrstuvwxyz"], @cw.words
|
335
|
+
assert_equal "abcdefghijklmnopqrstuvwxyz", @cw.words.first.chars.sort.join
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_reverse_reverses_words
|
339
|
+
@cw.assign_words ['first', 'then', 'last']
|
340
|
+
@cw.reverse
|
341
|
+
assert_equal ['last', 'then', 'first'], @cw.words.first(4)
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_save_word_file_saves_word_file
|
345
|
+
temp = Tempfile.new("saved.tmp")
|
346
|
+
@cw.assign_words ['the', 'of', 'and', 'a']
|
347
|
+
@cw.save_word_file(temp)
|
348
|
+
assert_equal "the of and a", temp.read
|
349
|
+
temp.close
|
350
|
+
end
|
351
|
+
|
352
|
+
def test_convert_generates_correct_command_for_default
|
353
|
+
@cw.dry_run = true
|
354
|
+
@cw.assign_words "some words"
|
355
|
+
assert_equal "echo some words | ebook2cw -w 25 -o \"mp3_output\" ", @cw.convert
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_run_converts_and_plays
|
359
|
+
@cw.dry_run = true
|
360
|
+
@cw.assign_words "some words"
|
361
|
+
assert_equal 'played', @cw.run
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_frequency_returns_frequency
|
365
|
+
assert_equal 567, @cw.frequency(567)
|
366
|
+
@cw.frequency 456
|
367
|
+
assert_equal 456, @cw.frequency
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_play_builds_correct_command_for_default
|
371
|
+
@cw.assign_words "some words"
|
372
|
+
@cw.dry_run = true
|
373
|
+
assert_equal "afplay mp3_output0000.mp3", @cw.play
|
374
|
+
end
|
375
|
+
|
376
|
+
# def test_dot_ms_returns_correct_time_in_milliseconds
|
377
|
+
# assert_in_delta(0.1, @cw.dot_ms(12), 0.001)
|
378
|
+
# end
|
379
|
+
#
|
380
|
+
# def test_space_ms_returns_correct_time_in_milliseconds
|
381
|
+
# assert_in_delta(0.3, @cw.space_ms(12), 0.001)
|
382
|
+
# end
|
383
|
+
|
384
|
+
def test_method_aliases
|
385
|
+
assert @cw.method(:word_length), @cw.method(:word_size)
|
386
|
+
assert @cw.method(:having_size_of), @cw.method(:word_size)
|
387
|
+
assert @cw.method(:word_shuffle), @cw.method(:shuffle)
|
388
|
+
assert @cw.method(:words_beginning_with), @cw.method(:beginning_with)
|
389
|
+
assert @cw.method(:words_ending_with), @cw.method(:ending_with)
|
390
|
+
assert @cw.method(:number_of_words), @cw.method(:word_count)
|
391
|
+
assert @cw.method(:words_including), @cw.method(:including)
|
392
|
+
assert @cw.method(:words_no_longer_than), @cw.method(:no_longer_than)
|
393
|
+
assert @cw.method(:words_no_shorter_than), @cw.method(:no_shorter_than)
|
394
|
+
assert @cw.method(:random_alphanumeric), @cw.method(:random_letters_numbers)
|
395
|
+
assert @cw.method(:comment), @cw.method(:name)
|
396
|
+
assert @cw.method(:no_run), @cw.method(:pause)
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_build_command_line_sets_w_param
|
400
|
+
@cw.wpm 33
|
401
|
+
assert @cw.build_cl.include?('-w 33 '), 'wpm param invalid'
|
402
|
+
end
|
403
|
+
|
404
|
+
def test_build_build_cl_sets_e_param
|
405
|
+
@cw.effective_wpm 33
|
406
|
+
assert @cw.build_cl.include?('-e 33 '), 'effective_wpm param invalid'
|
407
|
+
end
|
408
|
+
|
409
|
+
def test_build_build_cl_sets_W_param
|
410
|
+
@cw.word_spacing 2
|
411
|
+
assert @cw.build_cl.include?('-W 2 '), 'word_spacing param invalid'
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_build_build_cl_sets_f_param
|
415
|
+
@cw.frequency 800
|
416
|
+
assert @cw.build_cl.include?('-f 800 '), 'frequency param invalid'
|
417
|
+
end
|
418
|
+
|
419
|
+
def test_build_build_cl_sets_squarewave_param
|
420
|
+
@cw.set_tone_type :squarewave
|
421
|
+
assert @cw.build_cl.include?('-T 2 '), 'squarewave param invalid'
|
422
|
+
end
|
423
|
+
|
424
|
+
def test_build_build_cl_sets_sawtooth_param
|
425
|
+
@cw.set_tone_type :sawtooth
|
426
|
+
assert @cw.build_cl.include?('-T 1 '), 'sawtooth param invalid'
|
427
|
+
end
|
428
|
+
|
429
|
+
def test_build_build_cl_sets_sinewave_param
|
430
|
+
@cw.set_tone_type :sinewave
|
431
|
+
assert @cw.build_cl.include?('-T 0 '), 'sinewave param invalid'
|
432
|
+
end
|
433
|
+
|
434
|
+
def test_build_build_cl_ignores_invalid_tone_type
|
435
|
+
@cw.set_tone_type :sinewave
|
436
|
+
@cw.set_tone_type :invalid
|
437
|
+
assert @cw.build_cl.include?('-T 0 '), 'not ignoring invalid tone type'
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_build_build_cl_sets_author_param
|
441
|
+
@cw.author 'some author'
|
442
|
+
assert @cw.build_cl.include?('-a "some author" '), 'author param invalid'
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_build_build_cl_sets_title_param
|
446
|
+
@cw.title 'some title'
|
447
|
+
assert @cw.build_cl.include?('-t "some title" '), 'title param invalid'
|
448
|
+
end
|
449
|
+
|
450
|
+
def test_build_build_cl_sets_N_param_in_noise_mode
|
451
|
+
@cw.noise
|
452
|
+
assert @cw.build_cl.include?('-N 5 '), 'noise N param invalid'
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_build_build_cl_sets_B_param_in_noise_mode
|
456
|
+
@cw.noise
|
457
|
+
assert @cw.build_cl.include?('-B 1000 '), 'noise B param invalid'
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_build_build_cl_sets_default_mp3_filename
|
461
|
+
assert @cw.build_cl.include?('-o "mp3_output" '), 'default mp3 filename invalid'
|
462
|
+
end
|
463
|
+
|
464
|
+
def test_build_build_cl_sets_mp3_filename_to_given_name
|
465
|
+
@cw.mp3_filename 'some name'
|
466
|
+
assert @cw.build_cl.include?('-o "some name" '), 'default mp3 filename invalid'
|
467
|
+
end
|
468
|
+
|
469
|
+
# def test_build_build_cl_sets_mp3_filename_to_name_prefix
|
470
|
+
# cl = Cl.new(mp3_filename: "some name")
|
471
|
+
# cw = CW.new do
|
472
|
+
# name 'some name'
|
473
|
+
# no_run
|
474
|
+
# end
|
475
|
+
# assert cw.build_build_cl.include?('-o "some name" '), 'prefix mp3 filename invalid'
|
476
|
+
# end
|
477
|
+
|
478
|
+
def test_build_build_cl_sets_q_param_when_numeric_quality
|
479
|
+
@cw.quality 5
|
480
|
+
assert @cw.build_cl.include?('-q 5 '), 'mp3 quality invalid'
|
481
|
+
end
|
482
|
+
|
483
|
+
def test_build_build_cl_sets_low_quality
|
484
|
+
@cw.quality :low
|
485
|
+
assert @cw.build_cl.include?('-q 9 '), 'mp3 low quality invalid'
|
486
|
+
end
|
487
|
+
|
488
|
+
def test_build_build_cl_sets_medium_quality
|
489
|
+
@cw.quality :medium
|
490
|
+
assert @cw.build_cl.include?('-q 5 '), 'mp3 medium quality invalid'
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_build_build_cl_sets_high_quality
|
494
|
+
@cw.quality :high
|
495
|
+
assert @cw.build_cl.include?('-q 1 '), 'mp3 high quality invalid'
|
496
|
+
end
|
497
|
+
|
498
|
+
def test_build_command_includes_custom_commands_via_build_cl
|
499
|
+
@cw.command_line '-x "some custom command"'
|
500
|
+
assert @cw.build_cl.include?( '-x "some custom command"'), 'custom command invalid'
|
501
|
+
end
|
502
|
+
|
503
|
+
def test_cl_echo_returns_correct_string
|
504
|
+
str = ''
|
505
|
+
CW.new do
|
506
|
+
str = @cl.cl_echo ['some','words']
|
507
|
+
pause
|
508
|
+
end
|
509
|
+
assert_equal 'echo some words | ebook2cw -w 25 -o "mp3_output" ', str
|
510
|
+
end
|
511
|
+
|
512
|
+
def test_words_exist
|
513
|
+
temp = nil
|
514
|
+
CW.new do
|
515
|
+
assign_words 'some words'
|
516
|
+
temp = @words.exist?
|
517
|
+
pause
|
518
|
+
end
|
519
|
+
assert temp, "Words#exist? should be true"
|
520
|
+
CW.new do
|
521
|
+
@words.add nil
|
522
|
+
temp = @words.exist?
|
523
|
+
pause
|
524
|
+
end
|
525
|
+
refute temp, "Words#exist? should be nil"
|
526
|
+
end
|
527
|
+
end
|