forked from montanaflynn/stats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_test.go
More file actions
39 lines (34 loc) · 799 Bytes
/
sample_test.go
File metadata and controls
39 lines (34 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package stats
import (
"testing"
)
func TestSample(t *testing.T) {
_, err := Sample([]float64{}, 10, false)
if err == nil {
t.Errorf("Returned an error")
}
_, err2 := Sample([]float64{0.1, 0.2}, 10, false)
if err2 == nil {
t.Errorf("Returned an error")
}
}
func TestSampleWithoutReplacement(t *testing.T) {
arr := []float64{0.1, 0.2, 0.3, 0.4, 0.5}
result, _ := Sample(arr, 5, false)
checks := map[float64]bool{}
for _, res := range result {
_, ok := checks[res]
if ok {
t.Errorf("%v already seen", res)
}
checks[res] = true
}
}
func TestSampleWithReplacement(t *testing.T) {
arr := []float64{0.1, 0.2, 0.3, 0.4, 0.5}
numsamples := 100
result, _ := Sample(arr, numsamples, true)
if len(result) != numsamples {
t.Errorf("%v != %v", len(result), numsamples)
}
}