-
Notifications
You must be signed in to change notification settings - Fork 1
/
noise_test.go
55 lines (40 loc) · 1.6 KB
/
noise_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
package noise_test
import (
"math/rand"
"testing"
"time"
"github.com/KEINOS/go-noise"
"github.com/stretchr/testify/require"
)
func TestNew_unknown_noise_type(t *testing.T) {
const seed = 100
g, err := noise.New(1000, seed)
require.Error(t, err, "unknown noise type should return an error")
require.Nil(t, g, "it should be nil on error")
}
//nolint:dupl // let lines be duplicate with other tests for readability
func TestNew_is_in_range_perlin(t *testing.T) {
for i := 0; i < 100; i++ {
//nolint:gosec // Use of weak random number generator is OK here
seed := rand.New(rand.NewSource(time.Now().UnixNano())).Int63()
g, err := noise.New(noise.Perlin, seed)
require.NoError(t, err, "it should not return an error")
require.NotNil(t, g, "it should not be nil")
v := g.Eval64(rand.ExpFloat64())
require.GreaterOrEqual(t, v, float64(-1), "it should be in the range of -1 to 1")
require.LessOrEqual(t, v, float64(1), "it should be in the range of -1 to 1")
}
}
//nolint:dupl // let lines be duplicate with other tests for readability
func TestNew_is_in_range_opensimplex(t *testing.T) {
for i := 0; i < 100; i++ {
//nolint:gosec // Use of weak random number generator is OK here
seed := rand.New(rand.NewSource(time.Now().UnixNano())).Int63()
g, err := noise.New(noise.OpenSimplex, seed)
require.NoError(t, err, "it should not return an error")
require.NotNil(t, g, "it should not be nil")
v := g.Eval64(rand.ExpFloat64())
require.GreaterOrEqual(t, v, float64(-1), "it should be in the range of -1 to 1")
require.LessOrEqual(t, v, float64(1), "it should be in the range of -1 to 1")
}
}