Skip to content

Commit

Permalink
Add output limits.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Sep 14, 2022
1 parent e4e120f commit 21e9a08
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 36 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import java.util.Properties
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "com.github.cs125-illinois"
version = "2022.9.0"
version = "2022.9.1"

plugins {
kotlin("jvm") version "1.7.10"
java
`maven-publish`

id("org.jmailen.kotlinter") version "3.11.1"
id("org.jmailen.kotlinter") version "3.12.0"
checkstyle
id("com.github.sherter.google-java-format") version "0.9"

Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/InputOutput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data class CapturedResult(
val stderr: String,
val stdin: String,
val interleavedInputOutput: String,
val truncatedLines: Int,
val tag: Any? = null
)

Expand Down Expand Up @@ -94,6 +95,7 @@ fun defaultCaptureOutputControlInput(stdin: List<String> = listOf(), run: () ->
divertedStdout.stream.toString(),
divertedStderr.stream.toString(),
stdinBytes.toByteArray().decodeToString(),
ioBytes.toByteArray().decodeToString()
ioBytes.toByteArray().decodeToString(),
0
)
}
76 changes: 44 additions & 32 deletions src/main/kotlin/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Solution(val solution: Class<*>) {
executable.returnType.getArrayDimension() == 1
)
)

else -> designError("Unexpected executable type")
}
}.toSet()
Expand Down Expand Up @@ -284,39 +285,44 @@ class Solution(val solution: Class<*>) {
} else if (settings.receiverCount != -1) {
val methodCount = settings.totalTestCount - (settings.receiverCount * Settings.DEFAULT_RECEIVER_RETRIES)
settings.copy(methodCount = methodCount)
} else if (settings.methodCount != -1) {
val receiverCount = (
(settings.totalTestCount - settings.methodCount).toDouble() /
Settings.DEFAULT_RECEIVER_RETRIES.toDouble()
).toInt()
settings.copy(receiverCount = receiverCount)
} else {
val receiverCount = if (skipReceiver) {
0
} else if (fauxStatic) {
1
if (settings.methodCount != -1) {
val receiverCount = (
(settings.totalTestCount - settings.methodCount).toDouble() /
Settings.DEFAULT_RECEIVER_RETRIES.toDouble()
).toInt()
settings.copy(receiverCount = receiverCount)
} else {
(
(defaultReceiverCount.toDouble() / defaultTotalCount.toDouble()) *
settings.totalTestCount
).toInt().coerceAtLeast(
if (testingEquals) {
defaultReceiverCount
} else {
2
}
)
}
val methodCount =
(settings.totalTestCount - (receiverCount * Settings.DEFAULT_RECEIVER_RETRIES)).coerceAtLeast(
settings.totalTestCount / 2
)
settings.copy(methodCount = methodCount, receiverCount = receiverCount)
}.let {
if (it.totalTestCount == -1) {
it.copy(totalTestCount = it.methodCount + (it.receiverCount * Settings.DEFAULT_RECEIVER_RETRIES))
} else {
it
val receiverCount = if (skipReceiver) {
0
} else if (fauxStatic) {
1
} else {
(
(defaultReceiverCount.toDouble() / defaultTotalCount.toDouble()) *
settings.totalTestCount
).toInt().coerceAtLeast(
if (testingEquals) {
defaultReceiverCount
} else {
2
}
)
}
val methodCount =
(settings.totalTestCount - (receiverCount * Settings.DEFAULT_RECEIVER_RETRIES)).coerceAtLeast(
settings.totalTestCount / 2
)
settings.copy(methodCount = methodCount, receiverCount = receiverCount)
}.let {
if (it.totalTestCount == -1) {
it.copy(
totalTestCount =
it.methodCount + (it.receiverCount * Settings.DEFAULT_RECEIVER_RETRIES)
)
} else {
it
}
}
}
}.also {
Expand Down Expand Up @@ -404,7 +410,8 @@ class Solution(val solution: Class<*>) {
"Couldn't find field ${field.name} on alternate solution"
}

val (firstValue, secondValue) = @Suppress("TooGenericExceptionCaught") try {
val (firstValue, secondValue) = @Suppress("TooGenericExceptionCaught")
try {
Pair(field.get(null), otherField.get(null))
} catch (e: Exception) {
error("Retrieving field ${field.name} failed: $e")
Expand Down Expand Up @@ -496,6 +503,7 @@ fun String.toKotlinType() = when {
}
name
}

else -> this
}

Expand Down Expand Up @@ -619,8 +627,10 @@ fun compareReturn(
submissionReturn.isArray &&
submissionReturn.getArrayType() == submission &&
solutionReturn.getArrayDimension() == submissionReturn.getArrayDimension() -> true

solutionReturn is TypeVariable<*> && submissionReturn is TypeVariable<*> ->
solutionReturn.bounds.contentEquals(submissionReturn.bounds)

else -> false
}

Expand All @@ -643,6 +653,7 @@ fun compareParameters(
submissionType.rawType == solutionType -> {
submissionType.actualTypeArguments.all { it is Any }
}

submission.isKotlin() && solutionType is ParameterizedType && submissionType is ParameterizedType &&
solutionType.rawType == submissionType.rawType -> {
var matches = true
Expand All @@ -666,6 +677,7 @@ fun compareParameters(
}
matches
}

else -> false
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/Testing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class Result<T, P : ParameterGroup>(
@JvmField val stderr: String,
@JvmField val stdin: String,
@JvmField val interleavedOutput: String,
@JvmField val truncatedLines: Int,
@JvmField val tag: Any?,
@JvmField val modifiedParameters: Boolean
) {
Expand All @@ -43,6 +44,7 @@ data class Result<T, P : ParameterGroup>(
capturedResult.stderr,
capturedResult.stdin,
capturedResult.interleavedInputOutput,
capturedResult.truncatedLines,
capturedResult.tag,
modifiedParameters
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2022.9.0
version=2022.9.1

0 comments on commit 21e9a08

Please sign in to comment.