You are supposed to write a file spec/task01_spec.rb to test the code in
lib/task01.rb . Your tests should kill as many mutants as possible. I wrote
three simple tests that killed 251 of the 343 mutants mutant generates for
this code (73.18%), so figure reaching that many kills is worth a 50% on the
assignment. As you will doubtless see, as there become fewer mutants alive,
the remaining mutants become harder to kill, so a kill rate of 99% would
generally be worth more than 1% more than a kill rate of 98%.
Note that your spec/task01_spec.rb file will be copied into a fresh copy of
the assignment for evaluation, so make sure all your changes are inside
spec/task01_spec.rb . You are not allowed to change the task01.rb code
or the ruby system itself.
Note that your test suite is required to run in less than 3 minutes (180
seconds) on the class compute server cs4472a.gaul.csd.uwo.ca , which is a cloud
system where the basic computational unit is a dual-core Intel Xeon
Processor (Skylake) running at 2.3 GHz with 16 GB of RAM. If it takes
longer than that then it is assumed to be broken and worth less than 50%.
On my own old laptop, my three test cases, according to the linux time
command, took 14.277 seconds of user time.
Finding a bug in task01.rb would be interesting, but for the purposes of this
assignment, whatever the code in task01.rb does with its inputs is assumed
to be what it is supposed to do.
The code being tested came from
https://github.com/robertodecurnex/caesar.git
I also looked at
https://github.com/robertodecurnex/vigenere.git
but decided not to use it. The original sources can be found in
lib/reference_code and the usage licenses can be found at the github locations.
For more on Caesar ciphers (the basis of Task01), see
https://en.wikipedia.org/wiki/Caesar_cipher
class Task01
def initialize()
@a_offset = 65 #’A’.unpack(‘C’).first
@z_offset = 90 #’Z’.unpack(‘C’).first
end
def encode(key, plain_text)
key_offset = key.upcase.unpack(‘C’).first
cipher_text = plain_text.upcase.split(”).collect do |letter|
cipher_letter = (letter.unpack(‘C’).first + key_offset – @a_offset)
if cipher_letter > @z_offset
cipher_letter -= ( @z_offset – @a_offset + 1 )
end
cipher_letter.chr
end
return cipher_text.join
end
def decode(key, cipher_text)
key_offset = key.upcase.unpack(‘C’).first
plain_text = cipher_text.split(”).collect do |cipher_letter|
if !(‘A’..’Z’).include?(cipher_letter)
cipher_letter
else
if cipher_letter.unpack(‘C’).first >= key_offset
letter = cipher_letter.unpack(‘C’).first – key_offset
else
letter = (cipher_letter.unpack(‘C’).first + (@z_offset – @a_offset + 1)) – key_offset
end
letter += @a_offset
letter.chr
end
end
return plain_text.join
end
end