forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimplexNoiseTest.java
45 lines (33 loc) · 1.31 KB
/
SimplexNoiseTest.java
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
package src.test.java.com.generation;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.generation.SimplexNoise;
public class SimplexNoiseTest {
@Test
public void testGenerateHeightMap() {
final int WIDTH = 256;
final int HEIGHT = 256;
final int X = 0;
final int Y = 0;
final String RESOURCE_NAME = "src/test/java/com/generation/expected-result.png";
float[][] heightmap = new SimplexNoise(50, 0.3F, 1111111111111111L).generateHeightMap(X, Y, WIDTH, HEIGHT);
BufferedImage image = null;
try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(RESOURCE_NAME)) {
image = ImageIO.read(in);
Assert.assertEquals(WIDTH, image.getWidth());
Assert.assertEquals(HEIGHT, image.getHeight());
} catch (IOException | IllegalArgumentException exception) {
Assert.fail(exception.toString());
}
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
Assert.assertEquals(new Color(image.getRGB(x, y)).getRed(), (int) (heightmap[x][y] * 255));
}
}
}
}