aboutsummaryrefslogtreecommitdiff
path: root/internal/world/ground_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-16 14:09:22 -0400
committerhistoria <[not public]>2026-09-16 14:09:22 -0400
commit2f34e75f27e5f99cfc1c5f8eaf6ab4ff2fddb1d9 (patch)
treec50388fe639286bda1b1999ca6c2c972d03eb3a5 /internal/world/ground_test.go
parentc054b27f628f23fecc505b9e09e78721738f3c4e (diff)
downloadthehouseoficarus-2f34e75f27e5f99cfc1c5f8eaf6ab4ff2fddb1d9.tar.gz
fix: reserved-loot pickup, credit pickup, payout recovery, and slot stake/bonus shutdown handling
Diffstat (limited to 'internal/world/ground_test.go')
-rw-r--r--internal/world/ground_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/world/ground_test.go b/internal/world/ground_test.go
new file mode 100644
index 0000000..ef77766
--- /dev/null
+++ b/internal/world/ground_test.go
@@ -0,0 +1,50 @@
+package world
+
+import "testing"
+
+// TestRemoveReservedItemSkipsOtherPlayersReservations: the take loop must
+// apply the same ownership check as the availability pass. With a stack
+// reserved for Bob stored before a public stack, Alice's pickup must take
+// the public stack only — consuming Bob's reservation instead silently
+// destroys his loot while telling Alice the ground still holds it.
+func TestRemoveReservedItemSkipsOtherPlayersReservations(t *testing.T) {
+ w := New(t.TempDir())
+ w.AddReservedItem(1, "ore", 10, "bob")
+ w.AddGroundItem(1, "ore", 10)
+
+ taken, ok := w.RemoveReservedItem(1, "ore", 10, "alice")
+ if !ok || taken != 10 {
+ t.Fatalf("alice's pickup of the public stack = (%d, %v), want (10, true)", taken, ok)
+ }
+ if got := w.AccessibleGround(1, "alice")["ore"]; got != 0 {
+ t.Errorf("alice still sees %d ore after taking the public stack; removal consumed reserved stock", got)
+ }
+ // Bob's reserved stack must be untouched and still his to take.
+ if got := w.AccessibleGround(1, "bob")["ore"]; got != 10 {
+ t.Errorf("bob's reserved stack = %d, want 10", got)
+ }
+ bobTaken, ok := w.RemoveReservedItem(1, "ore", 10, "bob")
+ if !ok || bobTaken != 10 {
+ t.Errorf("bob's pickup of his own reservation = (%d, %v), want (10, true)", bobTaken, ok)
+ }
+}
+
+// TestRemoveAvailableItemTakesAccessibleStock: a request far larger than
+// the ground stock succeeds and takes exactly what is accessible, skipping
+// entries reserved for other players.
+func TestRemoveAvailableItemTakesAccessibleStock(t *testing.T) {
+ w := New(t.TempDir())
+ w.AddReservedItem(1, "credits", 10, "bob")
+ w.AddGroundItem(1, "credits", 5)
+
+ taken := w.RemoveAvailableItem(1, "credits", 999999, "alice")
+ if taken != 5 {
+ t.Fatalf("remove-available took %d, want the 5 accessible credits", taken)
+ }
+ if got := w.AccessibleGround(1, "alice")["credits"]; got != 0 {
+ t.Errorf("alice still sees %d accessible credits", got)
+ }
+ if got := w.AccessibleGround(1, "bob")["credits"]; got != 10 {
+ t.Errorf("bob's reserved credits = %d, want 10", got)
+ }
+}