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.

profile_test.gno

1.61 Kb · 51 lines
 1package brawl
 2
 3import "testing"
 4
 5func TestProfileRoundTrip(t *testing.T) {
 6	for _, s := range []string{"c1t3i1f6j8r6a7b2s5d4k0", "c0t3i0f9j9r8a9b9s9d9k5", "c4t9i9f0j0r1a0b0s0d0k0"} {
 7		if got := MustProfile(s).String(); got != s {
 8			t.Errorf("%s came back as %s", s, got)
 9		}
10	}
11}
12
13func TestProfileRefused(t *testing.T) {
14	for _, s := range []string{"", "c5t3i1f6j8r6a7b2s5d4k0", "c1t1i1f6j8r6a7b2s5d4k0", "c1t2i1f6j8r6a7b2s5d4k0", "c1t3i1f6j8r9a7b2s5d4k0", "c1t3i1f6j8r6a7b2s5d4k6", "t3c1i1f6j8r6a7b2s5d4k0"} {
15		if _, err := ParseProfile(s); err == nil {
16			t.Errorf("%q should be refused", s)
17		}
18	}
19}
20
21// the busiest profile allowed: re-plans every 2 ticks, looks 8 squares out
22func TestGasVersusProfileBusy(t *testing.T) {
23	VersusProfile(3, Hunter, "c0t3i0f9j9r8a9b9s9d9k5", gen(77))
24}
25func TestGasVersusProfileCollector(t *testing.T) {
26	VersusProfile(3, Hunter, "c4t3i0f0j9r8a0b0s9d0k0", gen(77))
27}
28func TestGasVersusProfileTypical(t *testing.T) {
29	VersusProfile(3, Hunter, "c1t3i1f6j8r6a7b2s5d4k0", gen(77))
30}
31
32// a profile bot saved and restored every 37 ticks plays the same match
33func TestProfileSnapshot(t *testing.T) {
34	p := MustProfile("c2t4i2f1j5r4a3b6s9d8k3")
35	inA := gen(91)
36	a, b := VersusProfile(12, Brawler, p.String(), inA)
37	g := New(12, Brawler, p.Class)
38	var bot Actor = NewProfileBot(p, 12)
39	for i := 0; i < Ticks; i++ {
40		if i%37 == 0 {
41			bot = RestoreActor(bot.Snapshot())
42			g = Restore(g.Snapshot())
43		}
44		m0, a0 := in(inA, i)
45		m1, a1 := bot.Act(g, 1)
46		g.Step(m0, a0, m1, a1)
47	}
48	if g.F[0].Gold != a || g.F[1].Gold != b {
49		t.Errorf("restored match %d-%d, straight match %d-%d", g.F[0].Gold, g.F[1].Gold, a, b)
50	}
51}