提交 4fd7698f 编写于 作者: A Abhijay Kumar

Updated SimpleNoise test to use org.juint.Assert instead of jupiter

上级 ba900596
package src.test.java.com.generation;
import static org.junit.jupiter.api.Assertions.*;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
......@@ -9,42 +7,43 @@ import java.io.InputStream;
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;
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);
assertEquals(WIDTH, image.getWidth());
assertEquals(HEIGHT, image.getHeight());
} catch(IOException | IllegalArgumentException exception) {
fail(exception);
}
for(int x = 0; x < WIDTH; x++) {
for(int y = 0; y < HEIGHT; y++) {
assertEquals(new Color(image.getRGB(x, y)).getRed(), (int)(heightmap[x][y] * 255));
}
}
}
@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));
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册