-
Notifications
You must be signed in to change notification settings - Fork 1
/
algo_test.go
38 lines (29 loc) · 982 Bytes
/
algo_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
package algoexplore
import (
"testing"
)
type Fake struct {
foobar int
}
func (fake *Fake) Name() string { return "fake" }
func (fake *Fake) Init(inputLen int) { return }
func (fake *Fake) Step(d byte) { return }
func (fake *Fake) SerializeState() string { return "serialized" }
func (fake *Fake) DeserializeState(state string) error { return nil }
func TestRegister_withValidFactory_addsToRegistry(t *testing.T) {
Register(func() AlgoPlugin { return &Fake{} })
_, err := GetAlgo("random")
if err == nil {
t.Fatal("found some unregistered algorithm!")
}
_, err = GetAlgo("fake")
if err != nil {
t.Fatal("valid algorithm not found")
}
}
func TestRegister_twiceWithSamePluginName_Panics(t *testing.T) {
defer func() { recover() }()
Register(func() AlgoPlugin { return &Fake{} })
Register(func() AlgoPlugin { return &Fake{} })
t.Errorf("did not panic on duplicate registration")
}