-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathidenticon_test.go
89 lines (70 loc) · 1.86 KB
/
identicon_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
// SPDX-FileCopyrightText: 2015-2024 caixw
//
// SPDX-License-Identifier: MIT
package identicon
import (
"image/color"
"image/png"
"math/rand"
"os"
"strconv"
"testing"
"time"
"github.com/issue9/assert/v4"
)
var (
back = color.RGBA{R: 255, G: 0, B: 0, A: 100}
fore = color.RGBA{R: 0, G: 255, B: 255, A: 100}
size = 128
)
func TestMake(t *testing.T) {
a := assert.New(t, false)
for i := 0; i < 20; i++ {
img := Make(Style1, size, back, fore, []byte("make-"+strconv.Itoa(i)))
a.NotNil(img)
fi, err := os.Create("./testdata/v1-make-" + strconv.Itoa(i) + ".png")
a.NotError(err).NotNil(fi)
a.NotError(png.Encode(fi, img))
a.NotError(fi.Close()) // 关闭文件
}
}
func TestIdenticon_Make_style1(t *testing.T) {
a := assert.New(t, false)
ii := S1(size)
a.NotNil(ii)
for i := 0; i < 20; i++ {
img := ii.Make([]byte("identicon-" + strconv.Itoa(i)))
a.NotNil(img)
fi, err := os.Create("./testdata/s1-identicon-make" + strconv.Itoa(i) + ".png")
a.NotError(err).NotNil(fi)
a.NotError(png.Encode(fi, img))
a.NotError(fi.Close()) // 关闭文件
}
}
func TestIdenticon_Rand_style1(t *testing.T) {
a := assert.New(t, false)
ii := S1(size)
a.NotNil(ii)
r := rand.New(rand.NewSource(time.Now().Unix()))
for i := 0; i < 20; i++ {
img := ii.Rand(r)
a.NotNil(img)
fi, err := os.Create("./testdata/s1-identicon-rand-" + strconv.Itoa(i) + ".png")
a.NotError(err).NotNil(fi)
a.NotError(png.Encode(fi, img))
a.NotError(fi.Close()) // 关闭文件
}
}
func TestIdenticon_Make_style2(t *testing.T) {
a := assert.New(t, false)
ii := S2(size)
a.NotNil(ii)
for i := 0; i < 20; i++ {
img := ii.Make([]byte("identicon-" + strconv.Itoa(i)))
a.NotNil(img)
fi, err := os.Create("./testdata/s2-identicon-make" + strconv.Itoa(i) + ".png")
a.NotError(err).NotNil(fi)
a.NotError(png.Encode(fi, img))
a.NotError(fi.Close()) // 关闭文件
}
}