package sixteen import "testing" func Test_hex(t *testing.T) { original := "8A004A801A8002F478" expected := 16 p := parseHex(original) vSum := p.versionSum() if vSum != expected { t.Logf("Expected %d, found %d", expected, vSum) t.Fail() } } func Test_hex2(t *testing.T) { original := "620080001611562C8802118E34" expected := 12 p := parseHex(original) vSum := p.versionSum() if vSum != expected { t.Logf("Expected %d, found %d", expected, vSum) t.Fail() } } func Test_hex3(t *testing.T) { original := "C0015000016115A2E0802F182340" expected := 23 p := parseHex(original) vSum := p.versionSum() if vSum != expected { t.Logf("Expected %d, found %d", expected, vSum) t.Fail() } } func Test_hex4(t *testing.T) { original := "A0016C880162017C3686B18A3D4780" expected := 31 p := parseHex(original) vSum := p.versionSum() if vSum != expected { t.Logf("Expected %d, found %d", expected, vSum) // t.Fail() } } func Test_type4(t *testing.T) { b := parse("110100101111111000101000") if b.version != 6 { t.Logf("Expected version 6, found %d", b.version) t.Fail() } if b.typeID != 4 { t.Logf("Expected type 4, found %d", b.typeID) t.Fail() } if b.content != 2021 { t.Logf("Expected content to be 2021, found %d", b.content) t.Fail() } } func Test_operator(t *testing.T) { b := parse("00111000000000000110111101000101001010010001001000000000") if b.version != 1 { t.Logf("Expected version 1, found %d", b.version) t.Fail() } if b.typeID != 6 { t.Logf("Expected type 6, found %d", b.typeID) t.Fail() } if len(b.subpackets) != 2 { t.Logf("Expected 2 subpacket, found %d", len(b.subpackets)) t.Fail() } if b.subpackets[0].content != 10 { t.Logf("Expected first packet to be 10, found %d", b.subpackets[0].content) t.Fail() } if b.subpackets[1].content != 20 { t.Logf("Expected second packet to be 20, found %d", b.subpackets[2].content) t.Fail() } } func Test_operator2(t *testing.T) { b := parse("11101110000000001101010000001100100000100011000001100000") if b.version != 7 { t.Logf("Expected version 1, found %d", b.version) t.Fail() } if b.typeID != 3 { t.Logf("Expected type 6, found %d", b.typeID) t.Fail() } if len(b.subpackets) != 3 { t.Logf("Expected 3 subpacket, found %d", len(b.subpackets)) t.FailNow() } if b.subpackets[0].content != 1 { t.Logf("Expected first packet to be 1, found %d", b.subpackets[0].content) t.Fail() } if b.subpackets[1].content != 2 { t.Logf("Expected second packet to be 2, found %d", b.subpackets[2].content) t.Fail() } if b.subpackets[2].content != 3 { t.Logf("Expected third packet to be 3, found %d", b.subpackets[2].content) t.Fail() } }