fill in CheckDigit test

This commit is contained in:
onyx 2023-12-04 03:14:22 +00:00
parent df7fa4b973
commit 153db25343

View File

@ -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)
})
}