From 59ea0e83f94ac0fc7ff224b1aea0a61e8d1acba2 Mon Sep 17 00:00:00 2001 From: amandelpie Date: Fri, 17 Jun 2022 18:32:59 +0300 Subject: [PATCH 1/8] Added the initial solution for the bug fix --- settings.gradle | 1 + utbot-analytics/build.gradle | 3 - .../main/java/guava/examples/math/Stats.java | 116 +++++++++++++ .../guava/examples/math/StatsAccumulator.java | 159 ++++++++++++++++++ .../examples/SummaryTestCaseGeneratorTest.kt | 53 ++++-- .../algorithms/SummaryReturnExampleTest.kt | 7 +- .../examples/controlflow/SummaryCycleTest.kt | 7 +- .../examples/inner/SummaryInnerCallsTest.kt | 6 +- .../examples/inner/SummaryNestedCallsTest.kt | 6 +- .../examples/ternary/SummaryTernary.kt | 5 +- .../src/test/kotlin}/math/SummaryIntMath.kt | 6 +- .../src/test/kotlin/math/SummaryOfMath.kt | 73 ++++++++ utbot-summary/build.gradle | 12 ++ .../org/utbot/summary/ast/JimpleToASTMap.kt | 6 +- .../summary/comment/SimpleSentenceBlock.kt | 2 +- 15 files changed, 431 insertions(+), 31 deletions(-) create mode 100644 utbot-sample/src/main/java/guava/examples/math/Stats.java create mode 100644 utbot-sample/src/main/java/guava/examples/math/StatsAccumulator.java rename {utbot-analytics/src/test/kotlin/org/utbot/analytics => utbot-summary-tests/src/test/kotlin}/examples/SummaryTestCaseGeneratorTest.kt (72%) rename {utbot-analytics/src/test/kotlin/org/utbot/analytics => utbot-summary-tests/src/test/kotlin}/examples/algorithms/SummaryReturnExampleTest.kt (99%) rename {utbot-analytics/src/test/kotlin/org/utbot/analytics => utbot-summary-tests/src/test/kotlin}/examples/controlflow/SummaryCycleTest.kt (96%) rename {utbot-analytics/src/test/kotlin/org/utbot/analytics => utbot-summary-tests/src/test/kotlin}/examples/inner/SummaryInnerCallsTest.kt (99%) rename {utbot-analytics/src/test/kotlin/org/utbot/analytics => utbot-summary-tests/src/test/kotlin}/examples/inner/SummaryNestedCallsTest.kt (93%) rename {utbot-analytics/src/test/kotlin/org/utbot/analytics => utbot-summary-tests/src/test/kotlin}/examples/ternary/SummaryTernary.kt (99%) rename {utbot-analytics/src/test/kotlin/org/utbot/analytics/guava => utbot-summary-tests/src/test/kotlin}/math/SummaryIntMath.kt (97%) create mode 100644 utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt diff --git a/settings.gradle b/settings.gradle index 4973300d4e..ac2c9d1279 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,4 +16,5 @@ include 'utbot-instrumentation-tests' include 'utbot-summary' include 'utbot-gradle' include 'utbot-maven' +include 'utbot-summary-tests' diff --git a/utbot-analytics/build.gradle b/utbot-analytics/build.gradle index 26c56fdcee..e6d06c3b18 100644 --- a/utbot-analytics/build.gradle +++ b/utbot-analytics/build.gradle @@ -5,7 +5,6 @@ configurations { mlmodels } - def osName = System.getProperty('os.name').toLowerCase().split()[0] if (osName == "mac") osName = "macosx" String classifier = osName + "-x86_64" @@ -49,11 +48,9 @@ dependencies { } test { - useJUnitPlatform { excludeTags 'Summary' } - } processResources { diff --git a/utbot-sample/src/main/java/guava/examples/math/Stats.java b/utbot-sample/src/main/java/guava/examples/math/Stats.java new file mode 100644 index 0000000000..ddfab0dd26 --- /dev/null +++ b/utbot-sample/src/main/java/guava/examples/math/Stats.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2012 The Guava Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package guava.examples.math; + +import java.io.Serializable; +import java.util.Iterator; + + +public final class Stats implements Serializable { + + private final long count; + private final double mean; + private final double sumOfSquaresOfDeltas; + private final double min; + private final double max; + + /** + * Internal constructor. Users should use {@link #of} or {@link StatsAccumulator#snapshot}. + * + *

To ensure that the created instance obeys its contract, the parameters should satisfy the + * following constraints. This is the callers responsibility and is not enforced here. + * + *

+ */ + Stats(long count, double mean, double sumOfSquaresOfDeltas, double min, double max) { + this.count = count; + this.mean = mean; + this.sumOfSquaresOfDeltas = sumOfSquaresOfDeltas; + this.min = min; + this.max = max; + } + + /** + * Returns statistics over a dataset containing the given values. + * + * @param values a series of values, which will be converted to {@code double} values (this may + * cause loss of precision) + */ + public static Stats of(Iterable values) { + StatsAccumulator accumulator = new StatsAccumulator(); + accumulator.addAll(values); + return accumulator.snapshot(); + } + + /** + * Returns statistics over a dataset containing the given values. + * + * @param values a series of values, which will be converted to {@code double} values (this may + * cause loss of precision) + */ + public static Stats of5(Iterator values) { + StatsAccumulator accumulator = new StatsAccumulator(); + accumulator.addAll(values); + return accumulator.snapshot(); + } + + /** + * Returns statistics over a dataset containing the given values. + * + * @param values a series of values + */ + public static Stats of1(double... values) { + StatsAccumulator acummulator = new StatsAccumulator(); + acummulator.addAll(values); + return acummulator.snapshot(); + } + + /** + * Returns statistics over a dataset containing the given values. + * + * @param values a series of values + */ + public static Stats of2(int... values) { + StatsAccumulator acummulator = new StatsAccumulator(); + acummulator.addAll(values); + return acummulator.snapshot(); + } + + /** + * Returns statistics over a dataset containing the given values. + * + * @param values a series of values, which will be converted to {@code double} values (this may + * cause loss of precision for longs of magnitude over 2^53 (slightly over 9e15)) + */ + public static Stats of3(long... values) { + StatsAccumulator acummulator = new StatsAccumulator(); + acummulator.addAll(values); + return acummulator.snapshot(); + } + + /** Returns the number of values. */ + public long count() { + return count; + } + + + private static final long serialVersionUID = 0; +} diff --git a/utbot-sample/src/main/java/guava/examples/math/StatsAccumulator.java b/utbot-sample/src/main/java/guava/examples/math/StatsAccumulator.java new file mode 100644 index 0000000000..57c9e93381 --- /dev/null +++ b/utbot-sample/src/main/java/guava/examples/math/StatsAccumulator.java @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2012 The Guava Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package guava.examples.math; + +import java.util.Iterator; + +import static java.lang.Double.*; + +public final class StatsAccumulator { + + // These fields must satisfy the requirements of Stats' constructor as well as those of the stat + // methods of this class. + private long count = 0; + private double mean = 0.0; // any finite value will do, we only use it to multiply by zero for sum + private double sumOfSquaresOfDeltas = 0.0; + private double min = NaN; // any value will do + private double max = NaN; // any value will do + + /** Adds the given value to the dataset. */ + public void add(double value) { + if (count == 0) { + count = 1; + mean = value; + min = value; + max = value; + if (!isFinite(value)) { + sumOfSquaresOfDeltas = NaN; + } + } else { + count++; + if (isFinite(value) && isFinite(mean)) { + // Art of Computer Programming vol. 2, Knuth, 4.2.2, (15) and (16) + double delta = value - mean; + mean += delta / count; + sumOfSquaresOfDeltas += delta * (value - mean); + } else { + mean = calculateNewMeanNonFinite(mean, value); + sumOfSquaresOfDeltas = NaN; + } + min = Math.min(min, value); + max = Math.max(max, value); + } + } + + /** + * Adds the given values to the dataset. + * + * @param values a series of values, which will be converted to {@code double} values (this may + * cause loss of precision) + */ + public void addAll(Iterable values) { + for (Number value : values) { + add(value.doubleValue()); + } + } + + /** + * Adds the given values to the dataset. + * + * @param values a series of values, which will be converted to {@code double} values (this may + * cause loss of precision) + */ + public void addAll(Iterator values) { + while (values.hasNext()) { + add(values.next().doubleValue()); + } + } + + /** + * Adds the given values to the dataset. + * + * @param values a series of values + */ + public void addAll(double... values) { + for (double value : values) { + add(value); + } + } + + /** + * Adds the given values to the dataset. + * + * @param values a series of values + */ + public void addAll(int... values) { + for (int value : values) { + add(value); + } + } + + /** + * Adds the given values to the dataset. + * + * @param values a series of values, which will be converted to {@code double} values (this may + * cause loss of precision for longs of magnitude over 2^53 (slightly over 9e15)) + */ + public void addAll(long... values) { + for (long value : values) { + add(value); + } + } + + /** Returns an immutable snapshot of the current statistics. */ + public Stats snapshot() { + return new Stats(count, mean, sumOfSquaresOfDeltas, min, max); + } + + /** Returns the number of values. */ + public long count() { + return count; + } + + /** + * Calculates the new value for the accumulated mean when a value is added, in the case where at + * least one of the previous mean and the value is non-finite. + */ + static double calculateNewMeanNonFinite(double previousMean, double value) { + /* + * Desired behaviour is to match the results of applying the naive mean formula. In particular, + * the update formula can subtract infinities in cases where the naive formula would add them. + * + * Consequently: + * 1. If the previous mean is finite and the new value is non-finite then the new mean is that + * value (whether it is NaN or infinity). + * 2. If the new value is finite and the previous mean is non-finite then the mean is unchanged + * (whether it is NaN or infinity). + * 3. If both the previous mean and the new value are non-finite and... + * 3a. ...either or both is NaN (so mean != value) then the new mean is NaN. + * 3b. ...they are both the same infinities (so mean == value) then the mean is unchanged. + * 3c. ...they are different infinities (so mean != value) then the new mean is NaN. + */ + if (isFinite(previousMean)) { + // This is case 1. + return value; + } else if (isFinite(value) || previousMean == value) { + // This is case 2. or 3b. + return previousMean; + } else { + // This is case 3a. or 3c. + return NaN; + } + } + + public static boolean isFinite(double value) { + return NEGATIVE_INFINITY < value && value < POSITIVE_INFINITY; + } +} diff --git a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt similarity index 72% rename from utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/SummaryTestCaseGeneratorTest.kt rename to utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index 1cdca4b148..be9be8d6e9 100644 --- a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -1,4 +1,4 @@ -package org.utbot.analytics.examples +package examples import org.utbot.common.WorkaroundReason import org.utbot.common.workaround @@ -15,6 +15,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtMethod import org.utbot.framework.plugin.api.util.UtContext +import org.utbot.summary.comment.nextSynonyms import org.utbot.summary.summarize import kotlin.reflect.KClass import kotlin.reflect.KFunction @@ -25,9 +26,7 @@ import kotlin.reflect.KFunction4 import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Tag -@Tag("Summary") open class SummaryTestCaseGeneratorTest( testClass: KClass<*>, testCodeGeneration: Boolean = true, @@ -53,38 +52,43 @@ open class SummaryTestCaseGeneratorTest( coverage: CoverageMatcher = DoNotCalculate, mockStrategy: MockStrategyApi = MockStrategyApi.NO_MOCKS, summaryKeys: List, + methodNames: List = listOf(), displayNames: List = listOf() - ) = check(method, mockStrategy, coverage, summaryKeys, displayNames) + ) = check(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) protected inline fun checkOneArgument( method: KFunction2<*, T, R>, coverage: CoverageMatcher = DoNotCalculate, mockStrategy: MockStrategyApi = MockStrategyApi.NO_MOCKS, summaryKeys: List, + methodNames: List = listOf(), displayNames: List = listOf() - ) = check(method, mockStrategy, coverage, summaryKeys, displayNames) + ) = check(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) protected inline fun checkTwoArguments( method: KFunction3<*, T1, T2, R>, coverage: CoverageMatcher = DoNotCalculate, mockStrategy: MockStrategyApi = MockStrategyApi.NO_MOCKS, summaryKeys: List, + methodNames: List = listOf(), displayNames: List = listOf() - ) = check(method, mockStrategy, coverage, summaryKeys, displayNames) + ) = check(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) protected inline fun checkThreeArguments( method: KFunction4<*, T1, T2, T3, R>, coverage: CoverageMatcher = DoNotCalculate, mockStrategy: MockStrategyApi = MockStrategyApi.NO_MOCKS, summaryKeys: List, + methodNames: List = listOf(), displayNames: List = listOf() - ) = check(method, mockStrategy, coverage, summaryKeys, displayNames) + ) = check(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) inline fun check( method: KFunction, mockStrategy: MockStrategyApi, coverageMatcher: CoverageMatcher, summaryKeys: List, + methodNames: List, displayNames: List ) { workaround(WorkaroundReason.HACK) { @@ -98,9 +102,19 @@ open class SummaryTestCaseGeneratorTest( val testCase = executionsModel(utMethod, mockStrategy) testCase.summarize(searchDirectory) testCase.executions.checkMatchersWithTextSummary(summaryKeys) + testCase.executions.checkMatchersWithMethodNames(methodNames) testCase.executions.checkMatchersWithDisplayNames(displayNames) } + private fun String.normalize(): String { + var result = this.replace("[\\n\\t\\s ]".toRegex(), "") + nextSynonyms.forEach { + result = result.replace(it, "") + } + return result + } + + fun List.checkMatchersWithTextSummary( summaryTextKeys: List, ) { @@ -108,9 +122,27 @@ open class SummaryTestCaseGeneratorTest( return } val notMatchedExecutions = this.filter { execution -> - summaryTextKeys.none { summaryKey -> execution.summary?.contains(summaryKey) == true } + summaryTextKeys.none { summaryKey -> val normalize = execution.summary?.toString()?.normalize() + println("Execution") + println(normalize) + println("SummaryKey") + println(summaryKey.normalize()) + + normalize?.contains(summaryKey.normalize()) == true } + } + Assertions.assertTrue(notMatchedExecutions.isEmpty()) { "Not matched comments ${summaries(notMatchedExecutions)}" } + } + + fun List.checkMatchersWithMethodNames( + methodNames: List, + ) { + if (methodNames.isEmpty()) { + return + } + val notMatchedExecutions = this.filter { execution -> + methodNames.none { methodName -> execution.testMethodName?.equals(methodName) == true } } - Assertions.assertTrue(notMatchedExecutions.isEmpty()) { "Not matched summaries ${summaries(notMatchedExecutions)}" } + Assertions.assertTrue(notMatchedExecutions.isEmpty()) { "Not matched display names ${summaries(notMatchedExecutions)}" } } fun List.checkMatchersWithDisplayNames( @@ -122,7 +154,7 @@ open class SummaryTestCaseGeneratorTest( val notMatchedExecutions = this.filter { execution -> displayNames.none { displayName -> execution.displayName?.equals(displayName) == true } } - Assertions.assertTrue(notMatchedExecutions.isEmpty()) { "Not matched summaries ${summaries(notMatchedExecutions)}" } + Assertions.assertTrue(notMatchedExecutions.isEmpty()) { "Not matched display names ${summaries(notMatchedExecutions)}" } } private fun summaries(executions: List): String { @@ -132,5 +164,4 @@ open class SummaryTestCaseGeneratorTest( } return result } - } \ No newline at end of file diff --git a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/algorithms/SummaryReturnExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt similarity index 99% rename from utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/algorithms/SummaryReturnExampleTest.kt rename to utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt index 7d5e23e262..622478f7aa 100644 --- a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/algorithms/SummaryReturnExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt @@ -1,9 +1,10 @@ -package org.utbot.analytics.examples.algorithms +package examples.algorithms -import org.utbot.analytics.examples.SummaryTestCaseGeneratorTest +import examples.SummaryTestCaseGeneratorTest +import org.junit.jupiter.api.Tag import org.utbot.examples.algorithms.ReturnExample import org.junit.jupiter.api.Test - +@Tag("Summary") class SummaryReturnExampleTest : SummaryTestCaseGeneratorTest( ReturnExample::class, ) { diff --git a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/controlflow/SummaryCycleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt similarity index 96% rename from utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/controlflow/SummaryCycleTest.kt rename to utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt index f5e655d102..e5df077b33 100644 --- a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/controlflow/SummaryCycleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt @@ -1,9 +1,10 @@ -package org.utbot.analytics.examples.controlflow +package examples.controlflow -import org.utbot.analytics.examples.SummaryTestCaseGeneratorTest +import examples.SummaryTestCaseGeneratorTest +import org.junit.jupiter.api.Tag import org.utbot.examples.controlflow.Cycles import org.junit.jupiter.api.Test - +@Tag("Summary") class SummaryCycleTest : SummaryTestCaseGeneratorTest( Cycles::class, ) { diff --git a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/inner/SummaryInnerCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt similarity index 99% rename from utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/inner/SummaryInnerCallsTest.kt rename to utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt index 976f3d969e..901feb9bbb 100644 --- a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/inner/SummaryInnerCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt @@ -1,9 +1,11 @@ -package org.utbot.analytics.examples.inner +package examples.inner -import org.utbot.analytics.examples.SummaryTestCaseGeneratorTest +import examples.SummaryTestCaseGeneratorTest +import org.junit.jupiter.api.Tag import org.utbot.examples.inner.InnerCalls import org.junit.jupiter.api.Test +@Tag("Summary") class SummaryInnerCallsTest : SummaryTestCaseGeneratorTest( InnerCalls::class, ) { diff --git a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/inner/SummaryNestedCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt similarity index 93% rename from utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/inner/SummaryNestedCallsTest.kt rename to utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt index 3e831c2e9e..6084cdbb05 100644 --- a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/inner/SummaryNestedCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt @@ -1,9 +1,11 @@ -package org.utbot.analytics.examples.inner +package examples.inner -import org.utbot.analytics.examples.SummaryTestCaseGeneratorTest +import examples.SummaryTestCaseGeneratorTest +import org.junit.jupiter.api.Tag import org.utbot.examples.inner.NestedCalls import org.junit.jupiter.api.Test +@Tag("Summary") class SummaryNestedCallsTest : SummaryTestCaseGeneratorTest( NestedCalls::class, ) { diff --git a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/ternary/SummaryTernary.kt b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernary.kt similarity index 99% rename from utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/ternary/SummaryTernary.kt rename to utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernary.kt index 8d3571feb1..69249e2bf7 100644 --- a/utbot-analytics/src/test/kotlin/org/utbot/analytics/examples/ternary/SummaryTernary.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernary.kt @@ -1,10 +1,11 @@ -package org.utbot.analytics.examples.ternary +package examples.ternary -import org.utbot.analytics.examples.SummaryTestCaseGeneratorTest +import examples.SummaryTestCaseGeneratorTest import org.utbot.examples.ternary.Ternary import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test +@Tag("Summary") class SummaryTernary : SummaryTestCaseGeneratorTest( Ternary::class, ) { diff --git a/utbot-analytics/src/test/kotlin/org/utbot/analytics/guava/math/SummaryIntMath.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMath.kt similarity index 97% rename from utbot-analytics/src/test/kotlin/org/utbot/analytics/guava/math/SummaryIntMath.kt rename to utbot-summary-tests/src/test/kotlin/math/SummaryIntMath.kt index d92c84f9d3..9f6fff80fa 100644 --- a/utbot-analytics/src/test/kotlin/org/utbot/analytics/guava/math/SummaryIntMath.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMath.kt @@ -1,9 +1,11 @@ -package org.utbot.analytics.guava.math +package math -import org.utbot.analytics.examples.SummaryTestCaseGeneratorTest +import examples.SummaryTestCaseGeneratorTest import guava.examples.math.IntMath +import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test +@Tag("Summary") class SummaryIntMath : SummaryTestCaseGeneratorTest( IntMath::class, ) { diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt new file mode 100644 index 0000000000..149cedc18b --- /dev/null +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt @@ -0,0 +1,73 @@ +package math + +import examples.SummaryTestCaseGeneratorTest +import guava.examples.math.Stats +import org.junit.jupiter.api.Test +import org.utbot.examples.DoNotCalculate +import org.utbot.framework.plugin.api.MockStrategyApi + +class SummaryOfMath : SummaryTestCaseGeneratorTest( + Stats::class, +) { + @Test + fun testOf1() { + val summary1 = "Test calls StatsAccumulator::addAll,\n" + + " there it triggers recursion of addAll once, \n" + + "Test throws NullPointerException in: acummulator.addAll(values);\n" + val summary2 = "Test calls StatsAccumulator::addAll,\n" + + " there it does not iterate for(int value: values), \n" + + "Test later calls StatsAccumulator::snapshot,\n" + + " there it returns from: return new Stats(count, mean, sumOfSquaresOfDeltas, min, max);\n" + + " \n" + + "Test then returns from: return acummulator.snapshot();" + val summary3 = "Test calls StatsAccumulator::addAll,\n" + + " there it iterates the loop for(int value: values) once. \n" + + "Test later calls StatsAccumulator::snapshot,\n" + + " there it returns from: return new Stats(count, mean, sumOfSquaresOfDeltas, min, max);\n" + + " \n" + + "Test then returns from: return acummulator.snapshot();" + val summary4 = "Test calls StatsAccumulator::addAll,\n" + + " there it iterates the loop for(int value: values) twice. \n" + + "Test later calls StatsAccumulator::snapshot,\n" + + " there it returns from: return new Stats(count, mean, sumOfSquaresOfDeltas, min, max);\n" + + " \n" + + "Test later returns from: return acummulator.snapshot();\n" + + val methodName1 = "testOf2_StatsAccumulatorAddAll" + val methodName2 = "testOf2_snapshot" + val methodName3 = "testOf2_IterateForEachLoop" + val methodName4 = "testOf2_IterateForEachLoop_1" + + val displayName1 = "acummulator.addAll(values) : True -> ThrowNullPointerException" + val displayName2 = "snapshot -> return new Stats(count, mean, sumOfSquaresOfDeltas, min, max)" + val displayName3 = "addAll -> return new Stats(count, mean, sumOfSquaresOfDeltas, min, max)" + val displayName4 = "addAll -> return new Stats(count, mean, sumOfSquaresOfDeltas, min, max)" + + val method = Stats::of2 + val mockStrategy = MockStrategyApi.NO_MOCKS + val coverage = DoNotCalculate + + val summaryKeys = listOf( + summary1, + summary2, + summary3, + summary4 + ) + + val displayNames = listOf( + displayName1, + displayName2, + displayName3, + displayName4 + ) + + val methodNames = listOf( + methodName1, + methodName2, + methodName3, + methodName4 + ) + + check(method, mockStrategy, coverage, summaryKeys, methodNames, displayNames) + } +} \ No newline at end of file diff --git a/utbot-summary/build.gradle b/utbot-summary/build.gradle index d0d8ff1c2e..96dbfcbdc1 100644 --- a/utbot-summary/build.gradle +++ b/utbot-summary/build.gradle @@ -4,13 +4,25 @@ apply plugin: "java" dependencies { implementation "com.github.UnitTestBot:soot:${soot_commit_hash}" + api project(":utbot-framework") api project(':utbot-framework-api') implementation(project(':utbot-instrumentation')) + testImplementation project(':utbot-sample') + testImplementation group: 'junit', name: 'junit', version: junit4_version + implementation group: 'com.github.haifengl', name: 'smile-kotlin', version: '2.6.0' implementation group: 'com.github.haifengl', name: 'smile-core', version: '2.6.0' implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlin_logging_version implementation group: 'com.github.javaparser', name: 'javaparser-core', version: '3.22.1' + + testCompile project(':utbot-framework').sourceSets.test.output +} + +test { + useJUnitPlatform { + excludeTags 'Summary' + } } \ No newline at end of file diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt index 3a4c048e85..b7515970a8 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt @@ -49,7 +49,7 @@ class JimpleToASTMap(stmts: Iterable, methodDeclaration: MethodDeclaration val stmtToASTNode = mutableMapOf() init { - removeComments(methodDeclaration) + removeComments(methodDeclaration) // TODO: Zinoviev probably - this is a place where I can obtain comments of tested methods and parse it by tags and so on mapTernaryConditional(methodDeclaration, stmts) val ifStmtToNodeMap = createIfStmtToASTNodesMap(methodDeclaration) for (stmt in stmts) { @@ -61,7 +61,9 @@ class JimpleToASTMap(stmts: Iterable, methodDeclaration: MethodDeclaration if (ASTNode != null) { if (ASTNode is IfStmt && stmt is JIfStmt) { - ASTNode = ifStmtToNodeMap[ASTNode]?.remove() + //ASTNode = ifStmtToNodeMap[ASTNode]?.remove() // TODO: Zinoviev + val nodes = ifStmtToNodeMap[ASTNode] + if(!nodes.isNullOrEmpty()) ASTNode = nodes.remove() } else if (stmt is JReturnStmt) { ASTNode = validateReturnASTNode(ASTNode) } diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt index 2b0129a264..b9f92fd9fc 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt @@ -92,7 +92,7 @@ class SimpleSentenceBlock(val stringTemplates: StringsTemplatesInterface) { result += stringTemplates.sentenceBeginning + " " restartSentence = false } - result += "${nextSynonyms.random()} $nextSentenceBlock" + result += "${nextSynonyms.random()} $nextSentenceBlock" // TODO: Zinoviev - add seed for test purposes if (nextSentenceBlock.trim().endsWith(DOT_SYMBOL)) { restartSentence = true From 98657f900d68b4ebd3403595cca52df105091cd5 Mon Sep 17 00:00:00 2001 From: amandelpie Date: Fri, 17 Jun 2022 20:15:27 +0300 Subject: [PATCH 2/8] Disabled tests --- utbot-summary-tests/build.gradle | 17 +++++++++++++++++ .../examples/SummaryTestCaseGeneratorTest.kt | 11 +++-------- .../algorithms/SummaryReturnExampleTest.kt | 4 +++- .../examples/controlflow/SummaryCycleTest.kt | 4 +++- .../examples/inner/SummaryInnerCallsTest.kt | 4 +++- .../examples/inner/SummaryNestedCallsTest.kt | 5 +++-- .../kotlin/examples/ternary/SummaryTernary.kt | 4 +++- .../src/test/kotlin/math/SummaryIntMath.kt | 3 ++- utbot-summary/build.gradle | 12 ------------ 9 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 utbot-summary-tests/build.gradle diff --git a/utbot-summary-tests/build.gradle b/utbot-summary-tests/build.gradle new file mode 100644 index 0000000000..cb460cbd1d --- /dev/null +++ b/utbot-summary-tests/build.gradle @@ -0,0 +1,17 @@ +apply from: "${parent.projectDir}/gradle/include/jvm-project.gradle" +apply plugin: "java" + +evaluationDependsOn(':utbot-framework') +compileTestJava.dependsOn tasks.getByPath(':utbot-framework:testClasses') + +dependencies { + implementation(project(":utbot-framework")) + implementation(project(':utbot-instrumentation')) + testImplementation project(':utbot-sample') + testImplementation group: 'junit', name: 'junit', version: junit4_version + testCompile project(':utbot-framework').sourceSets.test.output +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index be9be8d6e9..fef0e89b15 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -1,5 +1,6 @@ package examples +import org.junit.jupiter.api.* import org.utbot.common.WorkaroundReason import org.utbot.common.workaround import org.utbot.examples.AbstractTestCaseGeneratorTest @@ -23,10 +24,9 @@ import kotlin.reflect.KFunction1 import kotlin.reflect.KFunction2 import kotlin.reflect.KFunction3 import kotlin.reflect.KFunction4 -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions -import org.junit.jupiter.api.BeforeEach + +@Disabled open class SummaryTestCaseGeneratorTest( testClass: KClass<*>, testCodeGeneration: Boolean = true, @@ -123,11 +123,6 @@ open class SummaryTestCaseGeneratorTest( } val notMatchedExecutions = this.filter { execution -> summaryTextKeys.none { summaryKey -> val normalize = execution.summary?.toString()?.normalize() - println("Execution") - println(normalize) - println("SummaryKey") - println(summaryKey.normalize()) - normalize?.contains(summaryKey.normalize()) == true } } Assertions.assertTrue(notMatchedExecutions.isEmpty()) { "Not matched comments ${summaries(notMatchedExecutions)}" } diff --git a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt index 622478f7aa..e2e5181004 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/algorithms/SummaryReturnExampleTest.kt @@ -1,10 +1,12 @@ package examples.algorithms import examples.SummaryTestCaseGeneratorTest +import org.junit.Ignore +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.utbot.examples.algorithms.ReturnExample import org.junit.jupiter.api.Test -@Tag("Summary") +@Disabled class SummaryReturnExampleTest : SummaryTestCaseGeneratorTest( ReturnExample::class, ) { diff --git a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt index e5df077b33..80a7f05ba6 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/controlflow/SummaryCycleTest.kt @@ -1,10 +1,12 @@ package examples.controlflow import examples.SummaryTestCaseGeneratorTest +import org.junit.Ignore +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.utbot.examples.controlflow.Cycles import org.junit.jupiter.api.Test -@Tag("Summary") +@Disabled class SummaryCycleTest : SummaryTestCaseGeneratorTest( Cycles::class, ) { diff --git a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt index 901feb9bbb..19d077b972 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryInnerCallsTest.kt @@ -1,11 +1,13 @@ package examples.inner import examples.SummaryTestCaseGeneratorTest +import org.junit.Ignore +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.utbot.examples.inner.InnerCalls import org.junit.jupiter.api.Test -@Tag("Summary") +@Disabled class SummaryInnerCallsTest : SummaryTestCaseGeneratorTest( InnerCalls::class, ) { diff --git a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt index 6084cdbb05..e6e0eaa820 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/inner/SummaryNestedCallsTest.kt @@ -1,11 +1,12 @@ package examples.inner import examples.SummaryTestCaseGeneratorTest +import org.junit.Ignore +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.utbot.examples.inner.NestedCalls import org.junit.jupiter.api.Test - -@Tag("Summary") +@Disabled class SummaryNestedCallsTest : SummaryTestCaseGeneratorTest( NestedCalls::class, ) { diff --git a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernary.kt b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernary.kt index 69249e2bf7..f5a3bfc4db 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernary.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/ternary/SummaryTernary.kt @@ -1,11 +1,13 @@ package examples.ternary import examples.SummaryTestCaseGeneratorTest +import org.junit.Ignore +import org.junit.jupiter.api.Disabled import org.utbot.examples.ternary.Ternary import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test -@Tag("Summary") +@Disabled class SummaryTernary : SummaryTestCaseGeneratorTest( Ternary::class, ) { diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMath.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMath.kt index 9f6fff80fa..37e4ad24ee 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryIntMath.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryIntMath.kt @@ -2,10 +2,11 @@ package math import examples.SummaryTestCaseGeneratorTest import guava.examples.math.IntMath +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test -@Tag("Summary") +@Disabled class SummaryIntMath : SummaryTestCaseGeneratorTest( IntMath::class, ) { diff --git a/utbot-summary/build.gradle b/utbot-summary/build.gradle index 96dbfcbdc1..d0d8ff1c2e 100644 --- a/utbot-summary/build.gradle +++ b/utbot-summary/build.gradle @@ -4,25 +4,13 @@ apply plugin: "java" dependencies { implementation "com.github.UnitTestBot:soot:${soot_commit_hash}" - api project(":utbot-framework") api project(':utbot-framework-api') implementation(project(':utbot-instrumentation')) - testImplementation project(':utbot-sample') - testImplementation group: 'junit', name: 'junit', version: junit4_version - implementation group: 'com.github.haifengl', name: 'smile-kotlin', version: '2.6.0' implementation group: 'com.github.haifengl', name: 'smile-core', version: '2.6.0' implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlin_logging_version implementation group: 'com.github.javaparser', name: 'javaparser-core', version: '3.22.1' - - testCompile project(':utbot-framework').sourceSets.test.output -} - -test { - useJUnitPlatform { - excludeTags 'Summary' - } } \ No newline at end of file From 5c1d8d6f996058724c9a5b6eabe38fa1c4a6adb4 Mon Sep 17 00:00:00 2001 From: amandelpie Date: Mon, 20 Jun 2022 13:31:04 +0300 Subject: [PATCH 3/8] Disabled integration tests --- .../src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index fef0e89b15..bea29e7992 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -29,7 +29,7 @@ import kotlin.reflect.KFunction4 @Disabled open class SummaryTestCaseGeneratorTest( testClass: KClass<*>, - testCodeGeneration: Boolean = true, + testCodeGeneration: Boolean = false, languagePipelines: List = listOf( CodeGenerationLanguageLastStage(CodegenLanguage.JAVA), CodeGenerationLanguageLastStage(CodegenLanguage.KOTLIN, TestExecution) From 08b6dc351035360c62628edbc59df3d30ed56e5a Mon Sep 17 00:00:00 2001 From: amandelpie Date: Mon, 20 Jun 2022 15:20:03 +0300 Subject: [PATCH 4/8] Removed comments --- .../src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt | 3 +-- .../kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt index b7515970a8..13b0ed1673 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt @@ -49,7 +49,7 @@ class JimpleToASTMap(stmts: Iterable, methodDeclaration: MethodDeclaration val stmtToASTNode = mutableMapOf() init { - removeComments(methodDeclaration) // TODO: Zinoviev probably - this is a place where I can obtain comments of tested methods and parse it by tags and so on + removeComments(methodDeclaration) mapTernaryConditional(methodDeclaration, stmts) val ifStmtToNodeMap = createIfStmtToASTNodesMap(methodDeclaration) for (stmt in stmts) { @@ -61,7 +61,6 @@ class JimpleToASTMap(stmts: Iterable, methodDeclaration: MethodDeclaration if (ASTNode != null) { if (ASTNode is IfStmt && stmt is JIfStmt) { - //ASTNode = ifStmtToNodeMap[ASTNode]?.remove() // TODO: Zinoviev val nodes = ifStmtToNodeMap[ASTNode] if(!nodes.isNullOrEmpty()) ASTNode = nodes.remove() } else if (stmt is JReturnStmt) { diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt index b9f92fd9fc..2b0129a264 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleSentenceBlock.kt @@ -92,7 +92,7 @@ class SimpleSentenceBlock(val stringTemplates: StringsTemplatesInterface) { result += stringTemplates.sentenceBeginning + " " restartSentence = false } - result += "${nextSynonyms.random()} $nextSentenceBlock" // TODO: Zinoviev - add seed for test purposes + result += "${nextSynonyms.random()} $nextSentenceBlock" if (nextSentenceBlock.trim().endsWith(DOT_SYMBOL)) { restartSentence = true From 84edab4dd92f27e06cc708cf2c1731aa97ccf488 Mon Sep 17 00:00:00 2001 From: amandelpie Date: Mon, 20 Jun 2022 15:26:41 +0300 Subject: [PATCH 5/8] Added comments and renamed methods --- .../src/main/java/guava/examples/math/Stats.java | 12 ++++++------ .../src/test/kotlin/math/SummaryOfMath.kt | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/utbot-sample/src/main/java/guava/examples/math/Stats.java b/utbot-sample/src/main/java/guava/examples/math/Stats.java index ddfab0dd26..a99a37fbda 100644 --- a/utbot-sample/src/main/java/guava/examples/math/Stats.java +++ b/utbot-sample/src/main/java/guava/examples/math/Stats.java @@ -27,7 +27,7 @@ public final class Stats implements Serializable { private final double max; /** - * Internal constructor. Users should use {@link #of} or {@link StatsAccumulator#snapshot}. + * Internal constructor. Users should use {@link #ofIterable} or {@link StatsAccumulator#snapshot}. * *

To ensure that the created instance obeys its contract, the parameters should satisfy the * following constraints. This is the callers responsibility and is not enforced here. @@ -54,7 +54,7 @@ public final class Stats implements Serializable { * @param values a series of values, which will be converted to {@code double} values (this may * cause loss of precision) */ - public static Stats of(Iterable values) { + public static Stats ofIterable(Iterable values) { StatsAccumulator accumulator = new StatsAccumulator(); accumulator.addAll(values); return accumulator.snapshot(); @@ -66,7 +66,7 @@ public static Stats of(Iterable values) { * @param values a series of values, which will be converted to {@code double} values (this may * cause loss of precision) */ - public static Stats of5(Iterator values) { + public static Stats ofIterator(Iterator values) { StatsAccumulator accumulator = new StatsAccumulator(); accumulator.addAll(values); return accumulator.snapshot(); @@ -77,7 +77,7 @@ public static Stats of5(Iterator values) { * * @param values a series of values */ - public static Stats of1(double... values) { + public static Stats ofDoubles(double... values) { StatsAccumulator acummulator = new StatsAccumulator(); acummulator.addAll(values); return acummulator.snapshot(); @@ -88,7 +88,7 @@ public static Stats of1(double... values) { * * @param values a series of values */ - public static Stats of2(int... values) { + public static Stats ofInts(int... values) { StatsAccumulator acummulator = new StatsAccumulator(); acummulator.addAll(values); return acummulator.snapshot(); @@ -100,7 +100,7 @@ public static Stats of2(int... values) { * @param values a series of values, which will be converted to {@code double} values (this may * cause loss of precision for longs of magnitude over 2^53 (slightly over 9e15)) */ - public static Stats of3(long... values) { + public static Stats ofLongs(long... values) { StatsAccumulator acummulator = new StatsAccumulator(); acummulator.addAll(values); return acummulator.snapshot(); diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt index 149cedc18b..ed94b1025a 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt @@ -6,6 +6,12 @@ import org.junit.jupiter.api.Test import org.utbot.examples.DoNotCalculate import org.utbot.framework.plugin.api.MockStrategyApi +/** + * It runs test generation for the poor analogue of the Stats.of method ported from the guava-26.0 framework + * and validates generated docs, display names and test method names. + * + * @see Related issue + */ class SummaryOfMath : SummaryTestCaseGeneratorTest( Stats::class, ) { @@ -43,7 +49,7 @@ class SummaryOfMath : SummaryTestCaseGeneratorTest( val displayName3 = "addAll -> return new Stats(count, mean, sumOfSquaresOfDeltas, min, max)" val displayName4 = "addAll -> return new Stats(count, mean, sumOfSquaresOfDeltas, min, max)" - val method = Stats::of2 + val method = Stats::ofInts val mockStrategy = MockStrategyApi.NO_MOCKS val coverage = DoNotCalculate From b330a854dd833c6e0724524346702ee1237a4123 Mon Sep 17 00:00:00 2001 From: amandelpie Date: Mon, 20 Jun 2022 15:30:25 +0300 Subject: [PATCH 6/8] Renamed method --- utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt index ed94b1025a..844b3af945 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt @@ -16,7 +16,7 @@ class SummaryOfMath : SummaryTestCaseGeneratorTest( Stats::class, ) { @Test - fun testOf1() { + fun testOfInts() { val summary1 = "Test calls StatsAccumulator::addAll,\n" + " there it triggers recursion of addAll once, \n" + "Test throws NullPointerException in: acummulator.addAll(values);\n" From 2522ab68cd37b317a03cfb2576c4cc1f5918dc7c Mon Sep 17 00:00:00 2001 From: amandelpie Date: Mon, 20 Jun 2022 15:40:38 +0300 Subject: [PATCH 7/8] Fixed test after the method renaming --- utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt index 844b3af945..22260a231c 100644 --- a/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt +++ b/utbot-summary-tests/src/test/kotlin/math/SummaryOfMath.kt @@ -39,10 +39,10 @@ class SummaryOfMath : SummaryTestCaseGeneratorTest( " \n" + "Test later returns from: return acummulator.snapshot();\n" - val methodName1 = "testOf2_StatsAccumulatorAddAll" - val methodName2 = "testOf2_snapshot" - val methodName3 = "testOf2_IterateForEachLoop" - val methodName4 = "testOf2_IterateForEachLoop_1" + val methodName1 = "testOfInts_StatsAccumulatorAddAll" + val methodName2 = "testOfInts_snapshot" + val methodName3 = "testOfInts_IterateForEachLoop" + val methodName4 = "testOfInts_IterateForEachLoop_1" val displayName1 = "acummulator.addAll(values) : True -> ThrowNullPointerException" val displayName2 = "snapshot -> return new Stats(count, mean, sumOfSquaresOfDeltas, min, max)" From cdbb8fba964fa8ed3e182472bc15c3382bc23362 Mon Sep 17 00:00:00 2001 From: amandelpie Date: Wed, 22 Jun 2022 12:48:29 +0300 Subject: [PATCH 8/8] Fixed the regular expression --- .../test/kotlin/examples/SummaryTestCaseGeneratorTest.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt index bea29e7992..443bee938e 100644 --- a/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt +++ b/utbot-summary-tests/src/test/kotlin/examples/SummaryTestCaseGeneratorTest.kt @@ -106,8 +106,13 @@ open class SummaryTestCaseGeneratorTest( testCase.executions.checkMatchersWithDisplayNames(displayNames) } + /** + * It removes from the String all whitespaces, tabs etc. + * + * @see Explanation of the used regular expression. + */ private fun String.normalize(): String { - var result = this.replace("[\\n\\t\\s ]".toRegex(), "") + var result = this.replace("\\s+".toRegex(), "") nextSynonyms.forEach { result = result.replace(it, "") }