|
2 | 2 |
|
3 | 3 | require_relative 'spec_helper' |
4 | 4 |
|
5 | | -describe 'Exercise 7_caesar_cipher_variation' do |
6 | | - before do |
7 | | - # Other exercises could be using the same method name: |
8 | | - require_relative '../exercises/7_caesar_cipher_variation/solution' |
9 | | - alias solution_7_1 encode_str |
10 | | - alias solution_7_2 decode |
11 | | - end |
| 5 | +class CaesarCipherVariationSpecs < Minitest::Spec |
| 6 | + # Next line is equivalent to RSpec's before(:all) |
| 7 | + # For more details see https://github.com/minitest/minitest/issues/61 |
| 8 | + # It creates a class as SolutionClass:CaesarCipherVariation wrapping with the solution's code, |
| 9 | + # to be shared by all test runs: |
| 10 | + @@solution_class = SolutionClass.create_wrapping_class_for '7_caesar_cipher_variation' |
12 | 11 |
|
13 | | - describe '#encode_str' do |
14 | | - let(:sample_data) do |
15 | | - { |
16 | | - ['I should have known that you would have a perfect answer for me!!!', 1] => |
17 | | - ['ijJ tipvme ibw', 'f lopxo uibu z', 'pv xpvme ibwf ', 'b qfsgfdu botx', 'fs gps nf!!!'], |
18 | | - ['Now you know your ABCs!', 1] => ['noOpx', ' zpv ', 'lopx ', 'zpvs ', 'BCDt!'], |
19 | | - ['The same sentence, but split in 5 chunks', 0] => |
20 | | - ['ttThe sam', 'e sentenc', 'e, but sp', 'lit in 5 ', 'chunks'], |
21 | | - # Less than 5 chunks (small String): |
22 | | - ['A', 2] => ['a','c','C'], |
23 | | - # Checking letters cycle (if shift is 1, Z => A, z => a): |
24 | | - ['Z becomes A and z becomes a, right?', 1] => |
25 | | - ['zaA cfdp', 'nft B bo', 'e a cfdp', 'nft b, s', 'jhiu?'], |
26 | | - ['Hello world!', 6] => ['hnN', 'krr', 'u c', 'uxr', 'j!'], |
27 | | - ['Z', 1] => ['z','a','A'], |
28 | | - # Cases where the first character is not a letter: |
29 | | - ['1 is a valid string', 2] => ['ik1 k', 'u c x', "cnkf ", "uvtkp", "i"], |
30 | | - ['123456789Z', 1] => ["za1", "234", "567", "89A"], |
31 | | - # Not valid, I need at least one letter to encode the shift: |
32 | | - ['12345--#', 2] => [] |
33 | | - } |
34 | | - end |
| 12 | + describe '7_caesar_cipher_variation' do |
| 13 | + describe '#encode_str' do |
| 14 | + let(:sample_data) do |
| 15 | + { |
| 16 | + ['I should have known that you would have a perfect answer for me!!!', 1] => |
| 17 | + ['ijJ tipvme ibw', 'f lopxo uibu z', 'pv xpvme ibwf ', 'b qfsgfdu botx', 'fs gps nf!!!'], |
| 18 | + ['Now you know your ABCs!', 1] => ['noOpx', ' zpv ', 'lopx ', 'zpvs ', 'BCDt!'], |
| 19 | + ['The same sentence, but split in 5 chunks', 0] => |
| 20 | + ['ttThe sam', 'e sentenc', 'e, but sp', 'lit in 5 ', 'chunks'], |
| 21 | + # Less than 5 chunks (small String): |
| 22 | + ['A', 2] => ['a','c','C'], |
| 23 | + # Checking letters cycle (if shift is 1, Z => A, z => a): |
| 24 | + ['Z becomes A and z becomes a, right?', 1] => |
| 25 | + ['zaA cfdp', 'nft B bo', 'e a cfdp', 'nft b, s', 'jhiu?'], |
| 26 | + ['Hello world!', 6] => ['hnN', 'krr', 'u c', 'uxr', 'j!'], |
| 27 | + ['Z', 1] => ['z','a','A'], |
| 28 | + # Cases where the first character is not a letter: |
| 29 | + ['1 is a valid string', 2] => ['ik1 k', 'u c x', "cnkf ", "uvtkp", "i"], |
| 30 | + ['123456789Z', 1] => ["za1", "234", "567", "89A"], |
| 31 | + # Not valid, I need at least one letter to encode the shift: |
| 32 | + ['12345--#', 2] => [] |
| 33 | + } |
| 34 | + end |
35 | 35 |
|
36 | | - it 'sample cases match' do |
37 | | - sample_data.each do |arg, result| |
38 | | - assert_equal(result, solution_7_1(*arg), "#{arg} should output #{result}") |
| 36 | + it 'sample cases match' do |
| 37 | + sample_data.each do |arg, result| |
| 38 | + assert_equal(result, @@solution_class.encode_str(*arg), "#{arg} should output #{result}") |
| 39 | + end |
39 | 40 | end |
40 | 41 | end |
41 | | - end |
42 | 42 |
|
43 | | - describe '#decode' do |
44 | | - let(:sample_data) do |
45 | | - { |
46 | | - ['ijJ tipvme ibw', 'f lopxo uibu z', 'pv xpvme ibwf ', 'b qfsgfdu botx', 'fs gps nf!!!'] => |
47 | | - 'I should have known that you would have a perfect answer for me!!!', |
48 | | - ['noOpx', ' zpv ', 'lopx ', 'zpvs ', 'BCDt!'] => 'Now you know your ABCs!', |
49 | | - ['ttThe sam', 'e sentenc', 'e, but sp', 'lit in 5 ', 'chunks'] => |
50 | | - 'The same sentence, but split in 5 chunks', |
51 | | - # Less than 5 chunks (small String): |
52 | | - ['a','c','C'] => 'A', |
53 | | - # Checking letters cycle (if shift is 1, Z => A, z => a): |
54 | | - ['zaA cfdp', 'nft B bo', 'e a cfdp', 'nft b, s', 'jhiu?'] => |
55 | | - 'Z becomes A and z becomes a, right?', |
56 | | - ['hnN', 'krr', 'u c', 'uxr', 'j!'] => 'Hello world!', |
57 | | - ['z','a','A'] => 'Z', |
58 | | - # Cases where the first character is not a letter: |
59 | | - ['ik1 k', 'u c x', "cnkf ", "uvtkp", "i"] => '1 is a valid string', |
60 | | - ["za1", "234", "567", "89A"] => '123456789Z' |
61 | | - } |
62 | | - end |
| 43 | + describe '#decode' do |
| 44 | + let(:sample_data) do |
| 45 | + { |
| 46 | + ['ijJ tipvme ibw', 'f lopxo uibu z', 'pv xpvme ibwf ', 'b qfsgfdu botx', 'fs gps nf!!!'] => |
| 47 | + 'I should have known that you would have a perfect answer for me!!!', |
| 48 | + ['noOpx', ' zpv ', 'lopx ', 'zpvs ', 'BCDt!'] => 'Now you know your ABCs!', |
| 49 | + ['ttThe sam', 'e sentenc', 'e, but sp', 'lit in 5 ', 'chunks'] => |
| 50 | + 'The same sentence, but split in 5 chunks', |
| 51 | + # Less than 5 chunks (small String): |
| 52 | + ['a','c','C'] => 'A', |
| 53 | + # Checking letters cycle (if shift is 1, Z => A, z => a): |
| 54 | + ['zaA cfdp', 'nft B bo', 'e a cfdp', 'nft b, s', 'jhiu?'] => |
| 55 | + 'Z becomes A and z becomes a, right?', |
| 56 | + ['hnN', 'krr', 'u c', 'uxr', 'j!'] => 'Hello world!', |
| 57 | + ['z','a','A'] => 'Z', |
| 58 | + # Cases where the first character is not a letter: |
| 59 | + ['ik1 k', 'u c x', "cnkf ", "uvtkp", "i"] => '1 is a valid string', |
| 60 | + ["za1", "234", "567", "89A"] => '123456789Z' |
| 61 | + } |
| 62 | + end |
63 | 63 |
|
64 | | - it 'sample cases match' do |
65 | | - sample_data.each do |arg, result| |
66 | | - assert_equal(result, solution_7_2(arg), "#{arg} should output #{result}") |
| 64 | + it 'sample cases match' do |
| 65 | + sample_data.each do |arg, result| |
| 66 | + assert_equal(result, @@solution_class.decode(arg), "#{arg} should output #{result}") |
| 67 | + end |
67 | 68 | end |
68 | 69 | end |
69 | 70 | end |
|
0 commit comments