aboutsummaryrefslogtreecommitdiff
path: root/internal/world/ground_quality_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/world/ground_quality_test.go')
-rw-r--r--internal/world/ground_quality_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/world/ground_quality_test.go b/internal/world/ground_quality_test.go
new file mode 100644
index 0000000..e287642
--- /dev/null
+++ b/internal/world/ground_quality_test.go
@@ -0,0 +1,43 @@
+package world
+
+import "testing"
+
+// TestGroundPreservesQualityAcrossDropAndPickup pins the deferred item-quality
+// fix: a partially-used max_quality item dropped on the ground must not come
+// back at full quality when picked up.
+func TestGroundPreservesQualityAcrossDropAndPickup(t *testing.T) {
+ w := New(t.TempDir())
+ w.AddGroundItemQ(1, "lighter", 1, 42, 100)
+
+ if q, mq, ok := w.AccessibleGroundQuality(1, "lighter", "alice"); !ok || q != 42 || mq != 100 {
+ t.Fatalf("ground quality = (%d,%d,%v), want (42,100,true)", q, mq, ok)
+ }
+ removed, q, mq, ok := w.RemoveReservedItemQ(1, "lighter", 1, "alice")
+ if !ok || removed != 1 || q != 42 || mq != 100 {
+ t.Fatalf("pickup = (%d,%d,%d,%v), want (1,42,100,true)", removed, q, mq, ok)
+ }
+}
+
+// TestGroundMergeRequiresMatchingQuality: a full-quality spawn stack must not
+// absorb a used player-dropped stack (which would erase the charge).
+func TestGroundMergeRequiresMatchingQuality(t *testing.T) {
+ w := New(t.TempDir())
+ w.AddGroundItemQ(1, "lighter", 1, 100, 100)
+ w.AddGroundItemQ(1, "lighter", 1, 20, 100)
+ if got := len(w.GroundItemsDetailed(1)); got != 2 {
+ t.Fatalf("distinct-quality entries merged: %d entries, want 2", got)
+ }
+}
+
+// TestRemoveGroundItemSkipsReserved: the firemaking helper has no owner, so it
+// must never consume another player's reserved loot.
+func TestRemoveGroundItemSkipsReserved(t *testing.T) {
+ w := New(t.TempDir())
+ w.AddReservedItem(1, "log", 3, "bob")
+ if got := w.RemoveGroundItem(1, "log", 3); got != 0 {
+ t.Fatalf("RemoveGroundItem consumed a reserved stack: took %d", got)
+ }
+ if got := w.AccessibleGround(1, "bob")["log"]; got != 3 {
+ t.Fatalf("bob's reserved stock = %d, want 3", got)
+ }
+}