-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday9_test.go
70 lines (62 loc) · 1.49 KB
/
day9_test.go
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
67
68
69
70
package main
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestExamplePart1(t *testing.T) {
exampleInput1 := make([]string, 25)
for i := 0; i < 25; i++ {
exampleInput1[i] = fmt.Sprint(i + 1)
}
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(exampleInput1), func(i, j int) { exampleInput1[i], exampleInput1[j] = exampleInput1[j], exampleInput1[i] })
cipher := makeXmasCipher(exampleInput1)
cipher.Add(26)
assert.False(t, cipher.Broken(), "cipher: %v", cipher)
cipher = makeXmasCipher(exampleInput1)
cipher.Add(49)
assert.False(t, cipher.Broken(), "cipher: %v", cipher)
cipher = makeXmasCipher(exampleInput1)
cipher.Add(100)
assert.True(t, cipher.Broken())
assert.Equal(t, 100, cipher.weaknessTarget)
cipher = makeXmasCipher(exampleInput1)
cipher.Add(50)
assert.True(t, cipher.Broken())
assert.Equal(t, 50, cipher.weaknessTarget)
}
func TestExamplePart2(t *testing.T) {
exampleInput2 := []string{
"35",
"20",
"15",
"25",
"47",
"40",
"62",
"55",
"65",
"95",
"102",
"117",
"150",
"182",
"127",
"219",
"299",
"277",
"309",
"576",
}
cipher2 := makeXmasCipherBase(exampleInput2, 5)
assert.True(t, cipher2.Broken(), "cipher: %v", cipher2)
assert.Equal(t, 127, cipher2.weaknessTarget)
assert.Equal(t, 62, cipher2.FindWeakness())
exampleInput1 := []string{"1", "3", "5", "7", "9", "15"}
cipher := makeXmasCipherBase(exampleInput1, 5)
assert.True(t, cipher.Broken())
assert.Equal(t, 10, cipher.FindWeakness())
}