From db4dec549f4064d1024b0d08e0dae9d535774f9f Mon Sep 17 00:00:00 2001 From: Geoffrey Challen Date: Fri, 30 Sep 2022 08:08:53 -0500 Subject: [PATCH] Fix map sorting bug. --- build.gradle.kts | 2 +- src/main/kotlin/Submission.kt | 32 ++++++----- src/main/kotlin/Testing.kt | 56 +++---------------- src/main/kotlin/generators/Parameters.kt | 2 +- ...edu.illinois.cs.cs125.jenisol.core.version | 2 +- 5 files changed, 31 insertions(+), 63 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7862657..8f40380 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ import java.util.Properties import org.jetbrains.kotlin.gradle.tasks.KotlinCompile group = "com.github.cs125-illinois" -version = "2022.9.3" +version = "2022.9.4" plugins { kotlin("jvm") version "1.7.20" diff --git a/src/main/kotlin/Submission.kt b/src/main/kotlin/Submission.kt index 842e80e..ad54c96 100644 --- a/src/main/kotlin/Submission.kt +++ b/src/main/kotlin/Submission.kt @@ -378,6 +378,7 @@ class Submission(val solution: Solution, val submission: Class<*>) { count { !it.tested }, skippedSteps = map { it.skippedTests }.flatten().sorted(), randomTrace = recordingRandom.finish() + // randomCallers = recordingRandom.callers ) inner class ExecutablePicker(private val random: Random, private val methods: Set) { @@ -395,6 +396,9 @@ class Submission(val solution: Solution, val submission: Class<*>) { val methodsLeft = methods - finished executableChooser = TreeMap( methodsLeft.associateWith { solution.defaultTestingWeight(it) } + .toSortedMap { e1, e2 -> + e1.fullName().compareTo(e2.fullName()) + } .map { (executable, weight) -> setTotal += weight setTotal to executable @@ -431,14 +435,25 @@ class Submission(val solution: Solution, val submission: Class<*>) { class RecordingRandom(seed: Long = Random.nextLong(), private val follow: List? = null) : Random() { private val random = Random(seed) private val trace = mutableListOf() - private var currentIndex = 0 + + // val callers = mutableListOf() + var currentIndex = 0 + var lastRandom = 0 + + @Suppress("ThrowingExceptionsWithoutMessageOrCause") override fun nextBits(bitCount: Int): Int { + /* + val e = Exception() + callers.add(e.stackTraceToString()) + */ return random.nextBits(bitCount).also { trace += it + lastRandom = it }.also { - if (follow != null && (follow.getOrNull(currentIndex++) != it)) { + if (follow != null && (follow.getOrNull(currentIndex) != it)) { throw FollowTraceException(currentIndex) } + currentIndex++ } } @@ -473,16 +488,6 @@ class Submission(val solution: Solution, val submission: Class<*>) { "Running all tests combined with test shrinking produces inconsistent results" } - /* - if (!solution.skipReceiver) { - if (solution.fauxStatic) { - check(settings.receiverCount == 1) { "Incorrect receiver count" } - } else { - check(settings.receiverCount > 1) { "Incorrect receiver count: ${settings.receiverCount}" } - } - } - */ - val random = if (settings.seed == -1) { RecordingRandom(follow = followTrace) } else { @@ -535,7 +540,8 @@ class Submission(val solution: Solution, val submission: Class<*>) { ExecutablePicker(random, solution.methodsToTest), settings, runners, - receivers + receivers, + random ).also { runner -> if (receivers == null && !solution.skipReceiver) { runner.next(stepCount++) diff --git a/src/main/kotlin/Testing.kt b/src/main/kotlin/Testing.kt index 8558114..209b68a 100644 --- a/src/main/kotlin/Testing.kt +++ b/src/main/kotlin/Testing.kt @@ -106,7 +106,9 @@ data class TestResult( @JvmField val submissionIsKotlin: Boolean = submissionClass.isKotlin(), @JvmField val existingReceiverMismatch: Boolean = false, @JvmField val solutionMethodString: String, - @JvmField val submissionMethodString: String + @JvmField val submissionMethodString: String, + @JvmField val currentRandom: Int, + @JvmField val randomCount: Int ) { @Suppress("UNCHECKED_CAST") @JvmField @@ -272,6 +274,7 @@ class TestResults( designOnly: Boolean? = null, val skippedSteps: List, val randomTrace: List? = null + // val randomCallers: List? = null ) : List> by results { val succeeded = designOnly ?: finishedReceivers && all { it.succeeded } && completed val failed = !succeeded @@ -313,7 +316,8 @@ class TestRunner( val methodPicker: Submission.ExecutablePicker, val settings: Settings, val runners: List, - var receivers: Value? + var receivers: Value?, + val random: Submission.RecordingRandom ) { val testResults: MutableList> = mutableListOf() val skippedTests: MutableList = mutableListOf() @@ -557,50 +561,6 @@ class TestRunner( } ?: error("couldn't find a parameter generator that should exist: $solutionExecutable") } - /* - // Enable for debugging - check( - parameters.solution.filterNotNull().none { - it::class.java == submission.submission::class.java - } - ) - check( - parameters.submission.filterNotNull().none { - it::class.java == submission.solution.solution::class.java - } - ) - check( - parameters.submissionCopy.filterNotNull().none { - it::class.java == submission.solution.solution::class.java - } - ) - check( - parameters.solutionCopy.filterNotNull().none { - it::class.java == submission.submission::class.java - } - ) - check( - parameters.solution.zip(parameters.submission).filter { (solutionParameter, submissionParameter) -> - solutionParameter != null && - submissionParameter != null && - solutionParameter::class.java == submission.solution.solution::class.java && - submissionParameter::class.java == submission.submission::class.java - }.none { (solutionParameter, submissionParameter) -> - solutionParameter!!::class.java != submissionParameter!!::class.java - } - ) - check( - parameters.solutionCopy.zip(parameters.submissionCopy).filter { (solutionParameter, submissionParameter) -> - solutionParameter != null && - submissionParameter != null && - solutionParameter::class.java == submission.solution.solution::class.java && - submissionParameter::class.java == submission.submission::class.java - }.none { (solutionParameter, submissionParameter) -> - solutionParameter!!::class.java != submissionParameter!!::class.java - } - ) - */ - val stepType = type ?: if (!created) { when (solutionExecutable) { is Constructor<*> -> TestResult.Type.CONSTRUCTOR @@ -739,7 +699,9 @@ class TestRunner( stepReceivers.submission, existingReceiverMismatch = existingReceiverMismatch, solutionMethodString = solutionMethodString, - submissionMethodString = submissionMethodString + submissionMethodString = submissionMethodString, + currentRandom = random.lastRandom, + randomCount = random.currentIndex ) val unmodifiedCopy = submissionExecutable.pairRun( diff --git a/src/main/kotlin/generators/Parameters.kt b/src/main/kotlin/generators/Parameters.kt index a0faff5..6bd1d01 100644 --- a/src/main/kotlin/generators/Parameters.kt +++ b/src/main/kotlin/generators/Parameters.kt @@ -26,7 +26,6 @@ import edu.illinois.cs.cs125.jenisol.core.isSimpleType import edu.illinois.cs.cs125.jenisol.core.isStatic import edu.illinois.cs.cs125.jenisol.core.randomParametersMatchAll import edu.illinois.cs.cs125.jenisol.core.unwrap -import java.lang.ClassCastException import java.lang.reflect.Constructor import java.lang.reflect.Executable import java.lang.reflect.Field @@ -566,6 +565,7 @@ class ConfiguredParametersGenerator( private val overrideRandom: Method?, private val notNullParameters: List ) : ExecutableGenerator { + private val generator = if (overrideFixed != null && overrideRandom != null) { null } else { diff --git a/src/main/resources/edu.illinois.cs.cs125.jenisol.core.version b/src/main/resources/edu.illinois.cs.cs125.jenisol.core.version index 81b72c6..de9c1bc 100644 --- a/src/main/resources/edu.illinois.cs.cs125.jenisol.core.version +++ b/src/main/resources/edu.illinois.cs.cs125.jenisol.core.version @@ -1 +1 @@ -version=2022.9.3 \ No newline at end of file +version=2022.9.4 \ No newline at end of file