package engine

import "testing"

// TestAbortFinishesAsDrawWithoutAdjustment covers Abort, the graceful close used when a
// committed game can no longer be reconstructed from its journal. The game ends as a draw
// (no winner) regardless of the running scores, and the scores are left untouched (no
// end-game rack adjustment).
func TestAbortFinishesAsDrawWithoutAdjustment(t *testing.T) {
	g, err := New(testReg, Options{Variant: VariantEnglish, Version: testVersion, Players: 2, Seed: 1})
	if err != nil {
		t.Fatalf("new game: %v", err)
	}
	g.scores[0], g.scores[1] = 10, 5 // a clear leader, so a draw cannot come from equal scores

	g.Abort()

	if !g.Over() {
		t.Error("aborted game should be over")
	}
	if g.Reason() != EndAborted {
		t.Errorf("reason = %v, want EndAborted", g.Reason())
	}
	res := g.Result()
	if res.Winner != -1 {
		t.Errorf("winner = %d, want -1 (draw)", res.Winner)
	}
	if res.Scores[0] != 10 || res.Scores[1] != 5 {
		t.Errorf("scores = %v, want [10 5] (no rack adjustment on abort)", res.Scores)
	}
}
