Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

snapshot_test.gno

1.13 Kb · 32 lines
 1package brawl
 2
 3import "testing"
 4
 5// A match stopped, packed and restored part-way gives the same result as one
 6// played straight through, for every arena and with bots on both sides.
 7func TestSnapshot(t *testing.T) {
 8	for seed := uint32(3); seed < 6; seed++ {
 9		straight := NewLength(seed, Reader, Brawler, 900)
10		a1, b1 := NewBot(Hard, seed), NewBot(Normal, seed+1)
11		for !straight.Over() {
12			m0, x0 := a1.Act(straight, 0)
13			m1, x1 := b1.Act(straight, 1)
14			straight.Step(m0, x0, m1, x1)
15		}
16		g := NewLength(seed, Reader, Brawler, 900)
17		a2, b2 := NewBot(Hard, seed), NewBot(Normal, seed+1)
18		for !g.Over() {
19			if g.T%137 == 0 {
20				g = Restore(g.Snapshot())
21				a2, b2 = RestoreBot(a2.Snapshot()), RestoreBot(b2.Snapshot())
22			}
23			m0, x0 := a2.Act(g, 0)
24			m1, x1 := b2.Act(g, 1)
25			g.Step(m0, x0, m1, x1)
26		}
27		if g.F[0].Gold != straight.F[0].Gold || g.F[1].Gold != straight.F[1].Gold || g.F[0].X != straight.F[0].X {
28			t.Fatalf("seed %d: restored %d-%d, straight %d-%d", seed, g.F[0].Gold, g.F[1].Gold, straight.F[0].Gold, straight.F[1].Gold)
29		}
30		t.Logf("seed %d: %d-%d, snapshot %d bytes", seed, g.F[0].Gold, g.F[1].Gold, len(g.Snapshot()))
31	}
32}