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.

Playground

gnomod.toml

module = "gno.land/r/nym-moultest123/demo/millipede/v0"
gno = "0.9"

[addpkg]
  creator = "g1ml9grtwnpzqn3hre5ve5vjdlmv2srrmpmc0dsv"
  height = 186406
  max_deposit = "5000000ugnot"

millipede.gno

package millipede

import (
	"strconv"
	"strings"

	"gno.land/p/nt/ufmt/v0"
)

const (
	minSize     = 1
	defaultSize = 20
	maxSize     = 100
)

func Draw(size int) string {
	if size < minSize || size > maxSize {
		panic("invalid millipede size")
	}
	paddings := []string{"  ", " ", "", " ", "  ", "   ", "    ", "    ", "   "}
	var b strings.Builder
	b.WriteString("    ╚⊙ ⊙╝\n")
	for i := 0; i < size; i++ {
		b.WriteString(paddings[i%9] + "╚═(███)═╝\n")
	}
	return b.String()
}

func Render(path string) string {
	size := defaultSize

	path = strings.TrimSpace(path)
	if path != "" {
		var err error
		size, err = strconv.Atoi(path)
		if err != nil {
			panic(err)
		}
	}

	output := "```\n" + Draw(size) + "```\n"
	if size > minSize {
		output += ufmt.Sprintf("[%d](/r/demo/art/millipede:%d)< ", size-1, size-1)
	}
	if size < maxSize {
		output += ufmt.Sprintf(" >[%d](/r/demo/art/millipede:%d)", size+1, size+1)
	}
	return output
}

// based on https://github.com/getmillipede/millipede-go/blob/977f046c39c35a650eac0fd30245e96b22c7803c/main.go

millipede_test.gno

package millipede

import (
	"testing"

	"gno.land/p/nt/uassert/v0"
)

func TestRender(t *testing.T) {
	cases := []struct {
		path     string
		expected string
	}{
		{
			path: "",
			expected: "```" + `
    ╚⊙ ⊙╝
  ╚═(███)═╝
 ╚═(███)═╝
╚═(███)═╝
 ╚═(███)═╝
  ╚═(███)═╝
   ╚═(███)═╝
    ╚═(███)═╝
    ╚═(███)═╝
   ╚═(███)═╝
  ╚═(███)═╝
 ╚═(███)═╝
╚═(███)═╝
 ╚═(███)═╝
  ╚═(███)═╝
   ╚═(███)═╝
    ╚═(███)═╝
    ╚═(███)═╝
   ╚═(███)═╝
  ╚═(███)═╝
 ╚═(███)═╝
` + "```\n[19](/r/demo/art/millipede:19)<  >[21](/r/demo/art/millipede:21)",
		},
		{
			path: "4",
			expected: "```" + `
    ╚⊙ ⊙╝
  ╚═(███)═╝
 ╚═(███)═╝
╚═(███)═╝
 ╚═(███)═╝
` + "```\n[3](/r/demo/art/millipede:3)<  >[5](/r/demo/art/millipede:5)",
		},
	}

	for _, tc := range cases {
		t.Run(tc.path, func(t *testing.T) {
			got := Render(tc.path)
			uassert.Equal(t, tc.expected, got)
		})
	}
}

render_example_test.gno

package millipede

// ExampleRender pins the realm's Render output as a testable example.
func ExampleRender() {
	print(Render(""))
	// Output:
	// ```
	//     ╚⊙ ⊙╝
	//   ╚═(███)═╝
	//  ╚═(███)═╝
	// ╚═(███)═╝
	//  ╚═(███)═╝
	//   ╚═(███)═╝
	//    ╚═(███)═╝
	//     ╚═(███)═╝
	//     ╚═(███)═╝
	//    ╚═(███)═╝
	//   ╚═(███)═╝
	//  ╚═(███)═╝
	// ╚═(███)═╝
	//  ╚═(███)═╝
	//   ╚═(███)═╝
	//    ╚═(███)═╝
	//     ╚═(███)═╝
	//     ╚═(███)═╝
	//    ╚═(███)═╝
	//   ╚═(███)═╝
	//  ╚═(███)═╝
	// ```
	// [19](/r/demo/art/millipede:19)<  >[21](/r/demo/art/millipede:21)
}