Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

moodstone_test.gno

2.69 Kb · 125 lines
  1package moodstone
  2
  3import (
  4	"testing"
  5
  6	"gno.land/p/nt/testutils/v0"
  7)
  8
  9var (
 10	alice = testutils.TestAddress("alice")
 11	bob   = testutils.TestAddress("bob")
 12)
 13
 14func TestLogMoodBasic(cur realm, t *testing.T) {
 15	entries = nil
 16	testing.SetOriginCaller(alice)
 17
 18	LogMood(cross(cur),"happy", "great day!")
 19	LogMood(cross(cur),"calm", "")
 20
 21	if len(entries) != 2 {
 22		t.Fatalf("expected 2 entries, got %d", len(entries))
 23	}
 24	if entries[0].Mood != "happy" {
 25		t.Errorf("expected happy, got %s", entries[0].Mood)
 26	}
 27	if entries[0].Note != "great day!" {
 28		t.Errorf("expected 'great day!', got %s", entries[0].Note)
 29	}
 30	if entries[1].Mood != "calm" {
 31		t.Errorf("expected calm, got %s", entries[1].Mood)
 32	}
 33}
 34
 35func TestLogMoodCaseInsensitive(cur realm, t *testing.T) {
 36	entries = nil
 37	testing.SetOriginCaller(alice)
 38
 39	LogMood(cross(cur),"HAPPY", "uppercase input")
 40	if entries[0].Mood != "happy" {
 41		t.Errorf("expected normalized to happy, got %s", entries[0].Mood)
 42	}
 43}
 44
 45func TestIsValid(t *testing.T) {
 46	for _, m := range validMoods {
 47		if !isValid(m) {
 48			t.Errorf("%s should be valid", m)
 49		}
 50	}
 51	if isValid("euphoric") {
 52		t.Error("euphoric should not be valid")
 53	}
 54	if isValid("") {
 55		t.Error("empty string should not be valid")
 56	}
 57}
 58
 59func TestMoodCount(cur realm, t *testing.T) {
 60	entries = nil
 61	testing.SetOriginCaller(alice)
 62
 63	LogMood(cross(cur),"happy", "")
 64	LogMood(cross(cur),"happy", "")
 65	LogMood(cross(cur),"sad", "")
 66
 67	if MoodCount("happy") != 2 {
 68		t.Errorf("expected 2 happy, got %d", MoodCount("happy"))
 69	}
 70	if MoodCount("sad") != 1 {
 71		t.Errorf("expected 1 sad, got %d", MoodCount("sad"))
 72	}
 73	if MoodCount("angry") != 0 {
 74		t.Errorf("expected 0 angry, got %d", MoodCount("angry"))
 75	}
 76}
 77
 78func TestTotalEntries(cur realm, t *testing.T) {
 79	entries = nil
 80
 81	if TotalEntries() != 0 {
 82		t.Errorf("expected 0, got %d", TotalEntries())
 83	}
 84	testing.SetOriginCaller(alice)
 85	LogMood(cross(cur),"excited", "testing!")
 86	if TotalEntries() != 1 {
 87		t.Errorf("expected 1, got %d", TotalEntries())
 88	}
 89}
 90
 91func TestDominantMood(cur realm, t *testing.T) {
 92	entries = nil
 93
 94	if DominantMood() != "none" {
 95		t.Errorf("expected none on empty, got %s", DominantMood())
 96	}
 97
 98	testing.SetOriginCaller(alice)
 99	LogMood(cross(cur),"happy", "")
100	LogMood(cross(cur),"happy", "")
101
102	testing.SetOriginCaller(bob)
103	LogMood(cross(cur),"sad", "")
104
105	if DominantMood() != "happy" {
106		t.Errorf("expected happy to dominate, got %s", DominantMood())
107	}
108}
109
110func TestRender(cur realm, t *testing.T) {
111	entries = nil
112
113	out := Render("")
114	if len(out) == 0 {
115		t.Error("Render returned empty string")
116	}
117
118	testing.SetOriginCaller(alice)
119	LogMood(cross(cur),"neutral", "just checking the render")
120
121	out = Render("")
122	if len(out) == 0 {
123		t.Error("Render returned empty string after entries")
124	}
125}