1package mgdoc23import (4 "hash/fnv"5 "math"6 "testing"7)89func TestClaimRefusesAnOccupiedID(t *testing.T) {10 space := NewIDSpace()11 hash := fnv.New32a()12 _, _ = hash.Write([]byte("some-seed"))13 occupied := int64(hash.Sum32() & 0x7fffffff)14 space.seen[occupied] = "already-here"15 if _, err := space.Claim("some-seed"); err == nil {16 t.Fatal("claiming an occupied id did not fail")17 }18}1920func TestClaimStaysWithinPositiveInt31(t *testing.T) {21 space := NewIDSpace()22 for _, seed := range []string{"a", "b", "some:longer:seed", "ign:marker:x"} {23 id, err := space.Claim(seed)24 if err != nil {25 t.Fatal(err)26 }27 if id <= 0 || id > math.MaxInt32 {28 t.Fatalf("Claim(%q) = %d, outside the positive int31 range", seed, id)29 }30 }31}3233// TestSyntheticCoordinatesInvertTheViewer projects the synthetic coordinates34// with the viewer's own formula and expects the original pixel back.35func TestSyntheticCoordinatesInvertTheViewer(t *testing.T) {36 for _, pixel := range [][2]float64{{0, 0}, {4096, 4096}, {8192, 8192}, {123.5, 7000.25}} {37 latitude := SyntheticLatitude(pixel[1])38 longitude := SyntheticLongitude(pixel[0])39 worldTiles := math.Pow(2, SourceZoom)40 x := ((longitude + 180) / 360) * worldTiles * TileSize41 y := (1 - math.Asinh(math.Tan(latitude*math.Pi/180))/math.Pi) / 2 * worldTiles * TileSize42 if math.Abs(x-pixel[0]) > 1e-6 || math.Abs(y-pixel[1]) > 1e-6 {43 t.Fatalf("pixel %v round-tripped to %.8f,%.8f", pixel, x, y)44 }45 }46}4748func TestSpellOut(t *testing.T) {49 cases := map[string]string{50 "night-city": "Night City",51 "ncpd-scanner-hustles": "Ncpd Scanner Hustles",52 "collectibles": "Collectibles",53 }54 for slug, want := range cases {55 if got := SpellOut(slug); got != want {56 t.Errorf("SpellOut(%q) = %q, want %q", slug, got, want)57 }58 }59}