-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_4_tests.rb
66 lines (55 loc) · 1.55 KB
/
day_4_tests.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'minitest/autorun'
require './day_4'
class Day4Test < Minitest::Test
def test_count_letter_frequencies
str = 'aaaaa-bbb-z-y-x-'
expected_counts = {'a' => 5, 'b' => 3, 'z' => 1, 'y' => 1, 'x' => 1}
assert_equal expected_counts, count_letter_frequencies(str)
end
def test_group_letters_by_count
freq = {'a' => 5, 'b' => 3, 'z' => 1, 'y' => 1, 'x' => 1}
expected_grouping = {5 => 'a', 3 => 'b', 1 => 'xyz'}
assert_equal expected_grouping, group_letters_by_count(freq)
end
def test_checksum_for_name
test_cases = [
{
name: 'aaaaa-bbb-z-y-x-',
expected_checksum: 'abxyz'
},
{
name: 'a-b-c-d-e-f-g-h-',
expected_checksum: 'abcde'
},
{
name: 'not-a-real-room-',
expected_checksum: 'oarel'
}
]
test_cases.each do |test_case|
assert_equal test_case[:expected_checksum], checksum_for_name(test_case[:name])
end
end
def test_real?
test_cases = [
{
name: 'aaaaa-bbb-z-y-x-',
checksum: 'abxyz',
expected_result: true
},
{
name: 'totally-real-room-',
checksum: 'decoy',
expected_result: false
}
]
test_cases.each do |test_case|
assert_equal test_case[:expected_result], real_room?(test_case[:name], test_case[:checksum])
end
end
def test_decrypted_name
encrypted_name = 'qzmt-zixmtkozy-ivhz'
expected_decrypted_name = 'very encrypted name'
assert_equal expected_decrypted_name, decrypted_name(encrypted_name, 343)
end
end