Skip to content
Snippets Groups Projects
Commit ea3c9507 authored by Leonard Kupper's avatar Leonard Kupper
Browse files

Add further test cases. (AbstractRasterCanvas, MasterRenderer)

parent a9057e40
No related branches found
No related tags found
1 merge request!8Feat/rasterizer 10
package de.tudresden.inf.mci.brailleplot.rendering;
import de.tudresden.inf.mci.brailleplot.configparser.ConfigurationParser;
import de.tudresden.inf.mci.brailleplot.configparser.Format;
import de.tudresden.inf.mci.brailleplot.configparser.JavaPropertiesConfigurationParser;
import de.tudresden.inf.mci.brailleplot.configparser.Printer;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
public class AbstractRasterCanvasTest {
public static final String mDefaultConfig = getResource("default.properties").getAbsolutePath();
public static final String mBaseConfig = getResource("base_format.properties").getAbsolutePath();
public static final String mMarginsOnlyConfig = getResource("margins_only.properties").getAbsolutePath();
public static final String mConstraintOnlyConfig = getResource("constraint_only.properties").getAbsolutePath();
public static final String mBothConfig = getResource("margins_and_constraint.properties").getAbsolutePath();
public static File getResource(String fileName) {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
File resourceFile = new File(classLoader.getResource(fileName).getFile());
return resourceFile;
}
@Test
public void testBaseFormat() {
Assertions.assertDoesNotThrow(
() -> {
ConfigurationParser parser = new JavaPropertiesConfigurationParser(mBaseConfig, mDefaultConfig);
AbstractRasterCanvas canvas = new SixDotBrailleRasterCanvas(parser.getPrinter(), parser.getFormat("test"));
// pre-calculated and measured correct values:
int x = 0;
int y = 0;
int w = 35;
int h = 30;
double printW = (w * (2.5 + 3.5)) - 3.5; // 206.5 mm
double printH = (h * (2 * 2.5 + 5.0)) - 5.0; // 295.0 mm
// Test the calculated raster against the pre-calculated values
Rectangle raster = canvas.getCellRectangle();
Assertions.assertEquals(x, raster.getX());
Assertions.assertEquals(y, raster.getY());
Assertions.assertEquals(w, raster.getWidth());
Assertions.assertEquals(h, raster.getHeight());
Assertions.assertEquals(x, raster.intWrapper().getX());
Assertions.assertEquals(y, raster.intWrapper().getY());
Assertions.assertEquals(w, raster.intWrapper().getWidth());
Assertions.assertEquals(h, raster.intWrapper().getHeight());
Assertions.assertEquals(printW, canvas.getPrintableWidth());
Assertions.assertEquals(printH, canvas.getPrintableHeight());
// Test quantification (by equivalence class partitioning testing)
Assertions.assertEquals(0, canvas.quantifyX(-5));
Assertions.assertEquals(0, canvas.quantifyX(0));
Assertions.assertEquals(9, canvas.quantifyX(28.25));
Assertions.assertEquals(10, canvas.quantifyX(28.26));
Assertions.assertEquals(69, canvas.quantifyX(206.5));
Assertions.assertEquals(69, canvas.quantifyX(250));
Assertions.assertEquals(0, canvas.quantifyY(-5));
Assertions.assertEquals(0, canvas.quantifyY(0));
Assertions.assertEquals(15, canvas.quantifyY(51.25));
Assertions.assertEquals(16, canvas.quantifyY(51.26));
Assertions.assertEquals(89, canvas.quantifyY(295.0));
Assertions.assertEquals(89, canvas.quantifyY(350.0));
}
);
}
@Test
public void testMarginsOnly() {
Assertions.assertDoesNotThrow(
() -> {
ConfigurationParser parser = new JavaPropertiesConfigurationParser(mMarginsOnlyConfig, mDefaultConfig);
AbstractRasterCanvas canvas = new SixDotBrailleRasterCanvas(parser.getPrinter(), parser.getFormat("test"));
// pre-calculated and measured correct values:
// 6 mm left margin -> 1 cell border
// 12 mm top margin -> ~ 1.2 cell sizes -> 2 cell border
// 30 mm bottom margin -> 3 cell border
int x = 1;
int y = 2;
int w = 34; // 35 - 1
int h = 25; // 30 - 2 - 3
double printW = (w * (2.5 + 3.5)) - 3.5; // 200.5 mm
double printH = (h * (2 * 2.5 + 5.0)) - 5.0; // 245.0 mm
// Test the calculated raster against the pre-calculated values
Rectangle raster = canvas.getCellRectangle();
Assertions.assertEquals(x, raster.getX());
Assertions.assertEquals(y, raster.getY());
Assertions.assertEquals(w, raster.getWidth());
Assertions.assertEquals(h, raster.getHeight());
Assertions.assertEquals(x, raster.intWrapper().getX());
Assertions.assertEquals(y, raster.intWrapper().getY());
Assertions.assertEquals(w, raster.intWrapper().getWidth());
Assertions.assertEquals(h, raster.intWrapper().getHeight());
Assertions.assertEquals(printW, canvas.getPrintableWidth());
Assertions.assertEquals(printH, canvas.getPrintableHeight());
}
);
}
@Test
public void testConstraintOnly() {
Assertions.assertDoesNotThrow(
() -> {
ConfigurationParser parser = new JavaPropertiesConfigurationParser(mConstraintOnlyConfig, mDefaultConfig);
AbstractRasterCanvas canvas = new SixDotBrailleRasterCanvas(parser.getPrinter(), parser.getFormat("test"));
// pre-calculated and measured correct values:
// width-constraint: 190.0 mm -> fits 32 cells h.
// height-constraint: 250.0 mm -> fits 25 cells v.
int x = 0; // zero because constraint
int y = 0; // moves reference point.
int w = 30; // because raster.constraint.width = 30 < 32 (will pick minimum)
int h = 25; // because 25 < raster.constraint.height = 28
double printW = (w * (2.5 + 3.5)) - 3.5; // 176.5 mm
double printH = (h * (2 * 2.5 + 5.0)) - 5.0; // 245.0 mm
// Test the calculated raster against the pre-calculated values
Rectangle raster = canvas.getCellRectangle();
Assertions.assertEquals(x, raster.getX());
Assertions.assertEquals(y, raster.getY());
Assertions.assertEquals(w, raster.getWidth());
Assertions.assertEquals(h, raster.getHeight());
Assertions.assertEquals(x, raster.intWrapper().getX());
Assertions.assertEquals(y, raster.intWrapper().getY());
Assertions.assertEquals(w, raster.intWrapper().getWidth());
Assertions.assertEquals(h, raster.intWrapper().getHeight());
Assertions.assertEquals(printW, canvas.getPrintableWidth());
Assertions.assertEquals(printH, canvas.getPrintableHeight());
}
);
}
@Test
public void testBoth() {
Assertions.assertDoesNotThrow(
() -> {
ConfigurationParser parser = new JavaPropertiesConfigurationParser(mBothConfig, mDefaultConfig);
AbstractRasterCanvas canvas = new SixDotBrailleRasterCanvas(parser.getPrinter(), parser.getFormat("test"));
// pre-calculated and measured correct values:
// width-constraint: 190.0 mm -> fits 32 cells h.
// height-constraint: 250.0 mm -> fits 25 cells v.
int x = 0;
int y = 1;
int w = 30;
int h = 24;
double printW = (w * (2.5 + 3.5)) - 3.5; // 176.5 mm
double printH = (h * (2 * 2.5 + 5.0)) - 5.0; // 235.0 mm
// Test the calculated raster against the pre-calculated values
Rectangle raster = canvas.getCellRectangle();
Assertions.assertEquals(x, raster.getX());
Assertions.assertEquals(y, raster.getY());
Assertions.assertEquals(w, raster.getWidth());
Assertions.assertEquals(h, raster.getHeight());
Assertions.assertEquals(x, raster.intWrapper().getX());
Assertions.assertEquals(y, raster.intWrapper().getY());
Assertions.assertEquals(w, raster.intWrapper().getWidth());
Assertions.assertEquals(h, raster.intWrapper().getHeight());
Assertions.assertEquals(printW, canvas.getPrintableWidth());
Assertions.assertEquals(printH, canvas.getPrintableHeight());
}
);
}
}
package de.tudresden.inf.mci.brailleplot.rendering;
import de.tudresden.inf.mci.brailleplot.configparser.ConfigurationParser;
import de.tudresden.inf.mci.brailleplot.configparser.Format;
import de.tudresden.inf.mci.brailleplot.configparser.JavaPropertiesConfigurationParser;
import de.tudresden.inf.mci.brailleplot.configparser.Printer;
import diagrams.BarChart;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
public class MasterRendererTest {
public static final String mDefaultConfig = getResource("default.properties").getAbsolutePath();
public static final String mBaseConfig = getResource("base_format.properties").getAbsolutePath();
public static Printer mPrinter;
public static Format mFormat;
public static File getResource(String fileName) {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
File resourceFile = new File(classLoader.getResource(fileName).getFile());
return resourceFile;
}
@BeforeAll
public static void initialize() {
Assertions.assertDoesNotThrow(
() -> {
ConfigurationParser parser = new JavaPropertiesConfigurationParser(mBaseConfig, mDefaultConfig);
mPrinter = parser.getPrinter();
mFormat = parser.getFormat("test");
}
);
}
// Valid use test cases.
@Test
public void testRasterizerSelection() {
Assertions.assertDoesNotThrow(
() -> {
// Create own rendering base
FunctionalRenderingBase renderingBase = new FunctionalRenderingBase();
// Register two different rasterizers for two different types.
// The rasterizers are later distinguished by the number of pages they generate.
FunctionalRasterizer<Text> rasterizerRef1 = new FunctionalRasterizer<>(Text.class, (data, canvas) -> {
for (int i = 0; i < 1; i++) {
canvas.getNewPage();
}
});
FunctionalRasterizer<Image> rasterizerRef2 = new FunctionalRasterizer<>(Image.class, (data, canvas) -> {
for (int i = 0; i < 2; i++) {
canvas.getNewPage();
}
});
renderingBase.registerRasterizer(rasterizerRef1);
renderingBase.registerRasterizer(rasterizerRef2);
// create renderer from rendering base
MasterRenderer renderer = new MasterRenderer(mPrinter, mFormat, renderingBase);
// Test rasterizer selection
AbstractRasterCanvas result;
result= renderer.rasterize(new Text("dummy text", new Rectangle(0,0,1,1)));
Assertions.assertEquals(1, result.getPageCount());
result = renderer.rasterize(new Image(getResource("dummy.bmp")));
Assertions.assertEquals(2, result.getPageCount());
// Test replacement of rasterizer
FunctionalRasterizer<Image> rasterizerRef3 = new FunctionalRasterizer<>(Image.class, (data, canvas) -> {
for (int i = 0; i < 3; i++) {
canvas.getNewPage();
}
});
renderingBase.registerRasterizer(rasterizerRef3);
result = renderer.rasterize(new Image(getResource("dummy.bmp")));
Assertions.assertEquals(3, result.getPageCount());
}
);
}
// Invalid use test cases.
@Test
public void testRasterizerNotAvailable() {
// Create MasterRenderer with empty rendering base.
MasterRenderer empty = new MasterRenderer(mPrinter, mFormat, new FunctionalRenderingBase());
Assertions.assertThrows(IllegalArgumentException.class, () -> empty.rasterize(new Image(getResource("dummy.bmp"))));
}
}
......@@ -16,7 +16,7 @@ printer.constraint.top=5.0
printer.constraint.left=7.5
printer.constraint.width=190.0
printer.constraint.height=250.0
printer.raster.constraint.top=1
printer.raster.constraint.top=0
printer.raster.constraint.left=2
printer.raster.constraint.width=30
printer.raster.constraint.height=28
......@@ -27,5 +27,5 @@ printer.raster.constraint.height=28
# Test margins
format.test.margin.top=12
format.test.margin.left=6
format.test.margin.bottom=30
format.test.margin.bottom=42
format.test.margin.right=0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment