Skip to content
Myr

util_test.go

This file

Path

src/util/util_test.go

40 lines · 570 bytes · Go

Last changed by

Not known.

History of this file

Take it

1package util23import "testing"45func TestMax(t *testing.T) {6	if Max(-2, 5) != 5 {7		t.Error("Invalid result")8	}9}1011func TestContrain(t *testing.T) {12	if Constrain(-3, -1, 3) != -1 {13		t.Error("Expected", -1)14	}15	if Constrain(2, -1, 3) != 2 {16		t.Error("Expected", 2)17	}1819	if Constrain(5, -1, 3) != 3 {20		t.Error("Expected", 3)21	}22}2324func TestOnce(t *testing.T) {25	o := Once(false)26	if o() {27		t.Error("Expected: false")28	}29	if o() {30		t.Error("Expected: false")31	}3233	o = Once(true)34	if !o() {35		t.Error("Expected: true")36	}37	if o() {38		t.Error("Expected: false")39	}40}