|
1 | 1 | package src.test.java.com.generation; |
2 | 2 |
|
3 | | -import static org.junit.jupiter.api.Assertions.*; |
4 | | - |
5 | 3 | import java.awt.Color; |
6 | 4 | import java.awt.image.BufferedImage; |
7 | 5 | import java.io.IOException; |
8 | 6 | import java.io.InputStream; |
9 | 7 |
|
10 | 8 | import javax.imageio.ImageIO; |
11 | 9 |
|
12 | | -import org.junit.jupiter.api.Test; |
| 10 | +import org.junit.Assert; |
| 11 | +import org.junit.Test; |
13 | 12 |
|
14 | 13 | import src.main.java.com.generation.SimplexNoise; |
15 | 14 |
|
16 | 15 | public class SimplexNoiseTest { |
17 | 16 |
|
18 | | - @Test |
19 | | - public void testGenerateHeightMap() { |
20 | | - |
21 | | - final int WIDTH = 256; |
22 | | - final int HEIGHT = 256; |
23 | | - final int X = 0; |
24 | | - final int Y = 0; |
25 | | - final String RESOURCE_NAME = "src/test/java/com/generation/expected-result.png"; |
26 | | - |
27 | | - float[][] heightmap = new SimplexNoise(50, 0.3F, 1111111111111111L).generateHeightMap(X, Y, WIDTH, HEIGHT); |
28 | | - BufferedImage image = null; |
29 | | - |
30 | | - try(InputStream in = this.getClass().getClassLoader().getResourceAsStream(RESOURCE_NAME)) { |
31 | | - |
32 | | - image = ImageIO.read(in); |
33 | | - |
34 | | - assertEquals(WIDTH, image.getWidth()); |
35 | | - assertEquals(HEIGHT, image.getHeight()); |
36 | | - |
37 | | - } catch(IOException | IllegalArgumentException exception) { |
38 | | - |
39 | | - fail(exception); |
40 | | - } |
41 | | - |
42 | | - for(int x = 0; x < WIDTH; x++) { |
43 | | - |
44 | | - for(int y = 0; y < HEIGHT; y++) { |
45 | | - |
46 | | - assertEquals(new Color(image.getRGB(x, y)).getRed(), (int)(heightmap[x][y] * 255)); |
47 | | - } |
48 | | - } |
49 | | - } |
| 17 | + @Test |
| 18 | + public void testGenerateHeightMap() { |
| 19 | + |
| 20 | + final int WIDTH = 256; |
| 21 | + final int HEIGHT = 256; |
| 22 | + final int X = 0; |
| 23 | + final int Y = 0; |
| 24 | + final String RESOURCE_NAME = "src/test/java/com/generation/expected-result.png"; |
| 25 | + |
| 26 | + float[][] heightmap = new SimplexNoise(50, 0.3F, 1111111111111111L).generateHeightMap(X, Y, WIDTH, HEIGHT); |
| 27 | + BufferedImage image = null; |
| 28 | + |
| 29 | + try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(RESOURCE_NAME)) { |
| 30 | + |
| 31 | + image = ImageIO.read(in); |
| 32 | + |
| 33 | + Assert.assertEquals(WIDTH, image.getWidth()); |
| 34 | + Assert.assertEquals(HEIGHT, image.getHeight()); |
| 35 | + |
| 36 | + } catch (IOException | IllegalArgumentException exception) { |
| 37 | + |
| 38 | + Assert.fail(exception.toString()); |
| 39 | + } |
| 40 | + |
| 41 | + for (int x = 0; x < WIDTH; x++) { |
| 42 | + |
| 43 | + for (int y = 0; y < HEIGHT; y++) { |
| 44 | + |
| 45 | + Assert.assertEquals(new Color(image.getRGB(x, y)).getRed(), (int) (heightmap[x][y] * 255)); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
50 | 49 | } |
0 commit comments