Skip to content

Commit

Permalink
chore: fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
  • Loading branch information
moul committed Apr 2, 2023
1 parent e076d41 commit 8faf62d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
20 changes: 20 additions & 0 deletions examples/gno.land/r/demo/art/gnoface/gnoface.gno
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
package gnoface

import (
"std"
"strconv"
"strings"

"gno.land/p/demo/rand"
"gno.land/p/demo/ufmt"
)

func Render(path string) string {
seed := std.GetHeight()

path = strings.TrimSpace(path)
if path != "" {
s, err := strconv.Atoi(path)
if err != nil {
panic(err)
}
seed = int64(s)
}

output := ufmt.Sprintf("Gnoface #%d\n", seed)
output += Draw(seed)
return output
}

func Draw(seed int64) string {
var (
hairs = []string{
Expand Down
64 changes: 64 additions & 0 deletions examples/gno.land/r/demo/art/gnoface/gnoface_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,67 @@ o| ~ ~ |.
})
}
}

func TestRender(t *testing.T) {
cases := []struct {
path string
expected string
}{
{
path: "42",
expected: `
Gnoface #42
|||||||
////////\
| |
| ~ . |
)| X X |.
| |
| C |
| |
| __/ |
| |
\~~~~~~~/`[1:],
},
{
path: "1337",
expected: `
Gnoface #1337
s
/|||||||\
| |
| . * |
o| ~ ~ |.
| |
| O |
| |
| __/ |
| |
\_______/`[1:],
},
{
path: "123456789",
expected: `
Gnoface #123456789
s
/~~~~~~~\
| |
| ~ . |
<| ~ ~ |<
| |
| V |
| |
| \_/ |
| |
\-------/`[1:],
},
}
for _, tc := range cases {
t.Run(tc.path, func(t *testing.T) {
got := Render(tc.path)
if got != tc.expected {
t.Errorf("got %s, expected %s", got, tc.expected)
}
})
}
}

0 comments on commit 8faf62d

Please sign in to comment.