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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
package game
import (
"reflect"
"testing"
"thehouseoficarus/internal/player"
)
func TestRewritePlayerRoomIDsRename(t *testing.T) {
p := &player.Player{
RoomID: 10,
EnterSeqRoom: 20,
Flags: map[string]any{
"hidden_exit_10_north": 1,
"hidden_exit_20_down": 1,
"unrelated_flag": 1,
},
MapSymbols: map[int]player.MapSymbolData{
10: {Char: "X"},
30: {Char: "Y"},
},
}
p.Stats.RoomsVisited = map[int]bool{10: true, 40: true}
idMap := map[int]int{10: 100, 20: 200}
if !rewritePlayerRoomIDs(p, idMap) {
t.Fatal("expected changed=true")
}
if p.RoomID != 100 {
t.Errorf("RoomID = %d, want 100", p.RoomID)
}
if p.EnterSeqRoom != 200 {
t.Errorf("EnterSeqRoom = %d, want 200", p.EnterSeqRoom)
}
wantFlags := map[string]any{
"hidden_exit_100_north": 1,
"hidden_exit_200_down": 1,
"unrelated_flag": 1,
}
if !reflect.DeepEqual(p.Flags, wantFlags) {
t.Errorf("Flags = %v, want %v", p.Flags, wantFlags)
}
if _, ok := p.MapSymbols[100]; !ok {
t.Error("MapSymbols missing key 100")
}
if _, ok := p.MapSymbols[30]; !ok {
t.Error("MapSymbols missing unchanged key 30")
}
if _, ok := p.MapSymbols[10]; ok {
t.Error("MapSymbols should not still have key 10")
}
if !p.Stats.RoomsVisited[100] {
t.Error("RoomsVisited missing key 100")
}
if !p.Stats.RoomsVisited[40] {
t.Error("RoomsVisited missing unchanged key 40")
}
if p.Stats.RoomsVisited[10] {
t.Error("RoomsVisited should not still have key 10")
}
}
func TestRewritePlayerRoomIDsNoChange(t *testing.T) {
p := &player.Player{
RoomID: 5,
Flags: map[string]any{"hidden_exit_5_north": 1},
}
if rewritePlayerRoomIDs(p, map[int]int{99: 100}) {
t.Error("expected changed=false when no embedded ID matches")
}
if p.RoomID != 5 {
t.Errorf("RoomID = %d, want 5 (untouched)", p.RoomID)
}
if _, ok := p.Flags["hidden_exit_5_north"]; !ok {
t.Error("hidden_exit_5_north should be unchanged")
}
}
// A swap idMap (A<->B) must not clobber a flag whose old key maps to another
// flag's old key and vice versa.
func TestRewritePlayerRoomIDsSwap(t *testing.T) {
p := &player.Player{
RoomID: 10,
Flags: map[string]any{
"hidden_exit_10_north": 1,
"hidden_exit_100_east": 1,
},
}
swap := map[int]int{10: 100, 100: 10}
if !rewritePlayerRoomIDs(p, swap) {
t.Fatal("expected changed=true")
}
if p.RoomID != 100 {
t.Errorf("RoomID = %d, want 100", p.RoomID)
}
wantFlags := map[string]any{
"hidden_exit_100_north": 1,
"hidden_exit_10_east": 1,
}
if !reflect.DeepEqual(p.Flags, wantFlags) {
t.Errorf("Flags = %v, want %v", p.Flags, wantFlags)
}
}
|