/** * Generating header for a given table. * * @param table * the table where the header should fit to * @return another {@link NiceTable} instance */ private NiceTable generateHeader(final NiceTable table) { table.addHeader("Benchmark"); table.addRow(new String[] { "-", "unit", "sum", "min", "max", "avg", "stddev", "conf95", "runs" }); return table; }
/** * Adds a string row. checks that the strings added do not contain newlines, * because if so, it has to split them in order to make them fit the row. * * @param data * the array of data. */ public void addRow(final String[] data) { if (anyStringContainsNewLine(data)) { final String[][] theMatrix = Util.createMatrix(data); for (int i = 0; i < theMatrix.length; i++) { addRow(theMatrix[i]); } } else { final Row myRow = new Row(this, data); rows.add(myRow); } }
/** * Alignement test if some rows are incomplete */ @Test public void testRowAlignment() { final NiceTable zero = new NiceTable(2); zero.addRow(new String[] { "a\nb\nc", "a\nb" }); zero.addRow(new String[] { "d", "d" }); final String expected = "| a | a |\n" + "| b | b |\n" + "| c | |\n" + "| d | d |\n"; assertEquals("Test for row alignment", expected, zero.toString()); }
/** * Test method for {@link org.perfidix.ouput.asciitable.NiceTable#toString()}. */ @Test public void testToString() { table.addHeader("This is a header"); table.addRow(new String[] { "This", "is", "one", "data" }); table.addLine('-'); table.addRow(new String[] { "This", "is", "another", "data" }); assertEquals( "Test for a complete table", "|= This is a header ===========================|\n| This | is | one | data |\n|----------------------------------------------|\n| This | is | another | data |\n", table.toString()); }
/** * Test method for {@link org.perfidix.ouput.asciitable.NiceTable#addRow(java.lang.String[])} . */ @Test public void testAddRow() { final String[] data = { "this", "is", "a", "test" }; table.addRow(data); assertEquals("Test for | delim", "| this | is | a | test |\n", table.toString()); }
/** * Recursive usage of multiple tables */ @Test public void testNestedTable() { final NiceTable zero = new NiceTable(3); final NiceTable one = new NiceTable(2); final NiceTable two = new NiceTable(2); final NiceTable three = new NiceTable(2); one.addRow(new String[] { "a", "b" }); two.addRow(new String[] { "c", "d" }); three.addRow(new String[] { "e", "f" }); zero.addRow(new String[] { one.toString(), two.toString(), three.toString() }); final String result = zero.toString().trim(); assertEquals("Test for encapsulated tables", "| | a | b | | | c | d | | | e | f | |", result); }
/** * Generating the results for a given table. * * @param columnDesc * the description for the row * @param meter * the corresponding {@link AbstractMeter} instance * @param result * the corresponding {@link AbstractResult} instance * @param input * the {@link NiceTable} to be print to * @return the modified {@link NiceTable} instance */ private NiceTable generateMeterResult(final String columnDesc, final AbstractMeter meter, final AbstractResult result, final NiceTable input) { input.addRow(new String[] { columnDesc, meter.getUnit(), AbstractOutput.format(result.sum(meter)), AbstractOutput.format(result.min(meter)), AbstractOutput.format(result.max(meter)), AbstractOutput.format(result.mean(meter)), AbstractOutput.format(result.getStandardDeviation(meter)), new StringBuilder("[").append(AbstractOutput.format(result.getConf05(meter))).append("-").append( AbstractOutput.format(result.getConf95(meter))).append("]").toString(), AbstractOutput.format(result.getResultSet(meter).size()) }); return input; }