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.

mimir_test.gno

1.22 Kb · 39 lines
 1package mimir
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/uassert/v0"
 7)
 8
 9func TestHistoryBefore(t *testing.T) {
10	var h History
11	uassert.Equal(t, int64(0), h.Before(0).A)
12
13	h.Record(100, Amounts{A: 1})
14	h.Record(100, Amounts{A: 2}) // same second coalesces
15	h.Record(200, Amounts{A: 2, B: 5})
16	h.Record(300, Amounts{A: 7, B: 5})
17	uassert.Equal(t, 3, h.Len())
18
19	uassert.Equal(t, int64(7), h.Before(0).A)   // no cutoff: latest
20	uassert.Equal(t, int64(0), h.Before(100).A) // strictly before 100: nothing
21	uassert.Equal(t, int64(2), h.Before(101).A) // the coalesced checkpoint
22	uassert.Equal(t, int64(0), h.Before(200).B) // 200 itself is excluded
23	uassert.Equal(t, int64(5), h.Before(250).B)
24	uassert.Equal(t, int64(7), h.Before(1000).A)
25}
26
27func TestMulDiv(t *testing.T) {
28	uassert.Equal(t, int64(6), MulDiv(4, 3, 2))
29	uassert.Equal(t, int64(3), MulDiv(10, 1, 3)) // rounds down
30	big := int64(1) << 62
31	uassert.Equal(t, big, MulDiv(big, big, big)) // 124-bit product
32	uassert.PanicsContains(t, nil, "overflow", func() { MulDiv(big, big, 1) })
33	uassert.PanicsContains(t, nil, "d > 0", func() { MulDiv(1, 1, 0) })
34}
35
36func TestAdd(t *testing.T) {
37	uassert.Equal(t, int64(3), Add(1, 2))
38	uassert.PanicsContains(t, nil, "overflow", func() { Add(1<<62, 1<<62) })
39}