Skip to content

Commit 13262c5

Browse files
committed
fix: code coverage up to 100%
1 parent c4ed1c1 commit 13262c5

File tree

3 files changed

+268
-38
lines changed

3 files changed

+268
-38
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ v := n.Eval64(x, y, z) // v is between -1.0 and 1.0 of float64
6767

6868
### Note
6969

70-
This package does NOT support more than 3 dimensions. If more than 3 dimentions were given, such as `Noise.Eval64(w, x, y, z)`, it will retrun a `0` (zero) value.
70+
This package ONLY supports up to 3 dimensions. If more than 3 dimentions were given, such as `Noise.Eval64(w, x, y, z)`, it will retrun a `0` (zero) value.
7171

7272
## Usage
7373

pkg/opensimplex/example_test.go

Lines changed: 159 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,64 +6,191 @@ import (
66
"github.com/KEINOS/go-noise/pkg/opensimplex"
77
)
88

9-
func ExampleNew_one_dimmention() {
10-
const seed = 100
9+
// -----------------------------------------------------------------------------
10+
// Noise.Eval32 implementation test
11+
// -----------------------------------------------------------------------------
12+
13+
func ExampleNew_eval32_one_dimmention() {
14+
const (
15+
seed = 100
16+
smoothness = 100
17+
)
1118

1219
p := opensimplex.New(seed)
1320

14-
for x := 0.; x < 3; x++ {
15-
fmt.Printf("float32: %0.0f;%0.4f\n", x, p.Eval32(float32(x/10)))
21+
for x := float32(0); x < 3; x++ {
22+
fmt.Printf("%0.4f\n", p.Eval32(x/smoothness))
1623
}
1724

18-
for x := 0.; x < 3; x++ {
19-
fmt.Printf("float64: %0.0f;%0.4f\n", x, p.Eval64(x/10))
25+
// Output:
26+
// 0.0000
27+
// 0.0102
28+
// 0.0204
29+
}
30+
31+
func ExampleNew_eval32_two_dimmentions() {
32+
const (
33+
seed = 100
34+
smoothness = 100
35+
)
36+
37+
p := opensimplex.New(seed)
38+
39+
for y := float32(0); y < 2; y++ {
40+
for x := float32(0); x < 2; x++ {
41+
fmt.Printf(
42+
"%0.4f\n",
43+
p.Eval32(x/smoothness, y/smoothness),
44+
)
45+
}
2046
}
2147

2248
// Output:
23-
// float32: 0;0.0000
24-
// float32: 1;0.0950
25-
// float32: 2;0.1385
26-
// float64: 0;0.0000
27-
// float64: 1;0.0950
28-
// float64: 2;0.1385
49+
// 0000
50+
// 0.0170
51+
// -0.0068
52+
// 0.010
2953
}
3054

31-
func ExampleNew_three_dimmention() {
32-
const seed = 100
55+
func ExampleNew_eval32_three_dimmentions() {
56+
const (
57+
seed = 100
58+
smoothness = 100
59+
)
60+
61+
p := opensimplex.New(seed)
62+
63+
for z := float32(0); z < 2; z++ {
64+
for y := float32(0); y < 2; y++ {
65+
for x := float32(0); x < 2; x++ {
66+
fmt.Printf(
67+
"%0.4f\n",
68+
p.Eval32(x/smoothness, y/smoothness, z/smoothness),
69+
)
70+
}
71+
}
72+
}
73+
74+
// Output:
75+
// 0.0000
76+
// -0.0062
77+
// 0.0062
78+
// 0.0000
79+
// -0.0171
80+
// -0.0233
81+
// -0.0109
82+
// -0.0171
83+
}
84+
85+
func ExampleNew_eval32_more_than_three_dimmentions() {
86+
const (
87+
seed = 100
88+
)
89+
90+
p := opensimplex.New(seed)
91+
92+
// It only supports up to three dimmentions.
93+
// OpenSimplex itself supports more but currently we strictly limit it to three.
94+
fmt.Printf("%0.0f", p.Eval32(0.0001, 0.0001, 0.0001, 0.0001))
95+
96+
// Output: 0
97+
}
98+
99+
// -----------------------------------------------------------------------------
100+
// Noise.Eval64 implementation test
101+
// -----------------------------------------------------------------------------
102+
103+
func ExampleNew_eval64_one_dimmention() {
104+
const (
105+
seed = 100
106+
smoothness = 100
107+
)
108+
109+
p := opensimplex.New(seed)
110+
111+
for x := float64(0); x < 3; x++ {
112+
fmt.Printf(
113+
"%0.4f\n",
114+
p.Eval64(x/smoothness),
115+
)
116+
}
117+
118+
// Output:
119+
// 0.0000
120+
// 0.0102
121+
// 0.0204
122+
}
123+
124+
func ExampleNew_eval64_two_dimmentions() {
125+
const (
126+
seed = 100
127+
smoothness = 100
128+
)
33129

34130
p := opensimplex.New(seed)
35131

36132
for x := 0.; x < 2; x++ {
37133
for y := 0.; y < 2; y++ {
38134
for z := 0.; z < 2; z++ {
39-
fmt.Printf("float32: %0.0f;%0.0f;%0.0f;%0.4f\n", x, y, z, p.Eval32(float32(x/10), float32(y/10), float32(z/10)))
135+
fmt.Printf(
136+
"%0.4f\n",
137+
p.Eval64(x/smoothness, y/smoothness, z/smoothness),
138+
)
40139
}
41140
}
42141
}
43142

143+
// Output:
144+
// 0.0000
145+
// -0.0171
146+
// 0.0062
147+
// -0.0109
148+
// -0.0062
149+
// -0.0233
150+
// 0.0000
151+
// -0.0171
152+
}
153+
154+
func ExampleNew_eval64_three_dimmentions() {
155+
const (
156+
seed = 100
157+
smoothness = 100
158+
)
159+
160+
p := opensimplex.New(seed)
161+
44162
for x := 0.; x < 2; x++ {
45163
for y := 0.; y < 2; y++ {
46164
for z := 0.; z < 2; z++ {
47-
fmt.Printf("float64: %0.0f;%0.0f;%0.0f;%0.4f\n", x, y, z, p.Eval64(x/10, y/10, z/10))
165+
fmt.Printf(
166+
"%0.4f\n",
167+
p.Eval64(x/smoothness, y/smoothness, z/smoothness),
168+
)
48169
}
49170
}
50171
}
51172

52173
// Output:
53-
// float32: 0;0;0;0.0000
54-
// float32: 0;0;1;-0.1672
55-
// float32: 0;1;0;0.0607
56-
// float32: 0;1;1;-0.1040
57-
// float32: 1;0;0;-0.0611
58-
// float32: 1;0;1;-0.2227
59-
// float32: 1;1;0;0.0003
60-
// float32: 1;1;1;-0.1585
61-
// float64: 0;0;0;0.0000
62-
// float64: 0;0;1;-0.1672
63-
// float64: 0;1;0;0.0607
64-
// float64: 0;1;1;-0.1040
65-
// float64: 1;0;0;-0.0611
66-
// float64: 1;0;1;-0.2227
67-
// float64: 1;1;0;0.0003
68-
// float64: 1;1;1;-0.1585
174+
// 0.0000
175+
// -0.0171
176+
// 0.0062
177+
// -0.0109
178+
// -0.0062
179+
// -0.0233
180+
// 0.0000
181+
// -0.0171
182+
}
183+
184+
func ExampleNew_eval64_more_than_three_dimmentions() {
185+
const (
186+
seed = 100
187+
)
188+
189+
p := opensimplex.New(seed)
190+
191+
// It only supports up to three dimmentions.
192+
// OpenSimplex itself supports more but currently we strictly limit it to three.
193+
fmt.Printf("%0.0f", p.Eval64(0.0001, 0.0001, 0.0001, 0.0001))
194+
195+
// Output: 0
69196
}

pkg/perlin/example_test.go

Lines changed: 108 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ import (
66
"github.com/KEINOS/go-noise/pkg/perlin"
77
)
88

9+
// ----------------------------------------------------------------------------
10+
// Noise.Eval32 implementation test
11+
// ----------------------------------------------------------------------------
12+
913
func ExampleNew_eval32_one_dimmention() {
10-
const seed = 100
14+
const (
15+
seed = 100
16+
smoothness = 100
17+
)
1118

1219
p := perlin.New(seed)
1320

14-
for x := 0.; x < 3; x++ {
15-
fmt.Printf("%0.0f;%0.4f\n", x, p.Eval32(float32(x/100)))
21+
for x := float32(0); x < 3; x++ {
22+
fmt.Printf(
23+
"%0.0f;%0.4f\n",
24+
x,
25+
p.Eval32(x/smoothness),
26+
)
1627
}
1728

1829
// Output:
@@ -21,6 +32,84 @@ func ExampleNew_eval32_one_dimmention() {
2132
// 2;-0.0046
2233
}
2334

35+
func ExampleNew_eval32_two_dimmentions() {
36+
const (
37+
seed = 100
38+
smoothness = 100
39+
)
40+
41+
p := perlin.New(seed)
42+
43+
for y := float32(0); y < 3; y++ {
44+
for x := float32(0); x < 3; x++ {
45+
fmt.Printf(
46+
"%0.0f;%0.0f; %0.4f\n",
47+
x, y,
48+
p.Eval32(x/smoothness, y/smoothness),
49+
)
50+
}
51+
}
52+
53+
// Output:
54+
// 0;0; 0.0000
55+
// 1;0; -0.0285
56+
// 2;0; -0.0602
57+
// 0;1; -0.0152
58+
// 1;1; -0.0437
59+
// 2;1; -0.0753
60+
// 0;2; -0.0328
61+
// 1;2; -0.0612
62+
// 2;2; -0.0927
63+
}
64+
65+
func ExampleNew_eval32_three_dimmentions() {
66+
const (
67+
seed = 100
68+
smoothness = 100
69+
)
70+
71+
p := perlin.New(seed)
72+
73+
for z := float32(0); z < 2; z++ {
74+
for y := float32(0); y < 2; y++ {
75+
for x := float32(0); x < 2; x++ {
76+
fmt.Printf(
77+
"%0.0f;%0.0f;%0.0f; %0.4f\n",
78+
x, y, z,
79+
p.Eval32(x/smoothness, y/smoothness, z/smoothness),
80+
)
81+
}
82+
}
83+
}
84+
85+
// Output:
86+
// 0;0;0; 0.0000
87+
// 1;0;0; -0.0146
88+
// 0;1;0; -0.0104
89+
// 1;1;0; -0.0249
90+
// 0;0;1; 0.0257
91+
// 1;0;1; 0.0112
92+
// 0;1;1; 0.0154
93+
// 1;1;1; 0.0009
94+
}
95+
96+
func ExampleNew_eval32_more_than_three_dimmentions() {
97+
const (
98+
seed = 100
99+
)
100+
101+
p := perlin.New(seed)
102+
103+
// It only supports up to three dimmentions.
104+
fmt.Printf("%0.0f", p.Eval32(0.0001, 0.0001, 0.0001, 0.0001))
105+
106+
// Output: 0
107+
}
108+
109+
// ----------------------------------------------------------------------------
110+
// Noise.Eval64 implementation test
111+
// ----------------------------------------------------------------------------
112+
24113
func ExampleNew_eval64_one_dimmention() {
25114
const seed = 100
26115

@@ -36,7 +125,7 @@ func ExampleNew_eval64_one_dimmention() {
36125
// 2;-0.0017
37126
}
38127

39-
func ExampleNew_eval64_two_dimmention() {
128+
func ExampleNew_eval64_two_dimmentions() {
40129
const seed = 100
41130

42131
p := perlin.New(seed)
@@ -54,7 +143,7 @@ func ExampleNew_eval64_two_dimmention() {
54143
// 1;1;-0.5045
55144
}
56145

57-
func ExampleNew_eval64_three_dimmention() {
146+
func ExampleNew_eval64_three_dimmentions() {
58147
const seed = 100
59148

60149
p := perlin.New(seed)
@@ -77,3 +166,17 @@ func ExampleNew_eval64_three_dimmention() {
77166
// 1;1;0;-0.2208
78167
// 1;1;1;0.0304
79168
}
169+
170+
func ExampleNew_eval64_more_than_three_dimmentions() {
171+
const (
172+
seed = 100
173+
smoothness = 100
174+
)
175+
176+
p := perlin.New(seed)
177+
178+
// It only supports up to three dimmentions.
179+
fmt.Printf("%0.0f", p.Eval64(0.0001, 0.0001, 0.0001, 0.0001))
180+
181+
// Output: 0
182+
}

0 commit comments

Comments
 (0)