Skip to content

Empty test for Stats of(double... values) due to wrong documentation with /r/n #271

Description

@amandelpie

Description

If we run test generation without mocks for the following method

  /**
   * Returns statistics over a dataset containing the given values.
   *
   * @param values a series of values
   */
  public static Stats of(double... values) {
    StatsAccumulator acummulator = new StatsAccumulator();
    acummulator.addAll(values);
    return acummulator.snapshot();
  }

it will generates empty test and we obtain the following error

2022-06-21 17:13:52,707 [ 992103]  ERROR - pplication.impl.LaterInvocator - Wrong line separators: '...e(mean)) {\r\n *     d...' at offset 2757 
java.lang.AssertionError: Wrong line separators: '...e(mean)) {\r\n *     d...' at offset 2757
	at com.intellij.openapi.util.text.StringUtil.assertValidSeparators(StringUtil.java:2450)
	at com.intellij.openapi.editor.impl.DocumentImpl.assertValidSeparators(DocumentImpl.java:690)
	at com.intellij.openapi.editor.impl.DocumentImpl.replaceString(DocumentImpl.java:599)
	at com.intellij.openapi.editor.impl.DocumentImpl.lambda$setText$2(DocumentImpl.java:1061)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:211)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:177)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:167)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:153)
	at com.intellij.openapi.editor.impl.DocumentImpl.setText(DocumentImpl.java:1066)
	at org.utbot.intellij.plugin.generator.TestGenerator$addTestMethodsAndSaveReports$$inlined$executeCommand$1.run(actions.kt:13)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:211)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:177)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:167)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:153)
	at org.utbot.intellij.plugin.generator.TestGenerator.addTestMethodsAndSaveReports(TestGenerator.kt:419)
	at org.utbot.intellij.plugin.generator.TestGenerator.generateTestsInternal(TestGenerator.kt:88)
	at org.utbot.intellij.plugin.generator.TestGenerator.access$generateTestsInternal(TestGenerator.kt:67)
	at org.utbot.intellij.plugin.generator.TestGenerator$generateTests$1.run(TestGenerator.kt:70)
	at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$5(WriteCommandAction.java:351)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl$1.run(WriteCommandAction.java:105)
	at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
	at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$1(WriteCommandAction.java:246)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:980)
	at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:245)
	at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:303)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:187)
	at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:305)
	at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:244)
	at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:225)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:107)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:351)
	at org.utbot.intellij.plugin.generator.TestGenerator.generateTests(TestGenerator.kt:69)
	at org.utbot.intellij.plugin.ui.UtTestsDialogProcessor$createTests$2$1$run$$inlined$invokeLater$1.run(actions.kt:61)
	at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:201)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802)
	at com.intellij.openapi.application.impl.ApplicationImpl.lambda$invokeLater$4(ApplicationImpl.java:322)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:84)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:132)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:47)
	at com.intellij.openapi.application.impl.FlushQueue$FlushNow.run(FlushQueue.java:188)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:967)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:839)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:450)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:744)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:449)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:497)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
2022-06-21 17:13:52,708 [ 992104]  ERROR - pplication.impl.LaterInvocator - IntelliJ IDEA 2020.2  Build #IC-202.6397.94 
2022-06-21 17:13:52,708 [ 992104]  ERROR - pplication.impl.LaterInvocator - JDK: 11.0.7; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o. 
2022-06-21 17:13:52,708 [ 992104]  ERROR - pplication.impl.LaterInvocator - OS: Windows 10 
2022-06-21 17:13:52,708 [ 992104]  ERROR - pplication.impl.LaterInvocator - Plugin to blame: UnitTestBot version: 1.0-SNAPSHOT 
2022-06-21 17:13:52,708 [ 992104]  ERROR - pplication.impl.LaterInvocator - Last Action: org.utbot.intellij.plugin.ui.actions.GenerateTestsAction 

To Reproduce

Steps to reproduce the behavior:

  1. Run the SampleSolutions/guava-26 project in IntelliJ Idea
  2. Use plugin to generate tests for Stats of(double... values)
  3. Open the generated test

Expected behavior

Tests are supposed to be generated.

Actual behavior

Empty class without test methods

Environment

Windows 10

Additional context

Looks like the problem in the comment generation, for example the following JavaDoc was generated

Test calls StatsAccumulator::addAll,
    there it iterates the loop for(double value: values) twice,
        inside this loop, the test calls StatsAccumulator::add,
        there it executes conditions:
            (count == 0): True
            (!isFinite(value)): True
        calls StatsAccumulator::add,
        there it executes conditions:
            (count == 0): False
            (isFinite(value) && isFinite(mean)): True
            (if (isFinite(value) && isFinite(mean)) { <------------------------- THIS LOOKS LIKE THE WRONG PLACE
    double delta = value - mean;
    mean += delta / count;
    sumOfSquaresOfDeltas += delta * (value - mean);
} else {
    mean = calculateNewMeanNonFinite(mean, value);
    sumOfSquaresOfDeltas = NaN;
}): False
Test afterwards calls StatsAccumulator::snapshot,
    there it returns from: return new Stats(count, mean, sumOfSquaresOfDeltas, min, max);

Metadata

Metadata

Assignees

Labels

comp-summariesSomething related to the method names, code comments and display names generationctg-bugIssue is a bug

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions