Update SimplexNoiseTest.java

This commit is contained in:
Libin Yang 2019-05-09 16:34:58 +08:00 committed by GitHub
parent 39806e3fe6
commit 46e52f4378
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,5 @@
package src.test.java.com.generation; package src.test.java.com.generation;
import static org.junit.jupiter.api.Assertions.*;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@ -9,42 +8,42 @@ import java.io.InputStream;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.junit.jupiter.api.Test;
import org.junit.Assert;
import org.junit.Test;
import src.main.java.com.generation.SimplexNoise; import src.main.java.com.generation.SimplexNoise;
public class SimplexNoiseTest { public class SimplexNoiseTest {
@Test @Test
public void testGenerateHeightMap() { public void testGenerateHeightMap() {
final int WIDTH = 256; final int WIDTH = 256;
final int HEIGHT = 256; final int HEIGHT = 256;
final int X = 0; final int X = 0;
final int Y = 0; final int Y = 0;
final String RESOURCE_NAME = "src/test/java/com/generation/expected-result.png"; 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); float[][] heightmap = new SimplexNoise(50, 0.3F, 1111111111111111L).generateHeightMap(X, Y, WIDTH, HEIGHT);
BufferedImage image = null; BufferedImage image = null;
try(InputStream in = this.getClass().getClassLoader().getResourceAsStream(RESOURCE_NAME)) { try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(RESOURCE_NAME)) {
image = ImageIO.read(in); image = ImageIO.read(in);
assertEquals(WIDTH, image.getWidth()); Assert.assertEquals(WIDTH, image.getWidth());
assertEquals(HEIGHT, image.getHeight()); Assert.assertEquals(HEIGHT, image.getHeight());
} catch(IOException | IllegalArgumentException exception) { } catch (IOException | IllegalArgumentException exception) {
fail(exception); }
}
for (int x = 0; x < WIDTH; x++) {
for(int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
for(int y = 0; y < HEIGHT; y++) {
Assert.assertEquals(new Color(image.getRGB(x, y)).getRed(), (int) (heightmap[x][y] * 255));
assertEquals(new Color(image.getRGB(x, y)).getRed(), (int)(heightmap[x][y] * 255)); }
} }
} }
}
} }