In this tutorial we will see how to write tests aimed at learning the alphabet.

Learning the letters

The alphabet is represented by a combinations of dots and dashes. So as a first step lets learn the letters consisting of a single dot or dash. The example below plays these characters. Copy or download the script and name it alphabet.rb.

  # alphabet.rb

require 'cw'

cw do
  comment 'test single element letters'
  wpm 15
  load_alphabet :size, 1
  shuffle
  print_letters
end


To run the script enter the following on the command line:


cw alphabet.rb

Next, we will learn letters consisting of two elements:

Two element letters

  # alphabet_2.rb

require 'cw'

cw do
  comment 'test 2 element letters'
  wpm 15
  load_alphabet :size, 2
  shuffle
end


Now we can test all the letters we have learned so far:

Letters having less than 3 elements

  # alphabet_3.rb

require 'cw'

cw do
  comment 'test less than 3 element letters'
  wpm 15
  load_alphabet :less_than, 3
  shuffle
end




Now the three element letters:

Three element letters

  # alphabet_4.rb

require 'cw'

cw do
  comment 'test 3 element letters'
  wpm 15
  load_alphabet :size, 3
  shuffle
end




Now we can test all letters learned so far (letters having less than 4 elements)

Letters having less than 4 elements

  # alphabet_5.rb

require 'cw'

cw do
  comment 'test less than 4 element letters'
  wpm 15
  load_alphabet :less_than, 4
  shuffle
end




Now to learn the remaining letters - the 4 element letters:

Four element letters

  # alphabet_6.rb

require 'cw'

cw do
  comment 'test 4 element letters'
  wpm 15
  load_alphabet :size, 4
  shuffle
end


Now lets test just the first half of the alphabet:

Test letters a to m

  # alphabet_7.rb

require 'cw'

cw do
  comment 'test letters a to m'
  wpm 15
  load_alphabet "a".."m"
  shuffle
end



Next, the second half of the alphabet:

Test letters n to z

  # alphabet_8.rb

require 'cw'

cw do
  comment 'test letters n to z'
  wpm 15
  load_alphabet "n".."z"
  shuffle
end



Test alphabet

Finally We can now test the entire alphabet. Notice we don’t need to provide any arguments to the load_alphabet command to load the whole alphabet:

Test entire alphabet (scramble the order)

  # alphabet_9.rb

require 'cw'

cw do
  comment 'test entire alphabet'
  wpm 15
  load_alphabet
  shuffle
end



Add all above tests to a single script

CW is designed to make it easy for you to generate cw scripts consisting of several defferent tests, which are run one after the other. As an example, below is a script which includes all the tests shown so far. We’ve included a vowel test, and a couple of simple word tests.

Alphabet test medley

  # alphabet_10.rb

require 'cw'

cw do
  comment 'test single element letters'
  wpm 15
  load_alphabet :size, 1
  shuffle
end

cw do
  comment 'test 2 element letters'
  wpm 15
  load_alphabet :size, 2
  shuffle
end

cw do
  comment 'test less than 3 element letters'
  wpm 15
  load_alphabet :less_than, 3
  shuffle
end

cw do
  comment 'test 3 element letters'
  wpm 15
  load_alphabet :size, 3
  shuffle
end

cw do
  comment 'test less than 4 element letters'
  wpm 15
  load_alphabet :less_than, 4
  shuffle
end

cw do
  comment 'test 4 element letters'
  wpm 15
  load_alphabet :size, 4
  shuffle
end

cw do
  comment 'test alphabet vowels'
  wpm 15
  load_vowels
  shuffle
end

cw do
  comment 'test letters a..m'
  wpm 15
  load_alphabet("a".."m")
  shuffle
end

cw do
  comment 'test 4 small words made with letters a..m'
  wpm 15
  containing('a'..'m')
  shuffle
  word_size 2
  word_count 4
end

cw do
  comment 'test letters n..z'
  wpm 15
  load_letters('n'..'z')
  shuffle
end

cw do
  comment 'test 4 small words made with letters n..z'
  wpm 15
  containing('n'..'z')
  shuffle
  word_size 2
  word_count 4
end

cw do
  comment 'test entire alphabet'
  wpm 15
  load_alphabet
  shuffle
end



Running the script

To run the scripts open a shell and enter the following on the command line:


cw alphabet.rb

The .rb extension can also be omitted:


cw alphabet

If you wish to run the script multiple times, add a number after the script name:


cw alphabet 10

More details on running the cw executable are available here.