This repository has been 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
/
experiment_test.go
123 lines (104 loc) · 2.39 KB
/
experiment_test.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package labassistant
import (
"testing"
"github.com/stretchr/testify/assert"
)
func fail_compare(co, ca []interface{}) bool {
// This "comparison" will always fail.
return true
}
func ignore_all(co, ca []interface{}) bool {
// This "ignore" will always ignore.
return true
}
func TestSetControlIsOK(t *testing.T) {
a := assert.New(t)
e := NewExperiment("")
a.Zero(e.Control)
a.NotPanics(func() {
e.SetControl(good_func)
})
a.NotEmpty(e.Control)
a.Panics(func() {
e.SetControl("string")
})
}
func TestAddCandidateIsOK(t *testing.T) {
a := assert.New(t)
e := NewExperiment("")
a.Empty(e.Candidates)
a.NotPanics(func() {
e.AddCandidate(good_func)
})
a.Panics(func() {
e.AddCandidate("string")
})
a.NotEmpty(e.Candidates)
a.NotPanics(func() {
e.AddCandidate(panic_func)
})
a.Equal(2, len(e.Candidates))
a.NotEqual(e.Candidates[0], e.Candidates[1])
}
func TestRunIsOK(t *testing.T) {
a := assert.New(t)
e := NewExperiment("")
a.Panics(func() {
e.Run()
})
e.SetControl(good_func)
e.AddCandidate(good_func)
a.NotPanics(func() {
e.Run(1)
})
a.Equal([]interface{}{1}, e.Inputs)
a.Equal([]interface{}{1}, e.Control.Outputs)
a.NotEmpty(e.RunOrder)
a.Empty(e.Candidates[0].Panic)
a.False(e.Candidates[0].Mismatch)
a.Equal(e.Control.Outputs, e.Candidates[0].Outputs)
}
func TestRunWithPanicCandidates(t *testing.T) {
a := assert.New(t)
e := NewExperiment("")
e.SetControl(good_func)
e.AddCandidate(panic_func)
a.NotPanics(func() {
e.Run(1)
})
a.NotEmpty(e.Candidates[0].Panic)
a.True(e.Candidates[0].Mismatch)
}
func TestRunWithBadCandidates(t *testing.T) {
a := assert.New(t)
e := NewExperiment("")
e.SetControl(good_func)
e.AddCandidate(bad_func)
a.NotPanics(func() {
e.Run(1)
})
a.Empty(e.Candidates[0].Panic)
a.True(e.Candidates[0].Mismatch)
a.NotEqual(e.Control.Outputs, e.Candidates[0].Outputs)
}
func TestRunWithCustomCompare(t *testing.T) {
a := assert.New(t)
e := NewExperiment("")
e.SetControl(good_func)
e.AddCandidate(good_func)
e.SetCompare(fail_compare)
e.Run(1)
a.Equal([]interface{}{1}, e.Candidates[0].Outputs)
a.True(e.Candidates[0].Mismatch)
}
func TestRunWithCustomIgnore(t *testing.T) {
a := assert.New(t)
e := NewExperiment("")
e.SetControl(good_func)
e.AddCandidate(bad_func)
e.SetIgnore(ignore_all)
e.Run(1)
a.Equal([]interface{}{2}, e.Candidates[0].Outputs)
a.Empty(e.Candidates[0].Panic)
a.False(e.Candidates[0].Mismatch)
}