mirror of
https://github.com/gonum/gonum.git
synced 2025-10-08 16:40:06 +08:00
63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
package sliceops
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
SmallBenchmark = 10
|
|
MediumBenchmark = 1000
|
|
LargeBenchmark = 100000
|
|
)
|
|
|
|
func TestMin(t *testing.T) {
|
|
s := []float64{}
|
|
val, ind := Min(s)
|
|
if val != 0 {
|
|
t.Errorf("Val not returned as default when slice length is zero")
|
|
}
|
|
if ind != -1 {
|
|
t.Errorf("Ind not returned as -1 for empty slice")
|
|
}
|
|
s = []float64{3, 4, 1, 7, 5}
|
|
val, ind = Min(s)
|
|
if val != 1 {
|
|
t.Errorf("Wrong value returned")
|
|
}
|
|
if ind != 2 {
|
|
t.Errorf("Wrong index returned")
|
|
}
|
|
}
|
|
|
|
func TestMax(t *testing.T) {
|
|
s := []float64{}
|
|
val, ind := Max(s)
|
|
if val != 0 {
|
|
t.Errorf("Val not returned as default when slice length is zero")
|
|
}
|
|
if ind != -1 {
|
|
t.Errorf("Ind not returned as -1 for empty slice")
|
|
}
|
|
s = []float64{3, 4, 1, 7, 5}
|
|
val, ind = Max(s)
|
|
if val != 7 {
|
|
t.Errorf("Wrong value returned")
|
|
}
|
|
if ind != 3 {
|
|
t.Errorf("Wrong index returned")
|
|
}
|
|
}
|
|
|
|
func TestSum(t *testing.T) {
|
|
s := []float64{}
|
|
val := Sum(s)
|
|
if val != 0 {
|
|
t.Errorf("Val not returned as default when slice length is zero")
|
|
}
|
|
s = []float64{3, 4, 1, 7, 5}
|
|
val = Sum(s)
|
|
if val != 20 {
|
|
t.Errorf("Wrong sum returned")
|
|
}
|
|
}
|