From 8849c9b52a8022ee8aad59aefa9ed49ab89ecc8c Mon Sep 17 00:00:00 2001 From: Denis Benjamim Date: Sat, 15 May 2021 23:09:05 -0300 Subject: [PATCH 1/6] =?UTF-8?q?Alterado=20maven=20compiler=20para=20Java?= =?UTF-8?q?=208.=20Adicionada=20suporte=20a=20Internacionaliza=C3=A7=C3=A3?= =?UTF-8?q?o=20na=20classe=20TabularSummaryOutput.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + pom.xml | 4 +- .../perfidix/ouput/TabularSummaryOutput.java | 39 +++++++++++++------ src/main/resources/messages.properties | 18 +++++++++ src/main/resources/messages_pt_BR.properties | 18 +++++++++ 5 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 src/main/resources/messages.properties create mode 100644 src/main/resources/messages_pt_BR.properties diff --git a/.gitignore b/.gitignore index 294fd1cf..dd0abf7d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ target test-output .idea *.iml +/bin/ diff --git a/pom.xml b/pom.xml index 8f5d231f..0c9383a3 100644 --- a/pom.xml +++ b/pom.xml @@ -248,8 +248,8 @@ UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 /tmp/deploy diff --git a/src/main/java/org/perfidix/ouput/TabularSummaryOutput.java b/src/main/java/org/perfidix/ouput/TabularSummaryOutput.java index 051482f0..5195497d 100644 --- a/src/main/java/org/perfidix/ouput/TabularSummaryOutput.java +++ b/src/main/java/org/perfidix/ouput/TabularSummaryOutput.java @@ -32,6 +32,11 @@ import java.io.PrintStream; import java.lang.reflect.Method; +import java.security.MessageDigest; +import java.text.MessageFormat; +import java.util.Enumeration; +import java.util.Locale; +import java.util.ResourceBundle; /** @@ -41,7 +46,7 @@ * @author Sebastian Graf, University of Konstanz */ public final class TabularSummaryOutput extends AbstractOutput { - + private final ResourceBundle bundle; /** * Print stream where the result should end. */ @@ -55,6 +60,7 @@ public final class TabularSummaryOutput extends AbstractOutput { public TabularSummaryOutput(final PrintStream paramOut) { super(); out = paramOut; + bundle = ResourceBundle.getBundle("messages", Locale.getDefault()); } /** @@ -80,38 +86,38 @@ public void visitBenchmark(final BenchmarkResult benchRes) { table = generateMeterResult(methRes.getElementName(), meter, methRes, table); } - table.addHeader(new StringBuilder("Summary for ").append(classRes.getElementName()).toString(), '_', Alignment.Left); + table.addHeader(new StringBuilder(getMessageI18n("summary.for")).append(classRes.getElementName()).toString(), '_', Alignment.Left); table = generateMeterResult("", meter, classRes, table); table.addLine('-'); } } - table.addHeader("Summary for the whole benchmark", '=', Alignment.Center); + table.addHeader(getMessageI18n("summary"), '=', Alignment.Center); for (final AbstractMeter meter : benchRes.getRegisteredMeters()) { table = generateMeterResult("", meter, benchRes, table); } - table.addHeader("Exceptions", '=', Alignment.Center); + table.addHeader(getMessageI18n("exceptions"), '=', Alignment.Center); for (final AbstractPerfidixMethodException exec : benchRes.getExceptions()) { final StringBuilder execBuilder0 = new StringBuilder(); - execBuilder0.append("Related exception: ").append(exec.getExec().getClass().getSimpleName()); + execBuilder0.append(getMessageI18n("related.exceptions")).append(exec.getExec().getClass().getSimpleName()); table.addHeader(execBuilder0.toString(), ' ', Alignment.Left); final StringBuilder execBuilder1 = new StringBuilder(); if (exec instanceof PerfidixMethodInvocationException) { - execBuilder1.append("Related place: method invocation"); + execBuilder1.append(getMessageI18n("related.place", "method.invocation")); } else { - execBuilder1.append("Related place: method check"); + execBuilder1.append(getMessageI18n("related.place", "method.check")); } table.addHeader(execBuilder1.toString(), ' ', Alignment.Left); if (exec.getMethod() != null) { final StringBuilder execBuilder2 = new StringBuilder(); - execBuilder2.append("Related method: ").append(exec.getMethod().getName()); + execBuilder2.append(getMessageI18n("related.method")).append(exec.getMethod().getName()); table.addHeader(execBuilder2.toString(), ' ', Alignment.Left); } final StringBuilder execBuilder3 = new StringBuilder(); - execBuilder3.append("Related annotation: ").append(exec.getRelatedAnno().getSimpleName()); + execBuilder3.append(getMessageI18n("related.annotation")).append(exec.getRelatedAnno().getSimpleName()); table.addHeader(execBuilder3.toString(), ' ', Alignment.Left); table.addLine('-'); @@ -172,9 +178,20 @@ public boolean listenToException(final AbstractPerfidixMethodException exec) { * @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"}); + table.addHeader(getMessageI18n("benchmark")); + table.addRow(new String[]{"-", getMessageI18n("unit"), getMessageI18n("sum"), getMessageI18n("min"), getMessageI18n("max"), getMessageI18n("avg"), getMessageI18n("stddev"), getMessageI18n("conf95"), getMessageI18n("runs")}); return table; } + + private String getMessageI18n(String key) { + return bundle.getString(MessageFormat.format("tabularSummaryOutput.{0}", key)); + } + + private String getMessageI18n(String key1, String key2) { + String message = bundle.getString(MessageFormat.format("tabularSummaryOutput.{0}", key1)); + String message2 = bundle.getString(MessageFormat.format("tabularSummaryOutput.{0}", key2)); + + return MessageFormat.format("{0} {1}", message, message2); + } } diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties new file mode 100644 index 00000000..3968d652 --- /dev/null +++ b/src/main/resources/messages.properties @@ -0,0 +1,18 @@ +tabularSummaryOutput.benchmark = Benchmark +tabularSummaryOutput.unit = unit +tabularSummaryOutput.sum = sum +tabularSummaryOutput.min = min +tabularSummaryOutput.max = max +tabularSummaryOutput.avg = avg +tabularSummaryOutput.stddev = stddev +tabularSummaryOutput.conf95 = conf95 +tabularSummaryOutput.runs = runs +tabularSummaryOutput.summary.for = Summary for +tabularSummaryOutput.summary = Summary for the whole benchmark +tabularSummaryOutput.exceptions = Exceptions +tabularSummaryOutput.related.exceptions = Related exception: +tabularSummaryOutput.related.place = Related place: +tabularSummaryOutput.related.method = Related method: +tabularSummaryOutput.related.annotation = Related annotation: +tabularSummaryOutput.method.invocation = method invocation +tabularSummaryOutput.method.check = method check \ No newline at end of file diff --git a/src/main/resources/messages_pt_BR.properties b/src/main/resources/messages_pt_BR.properties new file mode 100644 index 00000000..93d2680c --- /dev/null +++ b/src/main/resources/messages_pt_BR.properties @@ -0,0 +1,18 @@ +tabularSummaryOutput.benchmark = Benchmark +tabularSummaryOutput.unit = unidade +tabularSummaryOutput.sum = soma +tabularSummaryOutput.min = minimo +tabularSummaryOutput.max = maximo +tabularSummaryOutput.avg = m�dia +tabularSummaryOutput.stddev = saida console +tabularSummaryOutput.conf95 = conf95 +tabularSummaryOutput.runs = execu��es +tabularSummaryOutput.summary.for = Resumo para +tabularSummaryOutput.summary = Resumo de todo benchmark +tabularSummaryOutput.exceptions = Exce��es +tabularSummaryOutput.related.exceptions = Exce��o relacionada: +tabularSummaryOutput.related.place = Lugar relacionado: +tabularSummaryOutput.related.method = M�todo relacionado: +tabularSummaryOutput.related.annotation = Anota��o relacionada: +tabularSummaryOutput.method.invocation = invoca��o de m�todo +tabularSummaryOutput.method.check = verifica��o de m�todo \ No newline at end of file From bcf7c4e83752eba69aab4204f03b6686882c5652 Mon Sep 17 00:00:00 2001 From: Denis Benjamim Date: Mon, 17 May 2021 16:19:51 -0300 Subject: [PATCH 2/6] Tests TabularSummaryOutput fixed --- .../perfidix/ouput/TabularSummaryOutput.java | 42 +++++++------ .../asciitable/AbstractTabularComponent.java | 2 +- src/main/resources/messages.properties | 6 +- .../output/TabularSummaryOutputTest.java | 61 +++++++++++++------ 4 files changed, 69 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/perfidix/ouput/TabularSummaryOutput.java b/src/main/java/org/perfidix/ouput/TabularSummaryOutput.java index 5195497d..e61ef74b 100644 --- a/src/main/java/org/perfidix/ouput/TabularSummaryOutput.java +++ b/src/main/java/org/perfidix/ouput/TabularSummaryOutput.java @@ -19,6 +19,12 @@ package org.perfidix.ouput; +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.text.MessageFormat; +import java.util.Locale; +import java.util.ResourceBundle; + import org.perfidix.element.BenchmarkMethod; import org.perfidix.exceptions.AbstractPerfidixMethodException; import org.perfidix.exceptions.PerfidixMethodInvocationException; @@ -30,14 +36,6 @@ import org.perfidix.result.ClassResult; import org.perfidix.result.MethodResult; -import java.io.PrintStream; -import java.lang.reflect.Method; -import java.security.MessageDigest; -import java.text.MessageFormat; -import java.util.Enumeration; -import java.util.Locale; -import java.util.ResourceBundle; - /** * Summary output using the {@link NiceTable} to format. Just giving an overview of statistical analysis over the @@ -46,7 +44,9 @@ * @author Sebastian Graf, University of Konstanz */ public final class TabularSummaryOutput extends AbstractOutput { - private final ResourceBundle bundle; + private final String LINE_SEPARATOR; + + private final ResourceBundle BUNDLE; /** * Print stream where the result should end. */ @@ -60,7 +60,8 @@ public final class TabularSummaryOutput extends AbstractOutput { public TabularSummaryOutput(final PrintStream paramOut) { super(); out = paramOut; - bundle = ResourceBundle.getBundle("messages", Locale.getDefault()); + BUNDLE = ResourceBundle.getBundle("messages", Locale.getDefault()); + LINE_SEPARATOR = System.lineSeparator(); } /** @@ -147,10 +148,11 @@ private NiceTable generateMeterResult(final String columnDesc, final AbstractMet public boolean listenToResultSet(final BenchmarkMethod meth, final AbstractMeter meter, final double data) { Method m = meth.getMethodToBench(); final StringBuilder builder = new StringBuilder(); - builder.append("Class: ").append(m.getDeclaringClass().getSimpleName()).append("#").append(m.getName()); - builder.append("\nMeter: ").append(meter.getName()); - builder.append("\nData: ").append(data).append("\n"); - out.println(builder.toString()); + + builder.append(MessageFormat.format("Class: {1}#{2}{0}", LINE_SEPARATOR, m.getDeclaringClass().getSimpleName(), m.getName())); + builder.append(MessageFormat.format("Meter: {1}{0}", LINE_SEPARATOR, meter.getName())); + builder.append(MessageFormat.format("Data: {1}{0}", LINE_SEPARATOR, String.valueOf(data))); + out.println(builder.toString()); return true; } @@ -161,10 +163,10 @@ public boolean listenToResultSet(final BenchmarkMethod meth, final AbstractMeter public boolean listenToException(final AbstractPerfidixMethodException exec) { final StringBuilder builder = new StringBuilder(); if (exec.getMethod() != null) { - builder.append("Class: ").append(exec.getMethod().getDeclaringClass().getSimpleName()).append("#").append(exec.getMethod().getName()).append("\n"); + builder.append("Class: ").append(exec.getMethod().getDeclaringClass().getSimpleName()).append("#").append(exec.getMethod().getName()).append(LINE_SEPARATOR); } - builder.append("Annotation: ").append(exec.getRelatedAnno().getSimpleName()); - builder.append("\nException: ").append(exec.getClass().getSimpleName()).append("/").append(exec.getExec().toString()); + builder.append("Annotation: ").append(exec.getRelatedAnno().getSimpleName()).append(LINE_SEPARATOR); + builder.append("Exception: ").append(exec.getClass().getSimpleName()).append("/").append(exec.getExec().toString()); out.println(builder.toString()); exec.getExec().printStackTrace(out); return true; @@ -184,12 +186,12 @@ private NiceTable generateHeader(final NiceTable table) { } private String getMessageI18n(String key) { - return bundle.getString(MessageFormat.format("tabularSummaryOutput.{0}", key)); + return BUNDLE.getString(MessageFormat.format("tabularSummaryOutput.{0}", key)); } private String getMessageI18n(String key1, String key2) { - String message = bundle.getString(MessageFormat.format("tabularSummaryOutput.{0}", key1)); - String message2 = bundle.getString(MessageFormat.format("tabularSummaryOutput.{0}", key2)); + String message = BUNDLE.getString(MessageFormat.format("tabularSummaryOutput.{0}", key1)); + String message2 = BUNDLE.getString(MessageFormat.format("tabularSummaryOutput.{0}", key2)); return MessageFormat.format("{0} {1}", message, message2); } diff --git a/src/main/java/org/perfidix/ouput/asciitable/AbstractTabularComponent.java b/src/main/java/org/perfidix/ouput/asciitable/AbstractTabularComponent.java index 685d5cab..a5eb40b3 100644 --- a/src/main/java/org/perfidix/ouput/asciitable/AbstractTabularComponent.java +++ b/src/main/java/org/perfidix/ouput/asciitable/AbstractTabularComponent.java @@ -28,7 +28,7 @@ public abstract class AbstractTabularComponent { /** * Constant for the newline-symbol. */ - static final String NEWLINE = "\n"; + static final String NEWLINE = System.lineSeparator(); /** * Border symbol, can be changed in the runtime. diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 3968d652..e02e8a3b 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -10,9 +10,9 @@ tabularSummaryOutput.runs = runs tabularSummaryOutput.summary.for = Summary for tabularSummaryOutput.summary = Summary for the whole benchmark tabularSummaryOutput.exceptions = Exceptions -tabularSummaryOutput.related.exceptions = Related exception: +tabularSummaryOutput.related.exceptions = Related exception: tabularSummaryOutput.related.place = Related place: -tabularSummaryOutput.related.method = Related method: -tabularSummaryOutput.related.annotation = Related annotation: +tabularSummaryOutput.related.method = Related method: +tabularSummaryOutput.related.annotation = Related annotation: tabularSummaryOutput.method.invocation = method invocation tabularSummaryOutput.method.check = method check \ No newline at end of file diff --git a/src/test/java/org/perfidix/output/TabularSummaryOutputTest.java b/src/test/java/org/perfidix/output/TabularSummaryOutputTest.java index cda82e42..71235c52 100644 --- a/src/test/java/org/perfidix/output/TabularSummaryOutputTest.java +++ b/src/test/java/org/perfidix/output/TabularSummaryOutputTest.java @@ -19,6 +19,16 @@ package org.perfidix.output; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.text.MessageFormat; +import java.util.Locale; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -33,14 +43,6 @@ import org.perfidix.result.BenchmarkResult; import org.perfidix.result.MethodResult; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.lang.reflect.Method; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - /** * Test case for {@link TabularSummaryOutput} @@ -48,9 +50,10 @@ * @author Sebastian Graf, University of Konstanz */ public class TabularSummaryOutputTest { + private final String LINE_SEPARATOR = System.lineSeparator(); - private final static String CLASSSTRING = "Class: Class1#method1\n"; - private final static String METERSTRING = "Meter: Meter1\n"; + private final String CLASSSTRING = MessageFormat.format("Class: Class1#method1{0}", LINE_SEPARATOR); + private final String METERSTRING = MessageFormat.format("Meter: Meter1{0}", LINE_SEPARATOR); private final static int NUMBEROFTICKS = 10; @@ -62,6 +65,10 @@ public class TabularSummaryOutputTest { private transient AbstractPerfidixMethodException testException; + private String TEMPLATE_EXPECTED_LISTEN_TO_RESULT_SET; + private String TEMPLATE_EXPECTED_LISTEN_TO_EXCEPTION; + + /** * Simple Constructor. * @@ -71,6 +78,7 @@ public class TabularSummaryOutputTest { */ @Before public void setUp() throws SecurityException, NoSuchMethodException, PerfidixMethodCheckException { + Locale.setDefault(Locale.ENGLISH); benchRes = new BenchmarkResult(); final Class class1 = Class1.class; @@ -90,6 +98,19 @@ public void setUp() throws SecurityException, NoSuchMethodException, PerfidixMet consoleOut = System.out; bytes = new ByteArrayOutputStream(); System.setOut(new PrintStream(bytes)); + + buildTemplatesListen(); + } + + private void buildTemplatesListen() { + StringBuilder builderPatterExpected = new StringBuilder(); + + for(double data = 1; data < 11 ;data++) { + builderPatterExpected.append(MessageFormat.format("{1}{2}Data: {3}{0}{0}", LINE_SEPARATOR, CLASSSTRING, METERSTRING, String.valueOf(data))); + } + + TEMPLATE_EXPECTED_LISTEN_TO_RESULT_SET = builderPatterExpected.toString(); + TEMPLATE_EXPECTED_LISTEN_TO_EXCEPTION = MessageFormat.format("Class: Class1#method1{0}Annotation: Bench{0}Exception: PerfidixMethodInvocationException/java.io.IOException{0}java.io.IOException{0}", LINE_SEPARATOR); } /** @@ -107,11 +128,13 @@ public void tearDown() throws Exception { * {@link org.perfidix.ouput.TabularSummaryOutput#visitBenchmark(org.perfidix.result.BenchmarkResult)} . */ @Test - public final void testVisitBenchmark() { + public final void testVisitBenchmark() { + final String expected = MessageFormat.format("|= Benchmark ======================================================================|{0}| - | unit | sum | min | max | avg | stddev | conf95 | runs |{0}|===================================== Meter1 =====================================|{0}|. Class1 .........................................................................|{0}| method1 | ticks | 55.00 | 01.00 | 10.00 | 05.50 | 03.03 | [01.00-10.00] | 10.00 |{0}|_ Summary for Class1 _____________________________________________________________|{0}| | ticks | 55.00 | 01.00 | 10.00 | 05.50 | 03.03 | [01.00-10.00] | 10.00 |{0}|----------------------------------------------------------------------------------|{0}|======================== Summary for the whole benchmark =========================|{0}| | ticks | 55.00 | 01.00 | 10.00 | 05.50 | 03.03 | [01.00-10.00] | 10.00 |{0}|=================================== Exceptions ===================================|{0}| Related exception: IOException |{0}| Related place: method invocation |{0}| Related method: method1 |{0}| Related annotation: Bench |{0}|----------------------------------------------------------------------------------|{0}|==================================================================================|{0}{0}", LINE_SEPARATOR); final TabularSummaryOutput output = new TabularSummaryOutput(); output.visitBenchmark(benchRes); final String result = bytes.toString(); - assertTrue("Complete Output check", result.startsWith("|= Benchmark ======================================================================|\n" + "| - | unit | sum | min | max | avg | stddev | conf95 | runs |\n" + "|===================================== Meter1 =====================================|\n" + "|. Class1 .........................................................................|\n" + "| method1 | ticks | 55.00 | 01.00 | 10.00 | 05.50 | 03.03 | [01.00-10.00] | 10.00 |\n" + "|_ Summary for Class1 _____________________________________________________________|\n" + "| | ticks | 55.00 | 01.00 | 10.00 | 05.50 | 03.03 | [01.00-10.00] | 10.00 |\n" + "|----------------------------------------------------------------------------------|\n" + "|======================== Summary for the whole benchmark =========================|\n" + "| | ticks | 55.00 | 01.00 | 10.00 | 05.50 | 03.03 | [01.00-10.00] | 10.00 |\n" + "|=================================== Exceptions ===================================|\n" + "| Related exception: IOException |\n" + "| Related place: method invocation |\n" + "| Related method: method1 |\n" + "| Related annotation: Bench |\n" + "|----------------------------------------------------------------------------------|\n" + "|==================================================================================|\n")); + + assertTrue("Complete Output check", result.startsWith(expected)); } /** @@ -127,11 +150,13 @@ public final void testListenToResultSet() throws IOException { final MethodResult methRes = benchRes.getIncludedResults().iterator().next().getIncludedResults().iterator().next(); final AbstractMeter meter = methRes.getRegisteredMeters().iterator().next(); final TabularSummaryOutput output = new TabularSummaryOutput(); + for (final double d : methRes.getResultSet(meter)) { output.listenToResultSet((BenchmarkMethod) methRes.getRelatedElement(), meter, d); - } - - assertEquals("Complete listener test", CLASSSTRING + METERSTRING + "Data: 1.0\n" + "\n" + CLASSSTRING + METERSTRING + "Data: 2.0\n" + "\n" + CLASSSTRING + METERSTRING + "Data: 3.0\n" + "\n" + CLASSSTRING + METERSTRING + "Data: 4.0\n" + "\n" + CLASSSTRING + METERSTRING + "Data: 5.0\n" + "\n" + CLASSSTRING + METERSTRING + "Data: 6.0\n" + "\n" + CLASSSTRING + METERSTRING + "Data: 7.0\n" + "\n" + CLASSSTRING + METERSTRING + "Data: 8.0\n" + "\n" + CLASSSTRING + METERSTRING + "Data: 9.0\n" + "\n" + CLASSSTRING + METERSTRING + "Data: 10.0\n" + "\n", bytes.toString()); + } + final String result = bytes.toString(); + + assertEquals("Complete listener test", TEMPLATE_EXPECTED_LISTEN_TO_RESULT_SET, result); } /** @@ -143,8 +168,9 @@ public final void testListenToResultSet() throws IOException { public final void testListenToException() { final TabularSummaryOutput output = new TabularSummaryOutput(); output.listenToException(testException); - - assertTrue("Exception listener test", bytes.toString().startsWith("Class: Class1#method1\n" + "Annotation: Bench\n" + "Exception: PerfidixMethodInvocationException/java.io.IOException\n" + "java.io.IOException\n")); + final String result = bytes.toString(); + + assertTrue("Exception listener test", result.startsWith(TEMPLATE_EXPECTED_LISTEN_TO_EXCEPTION)); } private class Class1 { @@ -154,5 +180,4 @@ public void method1() { } } - } From 02cdb5b72951948b97665e07e697a9bb06fb24e5 Mon Sep 17 00:00:00 2001 From: Denis Benjamim Date: Mon, 17 May 2021 17:44:53 -0300 Subject: [PATCH 3/6] Fixed NiceTableTest --- .../org/perfidix/ouput/asciitable/Util.java | 15 +++------- .../output/asciitable/NiceTableTest.java | 30 ++++++++++--------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/perfidix/ouput/asciitable/Util.java b/src/main/java/org/perfidix/ouput/asciitable/Util.java index 09e4479a..c0699790 100644 --- a/src/main/java/org/perfidix/ouput/asciitable/Util.java +++ b/src/main/java/org/perfidix/ouput/asciitable/Util.java @@ -138,7 +138,7 @@ static String repeat(final String toBeRepeated, final int numTimes) { * @return an array of elements */ private static String[] explode(final String toBeSplitted) { - return toBeSplitted.split("\\" + '\n'); + return toBeSplitted.split(AbstractTabularComponent.NEWLINE); } /** @@ -148,14 +148,7 @@ private static String[] explode(final String toBeSplitted) { * @return the number of occurences of {@link org.perfidix.ouput.asciitable.AbstractTabularComponent#NEWLINE} in the string. */ private static int numNewLines(final String toExamine) { - final char[] arr = toExamine.toCharArray(); - int result = 0; - for (char ch : arr) { - if (AbstractTabularComponent.NEWLINE.equals(new String(new char[]{ch}))) { - result++; - } - } - return result; + return toExamine.split(AbstractTabularComponent.NEWLINE).length; } /** @@ -180,10 +173,10 @@ public static String[][] createMatrix(final String[] data) { for (final String col : data) { maxNewLines = Math.max(maxNewLines, Util.numNewLines(col)); } - final String[][] matrix = new String[maxNewLines + 1][data.length]; + final String[][] matrix = new String[maxNewLines][data.length]; for (int col = 0; col < data.length; col++) { final String[] exploded = Util.explode(data[col]); - for (int row = 0; row < maxNewLines + 1; row++) { + for (int row = 0; row < maxNewLines; row++) { if (exploded.length > row) { matrix[row][col] = exploded[row]; } else { diff --git a/src/test/java/org/perfidix/output/asciitable/NiceTableTest.java b/src/test/java/org/perfidix/output/asciitable/NiceTableTest.java index f80ac84c..5c15b91b 100644 --- a/src/test/java/org/perfidix/output/asciitable/NiceTableTest.java +++ b/src/test/java/org/perfidix/output/asciitable/NiceTableTest.java @@ -19,13 +19,15 @@ package org.perfidix.output.asciitable; +import static org.junit.Assert.assertEquals; + +import java.text.MessageFormat; + import org.junit.Before; import org.junit.Test; import org.perfidix.ouput.asciitable.AbstractTabularComponent.Alignment; import org.perfidix.ouput.asciitable.NiceTable; -import static org.junit.Assert.assertEquals; - /** * Test class for the NiceTable. @@ -33,7 +35,7 @@ * @author Sebastian Graf, University of Konstanz */ public class NiceTableTest { - + private final String LINE_SEPARATOR = System.lineSeparator(); private final static int COLUMNNUMBER = 10; private final static String TESTSTRING = "This is a test"; private transient NiceTable table; @@ -60,7 +62,7 @@ public void testCreate() { @Test public void testAddHeaderString() { table.addHeader(TESTSTRING); - assertEquals("Test for normal adding", "|= This is a test =============|\n", table.toString()); + assertEquals("Test for normal adding", MessageFormat.format("|= This is a test =============|{0}", LINE_SEPARATOR), table.toString()); } /** @@ -70,17 +72,17 @@ public void testAddHeaderString() { @Test public void testAddHeaderStringCharAlignment() { table.addHeader(TESTSTRING, '-', Alignment.Left); - assertEquals("Test for left alignement adding", "|- This is a test -------------|\n", table.toString()); + assertEquals("Test for left alignement adding", MessageFormat.format("|- This is a test -------------|{0}", LINE_SEPARATOR), table.toString()); setUp(); table.addHeader(TESTSTRING, '/', Alignment.Center); - assertEquals("Test for center alignment", "|/////// This is a test ///////|\n", table.toString()); + assertEquals("Test for center alignment", MessageFormat.format("|/////// This is a test ///////|{0}",LINE_SEPARATOR), table.toString()); setUp(); table.addHeader(TESTSTRING, '\\', Alignment.Right); - assertEquals("Test for right alignment", "|\\\\\\\\\\\\\\\\\\\\\\\\\\ This is a test \\|\n", table.toString()); + assertEquals("Test for right alignment", MessageFormat.format("|\\\\\\\\\\\\\\\\\\\\\\\\\\ This is a test \\|{0}", LINE_SEPARATOR), table.toString()); } /** @@ -90,7 +92,7 @@ public void testAddHeaderStringCharAlignment() { public void testAddRow() { final String[] data = {"this", "is", "a", "test"}; table.addRow(data); - assertEquals("Test for | delim", "| this | is | a | test |\n", table.toString()); + assertEquals("Test for | delim", MessageFormat.format("| this | is | a | test |{0}", LINE_SEPARATOR), table.toString()); } /** @@ -99,7 +101,7 @@ public void testAddRow() { @Test public void testAddLine() { table.addLine('*'); - assertEquals("Test for adding a line", "|******************************|\n", table.toString()); + assertEquals("Test for adding a line", MessageFormat.format("|******************************|{0}",LINE_SEPARATOR), table.toString()); } /** @@ -111,7 +113,7 @@ public void testToString() { 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()); + assertEquals("Test for a complete table", MessageFormat.format("|= This is a header ===========================|{0}| This | is | one | data |{0}|----------------------------------------------|{0}| This | is | another | data |{0}", LINE_SEPARATOR), table.toString()); } /** @@ -130,7 +132,7 @@ public void testNestedTable() { 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); + assertEquals("Test for encapsulated tables", "| | a | b | | | c | d | | | e | f | |", result); } /** @@ -139,10 +141,10 @@ public void testNestedTable() { @Test public void testRowAlignment() { final NiceTable zero = new NiceTable(2); - zero.addRow(new String[]{"a\nb\nc", "a\nb"}); + zero.addRow(new String[]{ MessageFormat.format("a{0}b{0}c", LINE_SEPARATOR), MessageFormat.format("a{0}b", LINE_SEPARATOR)}); zero.addRow(new String[]{"d", "d"}); - final String expected = "| a | a |\n" + "| b | b |\n" + "| c | |\n" + "| d | d |\n"; + final String expected = MessageFormat.format("| a | a |{0}| b | b |{0}| c | |{0}| d | d |{0}", LINE_SEPARATOR); assertEquals("Test for row alignment", expected, zero.toString()); } @@ -162,7 +164,7 @@ public void testDynamics() { zero.addRow(new String[]{numbers[0].toString(), numbers[1].toString(), numbers[2].toString(), numbers[3].toString(), numbers[4].toString()}); zero.addLine('-'); final String result = zero.toString(); - assertEquals("Another test for a complete table", "|------------------------------------|\n" + "| a | b | c | d | e |\n" + "|====================================|\n" + "| 1.222222222 | 3.0 | 4 | 5.0 | 4444 |\n" + "|------------------------------------|\n", result); + assertEquals("Another test for a complete table", MessageFormat.format("|------------------------------------|{0}| a | b | c | d | e |{0}|====================================|{0}| 1.222222222 | 3.0 | 4 | 5.0 | 4444 |{0}|------------------------------------|{0}", LINE_SEPARATOR), result); } } From e257b317f00808f721b2811b9953752fa03b5f1f Mon Sep 17 00:00:00 2001 From: Denis Benjamim Date: Mon, 17 May 2021 18:44:18 -0300 Subject: [PATCH 4/6] =?UTF-8?q?remo=C3=A7=C3=A3o=20espa=C3=A7o=20testNeste?= =?UTF-8?q?dTable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/org/perfidix/output/asciitable/NiceTableTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/perfidix/output/asciitable/NiceTableTest.java b/src/test/java/org/perfidix/output/asciitable/NiceTableTest.java index 5c15b91b..49b97ea2 100644 --- a/src/test/java/org/perfidix/output/asciitable/NiceTableTest.java +++ b/src/test/java/org/perfidix/output/asciitable/NiceTableTest.java @@ -132,7 +132,7 @@ public void testNestedTable() { 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); + assertEquals("Test for encapsulated tables", "| | a | b | | | c | d | | | e | f | |", result); } /** From a47d39b2922faa47780c42eb48ca0ef6236ed19c Mon Sep 17 00:00:00 2001 From: Denis Benjamim Date: Mon, 17 May 2021 18:52:15 -0300 Subject: [PATCH 5/6] Adicionado readme pt-BR --- README.md | 5 +++- README.pt-BR.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 README.pt-BR.md diff --git a/README.md b/README.md index 2833ad65..181f1e16 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -#Perfidix - No discussions, Just facts. +[! [en] (https://img.shields.io/badge/lang-en-red.svg)] (https://github.com/denisbenjamim/perfidix/blob/master/README.md) +[! [pt-BR] (https://img.shields.io/badge/lang-pt--BR-green.svg)] (https://github.com/denisbenjamim/perfidix/blob/master/README.pt-BR.md) + +# Perfidix - No discussions, Just facts. Perfidix is a light-weight java library enabling users to benchmark sourcecode. Similar to JUnit, annotations can be placed before methods. diff --git a/README.pt-BR.md b/README.pt-BR.md new file mode 100644 index 00000000..56f99a37 --- /dev/null +++ b/README.pt-BR.md @@ -0,0 +1,71 @@ +[! [en] (https://img.shields.io/badge/lang-en-red.svg)] (https://github.com/denisbenjamim/perfidix/blob/master/README.md) + +# Perfidix - Sem discussões, apenas fatos. + +Perfidix é uma biblioteca java leve que permite aos usuários avaliar o código fonte. +Semelhante ao JUnit, as anotações podem ser colocadas antes dos métodos. +Dentro da invocação desses métodos, medições flexíveis são executadas. +Um plugin do eclipse (Perclipse, disponível em https://github.com/sebastiangraf/perclipse ) oferece fácil uso de qualquer método anotado. + +[![Build Status](https://secure.travis-ci.org/sebastiangraf/perfidix.png)](http://travis-ci.org/sebastiangraf/perfidix) + +##5 etapas para usar o Perfidix + +* Pegue o último jar no Github ou Maven + +```xml + + org.perfidix + perfidix + 4.0.0 + +``` + +* Anote seus métodos de bancada `@Bench`. Nota-se que estes métodos têm de ter o seguinte assinatura: `public (final) void method()`. +* Crie um novo objecto do tipo `Benchmark`. +* Adicione a classe com os métodos anotados desta forma `benchmarkObj.add(MyBenchmarkTest.class)`. +* Obtenha o `BenchmarkResult` com `benchmarkObj.run()`. +* Exiba o resultado desta forma `new TabularSummaryOutput (). VisitBenchmark (benchmarkResultObj)`. + +OU + +* Instale o plug-in Perclipse no site (http://sebastiangraf.github.com/perclipse/) e execute "Executar como" (consulte o Perclipse-Readme para obter mais informações: https://github.com/sebastiangraf/perclipse ). + +Para obter mais documentação e exemplo, consulte o pacote `org.perfidix.example`. + +##Conteúdo + +* README: arquivo leia-me original +* README.pt-BR: este arquivo leia-me +* LICENSE: arquivo de licença +* src: pasta de origem para o próprio perfidix +* pom.xml: pom simples (sim, usamos Maven) + +##Licença + +Este trabalho foi lançado em domínio público sob a licença BSD de 3 cláusulas + +##Outras informações + +A documentação até agora está acessível em http://perfidix.org (apontando para http://sebastiangraf.github.com/perfidix/ ). + +A estrutura foi apresentada no Jazoon '07 como um trabalho em andamento. O jornal pode ser encontrado [aqui](http://nbn-resolving.de/urn:nbn:de:bsz:352-opus-84446). + +Qualquer dúvida, basta entrar em contato com sebastian.graf AT uni-konstanz.de + +##Pessoas Envolvidas + +Perfidix é mantido por: + +* Sebastian Graf (núcleo da Perfidix e líder de Projeto) + +Os subprojetos concluídos foram: + +* [Nico Haase](mailto:nico@nicohaase.de) (benchmarks parametrizados) +* Nuray Gürler (Mocking e Maven-Website) +* Bastian Lemke (saída do gráfico) +* Alexander Onea (primeiro lançamento do núcleo) +* Tim Petrowski (primeiro lançamento do núcleo) +* Marc Kramis (líder de projeto até 2007) + + From 21976a27b53ecef82444ec6e49b75c33e06a509a Mon Sep 17 00:00:00 2001 From: Denis Benjamim Date: Mon, 17 May 2021 18:55:36 -0300 Subject: [PATCH 6/6] ajuste badge --- README.md | 14 +++++++------- README.pt-BR.md | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 181f1e16..2140776e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[! [en] (https://img.shields.io/badge/lang-en-red.svg)] (https://github.com/denisbenjamim/perfidix/blob/master/README.md) -[! [pt-BR] (https://img.shields.io/badge/lang-pt--BR-green.svg)] (https://github.com/denisbenjamim/perfidix/blob/master/README.pt-BR.md) +[![en](https://img.shields.io/badge/lang-en-red.svg)](https://github.com/denisbenjamim/perfidix/blob/master/README.md) +[![pt-BR](https://img.shields.io/badge/lang-pt--BR-green.svg)](https://github.com/denisbenjamim/perfidix/blob/master/README.pt-BR.md) # Perfidix - No discussions, Just facts. @@ -10,7 +10,7 @@ An eclipse plugin (Perclipse, available under https://github.com/sebastiangraf/p [![Build Status](https://secure.travis-ci.org/sebastiangraf/perfidix.png)](http://travis-ci.org/sebastiangraf/perfidix) -##5 steps how to use Perfidix +## 5 steps how to use Perfidix * Get the lastest jar over Github or Maven @@ -34,18 +34,18 @@ OR For further documentation and as an example, please refer to the `org.perfidix.example` package. -##Content +## Content * README: this readme file * LICENSE: license file * src: Source folder for perfidix itself * pom.xml: Simple pom (yes we use Maven) -##License +## License This work is released in the public domain under the BSD 3-clause license -##Further information +## Further information The documentation so far is accessible under http://perfidix.org (pointing to http://sebastiangraf.github.com/perfidix/). @@ -54,7 +54,7 @@ The framework was presented at the Jazoon '07 as work in progress. The paper can Any questions, just contact sebastian.graf AT uni-konstanz.de -##Involved People +## Involved People Perfidix is maintained by: diff --git a/README.pt-BR.md b/README.pt-BR.md index 56f99a37..f1b9895e 100644 --- a/README.pt-BR.md +++ b/README.pt-BR.md @@ -1,4 +1,4 @@ -[! [en] (https://img.shields.io/badge/lang-en-red.svg)] (https://github.com/denisbenjamim/perfidix/blob/master/README.md) +[![en](https://img.shields.io/badge/lang-en-red.svg)](https://github.com/denisbenjamim/perfidix/blob/master/README.md) # Perfidix - Sem discussões, apenas fatos. @@ -9,7 +9,7 @@ Um plugin do eclipse (Perclipse, disponível em https://github.com/sebastiangraf [![Build Status](https://secure.travis-ci.org/sebastiangraf/perfidix.png)](http://travis-ci.org/sebastiangraf/perfidix) -##5 etapas para usar o Perfidix +## 5 etapas para usar o Perfidix * Pegue o último jar no Github ou Maven @@ -33,7 +33,7 @@ OU Para obter mais documentação e exemplo, consulte o pacote `org.perfidix.example`. -##Conteúdo +## Conteúdo * README: arquivo leia-me original * README.pt-BR: este arquivo leia-me @@ -41,11 +41,11 @@ Para obter mais documentação e exemplo, consulte o pacote `org.perfidix.exampl * src: pasta de origem para o próprio perfidix * pom.xml: pom simples (sim, usamos Maven) -##Licença +## Licença Este trabalho foi lançado em domínio público sob a licença BSD de 3 cláusulas -##Outras informações +## Outras informações A documentação até agora está acessível em http://perfidix.org (apontando para http://sebastiangraf.github.com/perfidix/ ). @@ -53,7 +53,7 @@ A estrutura foi apresentada no Jazoon '07 como um trabalho em andamento. O jorna Qualquer dúvida, basta entrar em contato com sebastian.graf AT uni-konstanz.de -##Pessoas Envolvidas +## Pessoas Envolvidas Perfidix é mantido por: