From 153db2534312b8cc387a6bb4b46f8cb42ee1916b Mon Sep 17 00:00:00 2001 From: onyx Date: Mon, 4 Dec 2023 03:14:22 +0000 Subject: [PATCH] fill in CheckDigit test --- day-3/one_test.go | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/day-3/one_test.go b/day-3/one_test.go index 97265cc..9405c37 100644 --- a/day-3/one_test.go +++ b/day-3/one_test.go @@ -34,4 +34,71 @@ func TestSymbolToBool(t *testing.T) { func TestCheckDigit(t *testing.T) { //t.Skip("skipping test") + symbols := [][]bool{ + {false, false, false, false, false, false, false, false, false, false}, + {false, false, false, true, false, false, false, false, false, false}, + {false, false, false, false, false, false, false, false, false, false}, + {false, false, false, false, false, false, true, false, false, false}, + } + + d1 := func() digit { + var d digit = digit{row: 0, col: 2, raw: 0, pass: false} + i := d.col - 1 + for ; i < len(symbols[d.row]) && i <= d.col+1; i += 1 { + if i < 0 { + continue + } + if d.row != 0 { + if symbols[d.row-1][i] { + d.pass = true + break + } + } + if symbols[d.row][i] { + d.pass = true + break + } + if d.row != len(symbols)-1 { + if symbols[d.row+1][i] { + d.pass = true + break + } + } + } + return d + }() + d2 := func() digit { + var d digit = digit{row: 2, col: 9, raw: 0, pass: false} + i := d.col - 1 + for ; i < len(symbols[d.row]) && i <= d.col+1; i += 1 { + if i < 0 { + continue + } + if d.row != 0 { + if symbols[d.row-1][i] { + d.pass = true + break + } + } + if symbols[d.row][i] { + d.pass = true + break + } + if d.row != len(symbols)-1 { + if symbols[d.row+1][i] { + d.pass = true + break + } + } + } + return d + }() + + t.Run("Should pass the check", func(t *testing.T) { + assert.Equal(t, true, d1.pass) + }) + + t.Run("Should fail the check", func(t *testing.T) { + assert.Equal(t, false, d2.pass) + }) }