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.

score_test.gno

1.52 Kb · 64 lines
 1package flag
 2
 3import "testing"
 4
 5func TestValueCurve(t *testing.T) {
 6	cases := []struct {
 7		d      Difficulty
 8		solves int
 9		want   int
10	}{
11		{Easy, 0, 100},
12		{Easy, 1, 100},
13		{Easy, 2, 100 - 60*1/400},
14		{Medium, 11, 250 - 150*100/400},
15		{Hard, 21, 200},
16		{Hard, 500, 200},
17	}
18	for _, tc := range cases {
19		if got := Value(tc.d, tc.solves); got != tc.want {
20			t.Errorf("Value(%s, %d) = %d, want %d", tc.d, tc.solves, got, tc.want)
21		}
22	}
23}
24
25func TestValueMonotonic(t *testing.T) {
26	for _, d := range []Difficulty{Easy, Medium, Hard} {
27		prev := Value(d, 0)
28		for n := 1; n <= 40; n++ {
29			v := Value(d, n)
30			if v > prev || v < d.Floor() {
31				t.Fatalf("%s: value %d at %d solves breaks the curve", d, v, n)
32			}
33			prev = v
34		}
35	}
36}
37
38func TestFirstBlood(t *testing.T) {
39	if Hard.FirstBloodBonus() != 50 || Easy.FirstBloodBonus() != 10 {
40		t.Fatal("first blood bonus should be a tenth of the initial value")
41	}
42}
43
44func TestCard(t *testing.T) {
45	l := NewLedger()
46	l.Record(ash)
47	out := Card(Info{Slug: "label", Title: "The Forged Label", Difficulty: Easy, Category: "render", Brief: "Brief."}, l)
48	want := "# The Forged Label\n\n**Easy** · render · 1 captured · worth 100 points\n\nBrief.\n"
49	if out != want {
50		t.Fatalf("Card =\n%q\nwant\n%q", out, want)
51	}
52}
53
54func TestCaptures(t *testing.T) {
55	l := NewLedger()
56	if Captures(l, 3) != "*Nobody has broken it yet.*\n" {
57		t.Fatal("empty ledger should say so")
58	}
59	l.Record(ash)
60	out := Captures(l, 3)
61	if out != "- `"+ash.String()+"` at block 123 (first)\n" {
62		t.Fatalf("Captures = %q", out)
63	}
64}