1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package game
import (
"testing"
"thehouseoficarus/internal/player"
)
// TestMapDimensionsClamped: the player-settable map size drives a direct
// mapHeight x mapWidth allocation in buildFullMap, so an unbounded option
// value is a fatal out-of-memory kill reachable by any authenticated player
// (and persisted in the account file, so it repeats on login). The clamp must
// cap both dimensions while leaving ordinary values alone.
func TestMapDimensionsClamped(t *testing.T) {
p := player.New("mapper")
p.Options = map[string]any{"map_width": 100000, "map_height": 100000}
w, h := mapDimensions(p)
if w != maxMapDimension || h != maxMapDimension {
t.Fatalf("huge map dimensions = (%d,%d), want (%d,%d)", w, h, maxMapDimension, maxMapDimension)
}
p.Options = map[string]any{"map_width": -5, "map_height": 0}
w, h = mapDimensions(p)
if w != 5 || h != 5 {
t.Fatalf("undersized map dimensions = (%d,%d), want (5,5)", w, h)
}
p.Options = map[string]any{"map_width": 30, "map_height": 20}
w, h = mapDimensions(p)
if w != 30 || h != 20 {
t.Fatalf("normal map dimensions = (%d,%d), want (30,20)", w, h)
}
}
|