Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingFormatWidthException when using Statistics #72

Closed
gtrefs opened this issue Oct 30, 2019 · 3 comments
Closed

MissingFormatWidthException when using Statistics #72

gtrefs opened this issue Oct 30, 2019 · 3 comments
Labels

Comments

@gtrefs
Copy link
Contributor

gtrefs commented Oct 30, 2019

Testing Problem

The following code leads to a MissingFormatWidthException:

package de.gtrefs.pbt.chapter3

import de.gtrefs.pbt.chapter3.LibraryTest.Direction.*
import net.jqwik.api.Arbitraries.of
import net.jqwik.api.Arbitraries.oneOf
import net.jqwik.api.ForAll
import net.jqwik.api.Property
import net.jqwik.api.Provide
import net.jqwik.api.Statistics

class LibraryTest {
    @Property fun testSomeLibraryMethod(@ForAll("path") path: List<Direction>) {
        Statistics.label(path.size.toString()).collect(path)
    }

    @Provide
    fun path() = oneOf(of(LEFT, RIGHT, UP, DOWN)).list()

    enum class Direction {
        LEFT, RIGHT, UP, DOWN
    }

}

Stacktrace


java.util.MissingFormatWidthException: %02$d

	at java.base/java.util.Formatter$FormatSpecifier.checkNumeric(Formatter.java:3176)
	at java.base/java.util.Formatter$FormatSpecifier.checkInteger(Formatter.java:3136)
	at java.base/java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2874)
	at java.base/java.util.Formatter.parse(Formatter.java:2713)
	at java.base/java.util.Formatter.format(Formatter.java:2655)
	at java.base/java.util.Formatter.format(Formatter.java:2609)
	at java.base/java.lang.String.format(String.java:2897)
	at net.jqwik.engine.properties.StatisticsCollectorImpl.formatEntry(StatisticsCollectorImpl.java:88)
	at net.jqwik.engine.properties.StatisticsCollectorImpl.createReportEntry(StatisticsCollectorImpl.java:80)
	at net.jqwik.engine.properties.StatisticsCollectorImpl.report(StatisticsCollectorImpl.java:33)
	at net.jqwik.engine.properties.GenericProperty.reportStatistics(GenericProperty.java:45)
	at net.jqwik.engine.properties.GenericProperty.check(GenericProperty.java:40)
	at net.jqwik.engine.execution.CheckedProperty.check(CheckedProperty.java:39)
	at net.jqwik.engine.execution.PropertyMethodExecutor.executeProperty(PropertyMethodExecutor.java:134)
	at net.jqwik.engine.execution.PropertyMethodExecutor.executeMethod(PropertyMethodExecutor.java:122)
	at net.jqwik.engine.execution.PropertyMethodExecutor.lambda$executePropertyMethod$1(PropertyMethodExecutor.java:102)
	at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$static$0(AroundPropertyHook.java:17)
	at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$null$1(AroundPropertyHook.java:32)
	at net.jqwik.engine.execution.lifecycle.AutoCloseableHook.aroundProperty(AutoCloseableHook.java:15)
	at net.jqwik.api.lifecycle.AroundPropertyHook.lambda$around$2(AroundPropertyHook.java:37)
	at net.jqwik.engine.execution.PropertyMethodExecutor.executePropertyMethod(PropertyMethodExecutor.java:100)
	at net.jqwik.engine.execution.PropertyMethodExecutor.execute(PropertyMethodExecutor.java:46)
	at net.jqwik.engine.execution.PropertyTaskCreator.executeTestMethod(PropertyTaskCreator.java:79)
	at net.jqwik.engine.execution.PropertyTaskCreator.lambda$createTask$0(PropertyTaskCreator.java:38)
	at net.jqwik.engine.execution.pipeline.ExecutionTask$1.execute(ExecutionTask.java:24)
	at net.jqwik.engine.execution.pipeline.ExecutionPipeline.runToTermination(ExecutionPipeline.java:81)
	at net.jqwik.engine.execution.JqwikExecutor.execute(JqwikExecutor.java:46)
	at net.jqwik.engine.JqwikTestEngine.executeTests(JqwikTestEngine.java:68)
	at net.jqwik.engine.JqwikTestEngine.execute(JqwikTestEngine.java:57)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


Suggested Solution

I did not do a proper investigation but my guess is, that the computation of decimal in method createReportEntry in class StatisticsControllerImpl results in a 0, when the counts map has less than 10 entries.

@jlink jlink added the bug label Oct 31, 2019
@jlink
Copy link
Collaborator

jlink commented Oct 31, 2019

It's a bug that I'll fix.

Two remarks anyway.

  1. Your provider method can be simplified to (Java code):

     @Provide
     Arbitrary<List<Direction>> path(){
     	return of(Direction.class).list();
     }
    
    
  2. The way you do it you collect statistics on the actual path contents per path size. If you just want statistics on the path size, something like that will suffice:

    Statistics.label("path size").collect(path.size());

    And then the bug will not show up either :-)

@jlink
Copy link
Collaborator

jlink commented Oct 31, 2019

Fix available in 1.2.2-SNAPSHOT

@jlink jlink closed this as completed Oct 31, 2019
@gtrefs
Copy link
Contributor Author

gtrefs commented Nov 1, 2019

Thanks for the remarks, I will improve the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants