Skip to content

Commit

Permalink
Fix map sorting bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Sep 30, 2022
1 parent b020ed3 commit db4dec5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 19 additions & 13 deletions src/main/kotlin/Submission.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Executable>) {
Expand All @@ -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
Expand Down Expand Up @@ -431,14 +435,25 @@ class Submission(val solution: Solution, val submission: Class<*>) {
class RecordingRandom(seed: Long = Random.nextLong(), private val follow: List<Int>? = null) : Random() {
private val random = Random(seed)
private val trace = mutableListOf<Int>()
private var currentIndex = 0

// val callers = mutableListOf<String>()
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++
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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++)
Expand Down
56 changes: 9 additions & 47 deletions src/main/kotlin/Testing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ data class TestResult<T, P : ParameterGroup>(
@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
Expand Down Expand Up @@ -272,6 +274,7 @@ class TestResults(
designOnly: Boolean? = null,
val skippedSteps: List<Int>,
val randomTrace: List<Int>? = null
// val randomCallers: List<String>? = null
) : List<TestResult<Any, ParameterGroup>> by results {
val succeeded = designOnly ?: finishedReceivers && all { it.succeeded } && completed
val failed = !succeeded
Expand Down Expand Up @@ -313,7 +316,8 @@ class TestRunner(
val methodPicker: Submission.ExecutablePicker,
val settings: Settings,
val runners: List<TestRunner>,
var receivers: Value<Any?>?
var receivers: Value<Any?>?,
val random: Submission.RecordingRandom
) {
val testResults: MutableList<TestResult<*, *>> = mutableListOf()
val skippedTests: MutableList<Int> = mutableListOf()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/generators/Parameters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -566,6 +565,7 @@ class ConfiguredParametersGenerator(
private val overrideRandom: Method?,
private val notNullParameters: List<Boolean>
) : ExecutableGenerator {

private val generator = if (overrideFixed != null && overrideRandom != null) {
null
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2022.9.3
version=2022.9.4

0 comments on commit db4dec5

Please sign in to comment.