# HG changeset patch # User Mikael Berthe # Date 1473111729 -7200 # Node ID d41c4f8fe066cd38ee98a3095e00e28e565a0f9f # Parent 6a396d691a7d6a4b1cc0e172937400f28459107f Add some checks diff -r 6a396d691a7d -r d41c4f8fe066 takuzu.go --- a/takuzu.go Fri Sep 02 22:37:34 2016 +0200 +++ b/takuzu.go Mon Sep 05 23:42:09 2016 +0200 @@ -40,12 +40,17 @@ // NewFromString creates a new Takuzu board from a string definition func NewFromString(s string) (*Takuzu, error) { l := len(s) - // TODO: validate chars ([.01OI]) + if l < 4 { + return nil, errors.New("bad string length") + } + size := int(math.Sqrt(float64(l))) if size*size != l { return nil, errors.New("bad string length") } + // TODO: validate chars ([.01OI]) + i := 0 t := New(size) @@ -117,11 +122,18 @@ func BoardsMatch(t1, t2 *Takuzu, ignoreUndefined bool) (match bool, line, col int) { match = true + if t1 == nil || t2 == nil { + line, col = -1, -1 + match = false + return + } + if t1.Size != t2.Size { line, col = -1, -1 match = false return } + for line = range t1.Board { for col = range t1.Board[line] { if !t1.Board[line][col].Defined || !t2.Board[line][col].Defined {