-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
colorgens_test.go
53 lines (42 loc) · 1.37 KB
/
colorgens_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
package colorful
import (
"math/rand"
"testing"
"time"
)
// This is really difficult to test, if you've got a good idea, pull request!
// Check if it returns all valid colors.
func TestColorValidity(t *testing.T) {
// with default seed
for i := 0; i < 100; i++ {
if col := WarmColor(); !col.IsValid() {
t.Errorf("Warm color %v is not valid! Seed was: default", col)
}
if col := FastWarmColor(); !col.IsValid() {
t.Errorf("Fast warm color %v is not valid! Seed was: default", col)
}
if col := HappyColor(); !col.IsValid() {
t.Errorf("Happy color %v is not valid! Seed was: default", col)
}
if col := FastHappyColor(); !col.IsValid() {
t.Errorf("Fast happy color %v is not valid! Seed was: default", col)
}
}
// with custom seed
seed := time.Now().UTC().UnixNano()
rand := rand.New(rand.NewSource(seed))
for i := 0; i < 100; i++ {
if col := WarmColorWithRand(rand); !col.IsValid() {
t.Errorf("Warm color %v is not valid! Seed was: %v", col, seed)
}
if col := FastWarmColorWithRand(rand); !col.IsValid() {
t.Errorf("Fast warm color %v is not valid! Seed was: %v", col, seed)
}
if col := HappyColorWithRand(rand); !col.IsValid() {
t.Errorf("Happy color %v is not valid! Seed was: %v", col, seed)
}
if col := FastHappyColorWithRand(rand); !col.IsValid() {
t.Errorf("Fast happy color %v is not valid! Seed was: %v", col, seed)
}
}
}