Day 9: Part 1 and 2

Signed-off-by: James Griffin <james@unsupervised.ca>
This commit is contained in:
2020-12-09 11:24:19 -04:00
parent a5386931db
commit 1cb55213bc
5 changed files with 1207 additions and 3 deletions

45
nine/day_nine_test.go Normal file
View File

@@ -0,0 +1,45 @@
package nine
import "testing"
func Test_program_load(t *testing.T) {
x := xmas{}
err := x.load("sample.txt", 5)
if err != nil {
t.Log(err)
t.FailNow()
}
if len(x.values) != 20 {
t.Logf("Expected 20 values, Got %d values", len(x.values))
t.FailNow()
}
}
func Test_weakness_detection(t *testing.T) {
x, err := newXmas("sample.txt", 5)
if err != nil {
t.Log(err)
t.FailNow()
}
v, err := x.detectVulnerability()
if err != nil || v != 127 {
t.Logf("Expected vulnerability of 127, Got vulnerability %d", v)
t.FailNow()
}
}
func Test_weakness_compute(t *testing.T) {
x, err := newXmas("sample.txt", 5)
if err != nil {
t.Log(err)
t.FailNow()
}
e, err := x.computeWeakness()
if err != nil || e != 62 {
t.Logf("Expected weaknes 62, Got weakness %d", e)
t.FailNow()
}
}