Skip to content

Commit 5a9ce5d

Browse files
committed
Special details for the Caesar Cipher exercise specs
1 parent 2042a8e commit 5a9ce5d

File tree

2 files changed

+65
-64
lines changed

2 files changed

+65
-64
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,30 +92,30 @@ To run all the specs, run `rake`:
9292

9393
```Shell
9494
rake
95-
Run options: --seed 51435
95+
Run options: --seed 33218
9696

9797
# Running:
9898

99-
.........
99+
..........
100100

101-
Finished in 0.113061s, 79.6030 runs/s, 902.1679 assertions/s.
101+
Finished in 0.110904s, 90.1681 runs/s, 919.7143 assertions/s.
102102

103-
9 runs, 102 assertions, 0 failures, 0 errors, 0 skips
103+
10 runs, 102 assertions, 0 failures, 0 errors, 0 skips
104104
```
105105

106106
The tests can also be run independently, for each exercise:
107107

108108
```Shell
109109
rake test TEST=spec/7_caesar_cipher_variation_spec.rb
110-
Run options: --seed 62243
110+
Run options: --seed 37685
111111

112112
# Running:
113113

114-
.
114+
..
115115

116-
Finished in 0.000786s, 1272.2644 runs/s, 24173.0229 assertions/s.
116+
Finished in 0.000713s, 2805.0488 runs/s, 26647.9636 assertions/s.
117117

118-
1 runs, 19 assertions, 0 failures, 0 errors, 0 skips
118+
2 runs, 19 assertions, 0 failures, 0 errors, 0 skips
119119
```
120120

121121
See the exercises' specs under the `spec/` folder`.

spec/7_caesar_cipher_variation_spec.rb

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,69 @@
22

33
require_relative 'spec_helper'
44

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'
1211

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
3535

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
3940
end
4041
end
41-
end
4242

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
6363

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
6768
end
6869
end
6970
end

0 commit comments

Comments
 (0)