test: lobby, session, store tests — deep copy, logs, inventory, stats
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,3 +53,41 @@ func TestRanking(t *testing.T) {
|
||||
t.Errorf("Top player: got %q, want Charlie", rankings[0].Player)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetStats(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
db, err := Open(dir + "/test.db")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
// Save some runs
|
||||
db.SaveRun("Alice", 5, 100)
|
||||
db.SaveRun("Alice", 10, 250)
|
||||
db.SaveRun("Alice", 20, 500) // victory (floor >= 20)
|
||||
db.SaveRun("Bob", 3, 50)
|
||||
|
||||
stats, err := db.GetStats("Alice")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stats.TotalRuns != 3 {
|
||||
t.Errorf("expected 3 total runs, got %d", stats.TotalRuns)
|
||||
}
|
||||
if stats.BestFloor != 20 {
|
||||
t.Errorf("expected best floor 20, got %d", stats.BestFloor)
|
||||
}
|
||||
if stats.Victories != 1 {
|
||||
t.Errorf("expected 1 victory, got %d", stats.Victories)
|
||||
}
|
||||
if stats.TotalGold != 850 { // 100+250+500
|
||||
t.Errorf("expected total gold 850, got %d", stats.TotalGold)
|
||||
}
|
||||
|
||||
// Bob's stats should be separate
|
||||
bobStats, _ := db.GetStats("Bob")
|
||||
if bobStats.TotalRuns != 1 {
|
||||
t.Errorf("Bob should have 1 run, got %d", bobStats.TotalRuns)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user