PathrockNetwork Gno Explorer
HomeBlocksTransactionsTokensRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/g1sw5xklxjjuv0yvuxy5f5s3l3mnj0nqq626a9wr/canvas/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
g1sw5xklxjjuv0yvuxy5f5s3l3mnj0nqq626a9wr / canvas
Files
4 (README)(gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/g1sw5xklxjjuv0yvuxy5f5s3l3mnj0nqq626a9wr/canvas/v0
gno
0.9

Files (4)

  • README.mdmarkdown
  • gnomod.tomltoml
  • canvas.gnogno
  • canvas_test.gnogno
canvas_test.gnogno
1package canvas23import (4	"testing"56	"gno.land/p/nt/uassert/v0"7)89func TestNewRejectsBadSizes(t *testing.T) {10	for _, tc := range []struct{ w, h int }{{0, 1}, {1, 0}, {-1, 1}, {MaxSide + 1, 1}, {1, MaxSide + 1}} {11		func() {12			defer func() {13				if r := recover(); r == nil {14					t.Errorf("New(%d, %d) did not panic", tc.w, tc.h)15				}16			}()17			New(tc.w, tc.h)18		}()19	}20}2122func TestSetGet(t *testing.T) {23	c := New(4, 3)24	uassert.Equal(t, 4, c.Width())25	uassert.Equal(t, 3, c.Height())26	uassert.Equal(t, 0, c.Painted())27	uassert.Equal(t, Blank, c.Get(3, 2))2829	c.Set(Pixel{X: 3, Y: 2, Color: 6})30	uassert.Equal(t, byte(6), c.Get(3, 2))31	uassert.Equal(t, 1, c.Painted())3233	// Repainting the same pixel does not count twice.34	c.Set(Pixel{X: 3, Y: 2, Color: 7})35	uassert.Equal(t, byte(7), c.Get(3, 2))36	uassert.Equal(t, 1, c.Painted())3738	// Other rows stay unallocated and blank.39	uassert.Equal(t, Blank, c.Get(0, 0))40	uassert.True(t, c.rows[0] == nil, "row 0 should stay nil")41}4243func TestCheck(t *testing.T) {44	c := New(2, 2)45	tests := []struct {46		name string47		p    Pixel48		err  error49	}{50		{"ok", Pixel{0, 0, 1}, nil},51		{"ok max", Pixel{1, 1, MaxColor}, nil},52		{"x negative", Pixel{-1, 0, 1}, ErrOutOfRange},53		{"y negative", Pixel{0, -1, 1}, ErrOutOfRange},54		{"x too big", Pixel{2, 0, 1}, ErrOutOfRange},55		{"y too big", Pixel{0, 2, 1}, ErrOutOfRange},56		{"blank color", Pixel{0, 0, Blank}, ErrInvalidColor},57		{"color too big", Pixel{0, 0, MaxColor + 1}, ErrInvalidColor},58	}59	for _, tc := range tests {60		got := c.Check(tc.p)61		if got != tc.err {62			t.Errorf("%s: got %v, want %v", tc.name, got, tc.err)63		}64	}65}6667func TestRows(t *testing.T) {68	c := New(3, 3)69	uassert.Equal(t, "000000000", c.Rows(0, 3))70	c.Set(Pixel{X: 1, Y: 1, Color: 15})71	c.Set(Pixel{X: 2, Y: 2, Color: 10})72	uassert.Equal(t, "000", c.Rows(0, 1))73	uassert.Equal(t, "0f0", c.Rows(1, 2))74	uassert.Equal(t, "0f000a", c.Rows(1, 3))75	uassert.Equal(t, "", c.Rows(2, 2))7677	for _, r := range [][2]int{{-1, 1}, {0, 4}, {2, 1}} {78		func() {79			defer func() {80				if rec := recover(); rec == nil {81					t.Errorf("Rows(%d, %d) did not panic", r[0], r[1])82				}83			}()84			c.Rows(r[0], r[1])85		}()86	}87}8889func TestParsePixels(t *testing.T) {90	px, err := ParsePixels("0,0,1;5,7,15;")91	uassert.NoError(t, err)92	uassert.Equal(t, 2, len(px))93	if px[0] != (Pixel{0, 0, 1}) || px[1] != (Pixel{5, 7, 15}) {94		t.Errorf("unexpected pixels: %v", px)95	}9697	for _, bad := range []string{"", ";", "1,2", "1,2,3,4", "a,2,3", "1,b,3", "1,2,c", "1,2,0", "1,2,16", "1,2,-1"} {98		if _, err := ParsePixels(bad); err == nil {99			t.Errorf("ParsePixels(%q) accepted invalid input", bad)100		}101	}102}103104func TestEncodeRoundTrip(t *testing.T) {105	in := []Pixel{{0, 0, 1}, {999, 999, 15}, {3, 4, 8}}106	s := Encode(in)107	uassert.Equal(t, "0,0,1;999,999,15;3,4,8", s)108	out, err := ParsePixels(s)109	uassert.NoError(t, err)110	uassert.Equal(t, len(in), len(out))111	for i := range in {112		if in[i] != out[i] {113			t.Errorf("pixel %d: got %v, want %v", i, out[i], in[i])114		}115	}116}117

Functions

not supported for pure packages by the node (vm/qfuncs)

Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.