Adding a robot shape that got mangled to the test. #16.

This commit is contained in:
Rob Greene 2018-06-24 12:21:25 -05:00
parent cb85e065c3
commit 965d6be891
3 changed files with 107 additions and 0 deletions

View File

@ -91,6 +91,39 @@ public class ShapeGeneratorTest {
assertShapeMatches(mouse, vectorShape);
}
@Test
public void testRobotShape() throws IOException {
final String robot = "+-------------+\n"
+ "|....XXXXX...+|\n"
+ "|XXXXX...XX...|\n"
+ "|....XXXXX....|\n"
+ "|.............|\n"
+ "|..XX..XXX....|\n"
+ "|...XX.XXX....|\n"
+ "|...XX.XXXX...|\n"
+ "|..XX.XXXXX...|\n"
+ "|....XXXXXX...|\n"
+ "|.XXXXXXXXXXX.|\n"
+ "|XX.........XX|\n"
+ "|XX.........XX|\n"
+ "|.XXXXXXXXXXX.|\n"
+ "+-------------+\n";
ShapeTable st = ShapeGenerator.generate(getClass().getResourceAsStream("/robot-bitmap.st"));
assertNotNull(st);
assertEquals(1, st.shapes.size());
// Verify we read the shape correctly...
Shape shape = st.shapes.get(0);
assertNotNull(shape);
assertShapeMatches(robot, shape);
// Run vector transform to be certain we're ok
Shape vectorShape = shape.toVector();
assertNotNull(vectorShape);
assertShapeMatches(robot, vectorShape);
}
public void assertShapeMatches(final String expected, Shape shape) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ShapeExporter exp = ShapeExporter.text().asciiTextBorder().build();

View File

@ -0,0 +1,59 @@
package io.github.applecommander.bastools.api.shapes;
import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ShapeWriteAndReadTests {
@Parameters(name = "{index}: file= {0}")
public static Collection<String> data() {
return Arrays.asList("/mouse-bitmap.st", "/robot-bitmap.st");
}
@Parameter
public String filename;
private ShapeExporter textExporter;
@Before
public void setup() {
textExporter = ShapeExporter.text().asciiTextBorder().skipEmptyShapes(true).build();
}
@Test
public void test() throws IOException {
ShapeTable stBefore = ShapeGenerator.generate(getClass().getResourceAsStream(filename));
assertNotNull(stBefore);
assertFalse(stBefore.shapes.isEmpty());
final String expected = format(stBefore);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
stBefore.write(outputStream);
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
ShapeTable stAfter = ShapeTable.read(inputStream);
String actual = format(stAfter);
assertEquals(expected, actual);
}
public String format(ShapeTable st) throws IOException {
ByteArrayOutputStream text = new ByteArrayOutputStream();
textExporter.export(st, text);
return new String(text.toByteArray());
}
}

View File

@ -0,0 +1,15 @@
.bitmap
....XXXXX...+
XXXXX...XX...
....XXXXX....
.............
..XX..XXX....
...XX.XXX....
...XX.XXXX...
..XX.XXXXX...
....XXXXXX...
.XXXXXXXXXXX.
XX.........XX
XX.........XX
.XXXXXXXXXXX.