advent-of-code/math_test.go
2024-10-30 13:32:44 -06:00

51 lines
853 B
Go

package aoc_test
import (
"testing"
"github.com/matryer/is"
aoc "go.sour.is/advent-of-code"
)
func TestLCM(t *testing.T) {
is := is.New(t)
is.Equal(aoc.LCM([]int{}...), 0)
is.Equal(aoc.LCM(5), 5)
is.Equal(aoc.LCM(5, 3), 15)
is.Equal(aoc.LCM(5, 3, 2), 30)
}
func TestPower2(t *testing.T) {
is := is.New(t)
is.Equal(aoc.Power2(0), 1)
is.Equal(aoc.Power2(1), 2)
is.Equal(aoc.Power2(2), 4)
}
func TestABS(t *testing.T) {
is := is.New(t)
is.Equal(aoc.ABS(1), 1)
is.Equal(aoc.ABS(0), 0)
is.Equal(aoc.ABS(-1), 1)
}
func TestMin(t *testing.T) {
is := is.New(t)
is.Equal(aoc.Min(10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 1)
}
func TestMax(t *testing.T) {
is := is.New(t)
is.Equal(aoc.Max(1, 10, 2, 3, 4, 5, 6, 7, 8, 9, 1), 10)
}
func TestSum(t *testing.T) {
is := is.New(t)
is.Equal(aoc.Sum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 55)
}