Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions move.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (m *Move) SetCommand(key, value string) {
m.command[key] = value
}

func (m *Move) SetComment(comment string) {
m.comments = comment
}

func (m *Move) AddComment(comment string) {
comments := strings.Builder{}
comments.WriteString(m.comments)
Expand Down
97 changes: 97 additions & 0 deletions move_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,103 @@ func countMoves(t *testing.T, originalPosition *Position, positions []*Position,
countMoves(t, originalPosition, newPositions, nodesPerDepth[1:], maxDepth)
}

func Test_SetCommentUpdatesComment(t *testing.T) {
move := &Move{}
move.SetComment("Initial comment")
expected := "Initial comment"
if move.Comments() != expected {
t.Fatalf("expected %v but got %v", expected, move.Comments())
}
}

func Test_SetCommentOverwritesExistingComment(t *testing.T) {
move := &Move{comments: "Old comment"}
move.SetComment("New comment")
expected := "New comment"
if move.Comments() != expected {
t.Fatalf("expected %v but got %v", expected, move.Comments())
}
}

func Test_SetCommentWithEmptyString(t *testing.T) {
move := &Move{comments: "Existing comment"}
move.SetComment("")
expected := ""
if move.Comments() != expected {
t.Fatalf("expected %v but got %v", expected, move.Comments())
}
}

func TestAddComment(t *testing.T) {
t.Run("AddCommentAppendsToExistingComment", func(t *testing.T) {
move := &Move{comments: "Initial comment. "}
move.AddComment("Additional comment.")
expected := "Initial comment. Additional comment."
if move.Comments() != expected {
t.Fatalf("expected %v but got %v", expected, move.Comments())
}
})

t.Run("AddCommentToEmptyComment", func(t *testing.T) {
move := &Move{}
move.AddComment("First comment.")
expected := "First comment."
if move.Comments() != expected {
t.Fatalf("expected %v but got %v", expected, move.Comments())
}
})
}

func TestNAGReturnsCorrectValue(t *testing.T) {
t.Run("NAGReturnsCorrectValue", func(t *testing.T) {
move := &Move{nag: "!!"}
expected := "!!"
if move.NAG() != expected {
t.Fatalf("expected %v but got %v", expected, move.NAG())
}
})
}

func TestSetNAGUpdatesNAG(t *testing.T) {
t.Run("SetNAGUpdatesNAG", func(t *testing.T) {
move := &Move{}
move.SetNAG("??")
expected := "??"
if move.NAG() != expected {
t.Fatalf("expected %v but got %v", expected, move.NAG())
}
})
}

func TestGetCommand(t *testing.T) {
t.Run("GetCommandReturnsValueIfExists", func(t *testing.T) {
move := &Move{command: map[string]string{"key": "value"}}
value, ok := move.GetCommand("key")
if !ok || value != "value" {
t.Fatalf("expected value to be 'value' and ok to be true, but got value: %v, ok: %v", value, ok)
}
})

t.Run("GetCommandReturnsFalseIfKeyDoesNotExist", func(t *testing.T) {
move := &Move{command: map[string]string{"key": "value"}}
_, ok := move.GetCommand("nonexistent")
if ok {
t.Fatalf("expected ok to be false, but got true")
}
})

t.Run("GetCommandInitializesCommandMapIfNil", func(t *testing.T) {
move := &Move{}
_, ok := move.GetCommand("key")
if ok {
t.Fatalf("expected ok to be false, but got true")
}
if move.command == nil {
t.Fatalf("expected command map to be initialized, but it was nil")
}
})
}

func BenchmarkValidMoves(b *testing.B) {
pos := unsafeFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
b.ResetTimer()
Expand Down
Loading