|
1 | 1 | packagesrc.test.java.com.generation; |
2 | 2 |
|
3 | | -importstaticorg.junit.jupiter.api.Assertions.*; |
4 | | - |
5 | 3 | importjava.awt.Color; |
6 | 4 | importjava.awt.image.BufferedImage; |
7 | 5 | importjava.io.IOException; |
8 | 6 | importjava.io.InputStream; |
9 | 7 |
|
10 | 8 | importjavax.imageio.ImageIO; |
11 | 9 |
|
12 | | -importorg.junit.jupiter.api.Test; |
| 10 | +importorg.junit.Assert; |
| 11 | +importorg.junit.Test; |
13 | 12 |
|
14 | 13 | importsrc.main.java.com.generation.SimplexNoise; |
15 | 14 |
|
16 | 15 | publicclassSimplexNoiseTest { |
17 | 16 |
|
18 | | -@Test |
19 | | -publicvoidtestGenerateHeightMap() { |
20 | | -
|
21 | | -finalintWIDTH =256; |
22 | | -finalintHEIGHT =256; |
23 | | -finalintX =0; |
24 | | -finalintY =0; |
25 | | -finalStringRESOURCE_NAME ="src/test/java/com/generation/expected-result.png"; |
26 | | -
|
27 | | -float[][]heightmap =newSimplexNoise(50,0.3F,1111111111111111L).generateHeightMap(X,Y,WIDTH,HEIGHT); |
28 | | -BufferedImageimage =null; |
29 | | -
|
30 | | -try(InputStreamin =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 |IllegalArgumentExceptionexception) { |
38 | | -
|
39 | | -fail(exception); |
40 | | -} |
41 | | -
|
42 | | -for(intx =0;x <WIDTH;x++) { |
43 | | -
|
44 | | -for(inty =0;y <HEIGHT;y++) { |
45 | | -
|
46 | | -assertEquals(newColor(image.getRGB(x,y)).getRed(), (int)(heightmap[x][y] *255)); |
47 | | -} |
48 | | -} |
49 | | -} |
| 17 | +@Test |
| 18 | +publicvoidtestGenerateHeightMap() { |
| 19 | + |
| 20 | +finalintWIDTH =256; |
| 21 | +finalintHEIGHT =256; |
| 22 | +finalintX =0; |
| 23 | +finalintY =0; |
| 24 | +finalStringRESOURCE_NAME ="src/test/java/com/generation/expected-result.png"; |
| 25 | + |
| 26 | +float[][]heightmap =newSimplexNoise(50,0.3F,1111111111111111L).generateHeightMap(X,Y,WIDTH,HEIGHT); |
| 27 | +BufferedImageimage =null; |
| 28 | + |
| 29 | +try(InputStreamin =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 |IllegalArgumentExceptionexception) { |
| 37 | + |
| 38 | +Assert.fail(exception.toString()); |
| 39 | + } |
| 40 | + |
| 41 | +for(intx =0;x <WIDTH;x++) { |
| 42 | + |
| 43 | +for(inty =0;y <HEIGHT;y++) { |
| 44 | + |
| 45 | +Assert.assertEquals(newColor(image.getRGB(x,y)).getRed(), (int)(heightmap[x][y] *255)); |
| 46 | +} |
| 47 | +} |
| 48 | +} |
50 | 49 | } |