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

zz_bounds_test.gno

0.78 Kb · 27 lines
 1package collatz
 2
 3import (
 4	"strconv"
 5	"testing"
 6
 7	"gno.land/p/nt/uassert/v0"
 8)
 9
10// Anyone may Compute, and each new n is an entry the root page sorts: the
11// leaderboard refuses a new n once it is full, and still updates an old one.
12func TestLeaderboardIsBounded(cur realm, t *testing.T) {
13	var added []string
14	for i := 1; results.Size() < MaxResults; i++ {
15		k := strconv.Itoa(1_000_000 + i)
16		results.Set(k, Result{N: int64(1_000_000 + i)})
17		added = append(added, k)
18	}
19	// One realm state per package run: leave the board as it was found.
20	defer func() {
21		for _, k := range added {
22			results.Remove(k)
23		}
24	}()
25	uassert.AbortsContains(t, cur, "leaderboard is full", func() { Compute(cross(cur), 999_999_937) })
26	Compute(cross(cur), 1_000_001) // an n already recorded is refreshed, not refused
27}