This repository was archived by the owner on Feb 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.go
More file actions
50 lines (42 loc) · 1.2 KB
/
utils.go
File metadata and controls
50 lines (42 loc) · 1.2 KB
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
40
41
42
43
44
45
46
47
48
49
50
package labassistant
import (
"math/rand"
"reflect"
"time"
)
// Shuffle a slice
func shuffle(slice []*Observation) {
rand.Seed(int64(time.Now().Nanosecond()))
for i := range slice {
j := rand.Intn(i + 1)
slice[i], slice[j] = slice[j], slice[i]
}
}
// Check if a variable is a function.
func is_func(f interface{}) bool {
return reflect.ValueOf(f).Type().Kind() == reflect.Func
}
// The default output mismatch comparison.
// If there's a mismatch it will return true.
//
// It loops over all outputs for a candidate and do a simple == comparison
// against the control's output. It also ensures that the number of outputs of
// the candidate is the same as the control's.
func DefaultMismatchCompare(control, candidate []interface{}) bool {
// We will likely run into a "index out of range" panic if we don't make
// sure the len of outputs are equal.
if len(candidate) != len(control) {
return true
}
for i := range candidate {
if candidate[i] != control[i] {
return true
}
}
return false
}
// The default ignore mismatch check.
// It always returns false, so it will never ignore any output mismatches.
func DefaultIgnoreMismatch(control, candidate []interface{}) bool {
return false
}