2023-12-03 23:57:05 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/go-playground/assert/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSymbolToBool(t *testing.T) {
|
|
|
|
//t.Skip("skipping test")
|
|
|
|
input := []string{
|
|
|
|
"467..114..",
|
|
|
|
"...*......",
|
|
|
|
"..35..633.",
|
|
|
|
"......#...",
|
|
|
|
}
|
|
|
|
|
|
|
|
expected := [][]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},
|
|
|
|
}
|
|
|
|
|
|
|
|
bool_matrix := [][]bool{}
|
|
|
|
for _, line := range input {
|
|
|
|
bool_matrix = append(bool_matrix, symbolToBool(line))
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Should produce equal boolean matrices", func(t *testing.T) {
|
|
|
|
assert.Equal(t, expected, bool_matrix)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckDigit(t *testing.T) {
|
|
|
|
//t.Skip("skipping test")
|
2023-12-04 03:14:22 +00:00
|
|
|
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)
|
|
|
|
})
|
2023-12-03 23:57:05 +00:00
|
|
|
}
|