Skip to content

Commit

Permalink
Clean up tests and get things passing
Browse files Browse the repository at this point in the history
  • Loading branch information
rchowell committed Nov 15, 2023
1 parent 213b235 commit 5f9bcd1
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 79 deletions.
1 change: 1 addition & 0 deletions examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ application {

dependencies {
implementation(project(":partiql-lang"))
implementation(project(":partiql-eval"))
implementation(project(":partiql-types"))
implementation(Deps.awsSdkS3)
}
Expand Down
6 changes: 5 additions & 1 deletion partiql-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ plugins {
}

dependencies {
// EvaluatingCompiler / ExprValue
implementation(project(":partiql-lang"))
//
implementation(project(":partiql-ast"))
implementation(project(":partiql-eval"))
implementation(project(":partiql-parser"))
implementation(project(":partiql-plan"))
implementation(project(":partiql-planner"))
implementation(project(":partiql-types"))
implementation(project(":plugins:partiql-local"))
implementation(project(":partiql-spi"))
implementation(project(":plugins:partiql-local"))
implementation(Deps.csv)
implementation(Deps.awsSdkBom)
implementation(Deps.awsSdkDynamodb)
Expand All @@ -36,6 +39,7 @@ dependencies {
implementation(Deps.joda)
implementation(Deps.picoCli)
implementation(Deps.kotlinReflect)

testImplementation(Deps.mockito)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.partiql.lang.eval

import junitparams.Parameters
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.partiql.errors.ErrorCode
import org.partiql.errors.Property
import org.partiql.lang.util.propertyValueMapOf
Expand All @@ -14,25 +15,10 @@ import java.math.BigInteger
*/
class EvaluatingCompilerIntTest : EvaluatorTestBase() {

private val closeToMaxLong = (Long.MAX_VALUE - 1)
private val closeToMinLong = (Long.MIN_VALUE + 1)

private val bigInt = BigInteger.valueOf(Long.MAX_VALUE).times(BigInteger.valueOf(2))
private val negativeBigInt = BigInteger.valueOf(Long.MIN_VALUE).times(BigInteger.valueOf(2))

@Test
@Parameters
@ParameterizedTest
@MethodSource("parametersForValues")
fun values(pair: Pair<String, String>) = assertPair(pair)

fun parametersForValues(): List<Pair<String, String>> {
val parameters = mutableListOf<Pair<String, String>>()
parameters.add("$closeToMaxLong" to "$closeToMaxLong")
parameters.add("$closeToMinLong" to "$closeToMinLong")
parameters.add("`0x00ffFFffFFffFFff`" to "72057594037927935")

return parameters
}

@Test
fun bigInt() = runEvaluatorErrorTestCase(
"$bigInt",
Expand All @@ -47,15 +33,10 @@ class EvaluatingCompilerIntTest : EvaluatorTestBase() {
expectedErrorContext = propertyValueMapOf(1, 2)
)

@Test
@Parameters
fun plus(pair: Pair<String, String>) = assertPair(pair)

fun parametersForPlus(): List<Pair<String, String>> {
val parameters = mutableListOf<Pair<String, String>>()
// Deliberately kept in case we need to manually add test case in the future.
return parameters
}
// EMPTY
// @ParameterizedTest
// @MethodSource("parametersForPlus")
// fun plus(pair: Pair<String, String>) = assertPair(pair)

@Test
fun plusOverflow() = runEvaluatorErrorTestCase(
Expand All @@ -65,15 +46,10 @@ class EvaluatingCompilerIntTest : EvaluatorTestBase() {
expectedPermissiveModeResult = "MISSING"
)

@Test
@Parameters
fun minus(pair: Pair<String, String>) = assertPair(pair)

fun parametersForMinus(): List<Pair<String, String>> {
val parameters = mutableListOf<Pair<String, String>>()
// Deliberately kept in case we need to manually add test case in the future.
return parameters
}
// EMPTY
// @ParameterizedTest
// @MethodSource("parametersForMinus")
// fun minus(pair: Pair<String, String>) = assertPair(pair)

@Test
fun minusUnderflow() = runEvaluatorErrorTestCase(
Expand All @@ -83,18 +59,10 @@ class EvaluatingCompilerIntTest : EvaluatorTestBase() {
expectedPermissiveModeResult = "MISSING"
)

@Test
@Parameters
@ParameterizedTest
@MethodSource("parametersForTimes")
fun times(pair: Pair<String, String>) = assertPair(pair)

fun parametersForTimes(): List<Pair<String, String>> {
val parameters = mutableListOf<Pair<String, String>>()

parameters.add("${Long.MAX_VALUE} * -1" to "-${Long.MAX_VALUE}")

return parameters
}

@Test
fun timesOverflow() = runEvaluatorErrorTestCase(
"$closeToMaxLong * 2",
Expand All @@ -111,18 +79,10 @@ class EvaluatingCompilerIntTest : EvaluatorTestBase() {
expectedPermissiveModeResult = "MISSING"
)

@Test
@Parameters
@ParameterizedTest
@MethodSource("parametersForDivision")
fun division(pair: Pair<String, String>) = assertPair(pair)

fun parametersForDivision(): List<Pair<String, String>> {
val parameters = mutableListOf<Pair<String, String>>()

parameters.add("${Long.MAX_VALUE} / -1" to "-${Long.MAX_VALUE}")

return parameters
}

@Test
fun divisionUnderflow() = runEvaluatorErrorTestCase(
"${Long.MIN_VALUE} / -1",
Expand All @@ -131,27 +91,10 @@ class EvaluatingCompilerIntTest : EvaluatorTestBase() {
expectedPermissiveModeResult = "MISSING"
)

@Test
@Parameters
@ParameterizedTest
@MethodSource("parametersForBitwiseAnd")
fun bitwiseAnd(pair: Pair<String, String>) = assertPair(pair)

fun parametersForBitwiseAnd(): List<Pair<String, String>> {
val parameters = mutableListOf<Pair<String, String>>()

parameters.add("1 & 2" to "0")
parameters.add("3 & 5" to "1")
parameters.add("5 & 7" to "5")
parameters.add("31 & 15 & 7 & 3 & 1" to "1")
parameters.add("1 + 5 & 5" to "4")
parameters.add("(1 + 5) & 5" to "4")
parameters.add("1 + (5 & 5)" to "6")
parameters.add("5 & 5 + 1" to "4")
parameters.add("(5 & 5) + 1" to "6")
parameters.add("5 & (5 + 1)" to "4")

return parameters
}

@Test
fun castBigInt() = runEvaluatorErrorTestCase(
"cast('$bigInt' as int)",
Expand Down Expand Up @@ -202,4 +145,52 @@ class EvaluatingCompilerIntTest : EvaluatorTestBase() {
val (query, expected) = pair
runEvaluatorTestCase(query, expectedResult = expected)
}

companion object {

private val closeToMaxLong = (Long.MAX_VALUE - 1)
private val closeToMinLong = (Long.MIN_VALUE + 1)

private val bigInt = BigInteger.valueOf(Long.MAX_VALUE).times(BigInteger.valueOf(2))
private val negativeBigInt = BigInteger.valueOf(Long.MIN_VALUE).times(BigInteger.valueOf(2))

@JvmStatic
fun parametersForValues(): List<Pair<String, String>> = listOf(
"$closeToMaxLong" to "$closeToMaxLong",
"$closeToMinLong" to "$closeToMinLong",
"`0x00ffFFffFFffFFff`" to "72057594037927935",
)

// Deliberately kept in case we need to manually add test case in the future.
@JvmStatic
fun parametersForPlus(): List<Pair<String, String>> = emptyList()

@JvmStatic
fun parametersForTimes(): List<Pair<String, String>> = listOf(
"${Long.MAX_VALUE} * -1" to "-${Long.MAX_VALUE}"
)

@JvmStatic
fun parametersForDivision(): List<Pair<String, String>> = listOf(
"${Long.MAX_VALUE} / -1" to "-${Long.MAX_VALUE}",
)

// Deliberately kept in case we need to manually add test case in the future.
@JvmStatic
fun parametersForMinus(): List<Pair<String, String>> = emptyList()

@JvmStatic
fun parametersForBitwiseAnd(): List<Pair<String, String>> = listOf(
"1 & 2" to "0",
"3 & 5" to "1",
"5 & 7" to "5",
"31 & 15 & 7 & 3 & 1" to "1",
"1 + 5 & 5" to "4",
"(1 + 5) & 5" to "4",
"1 + (5 & 5)" to "6",
"5 & 5 + 1" to "4",
"(5 & 5) + 1" to "6",
"5 & (5 + 1)" to "4",
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.amazon.ion.IonValue
import com.amazon.ionelement.api.toIonElement
import junitparams.JUnitParamsRunner
import junitparams.Parameters
import org.junit.jupiter.api.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.partiql.lang.CompilerPipeline
import org.partiql.lang.ION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.partiql.lang.eval

import junitparams.Parameters
import org.junit.jupiter.api.Test
import org.junit.Test
import org.partiql.lang.eval.evaluatortestframework.EvaluatorTestCase
import org.partiql.lang.util.downcast

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.partiql.lang.eval.EvaluationException
import org.partiql.lang.eval.EvaluatorTestBase
import org.partiql.lang.eval.FunctionNotFoundException
import org.partiql.lang.eval.internal.builtins.SCALAR_BUILTINS_DEFAULT
import org.partiql.types.StaticType

Expand Down
3 changes: 3 additions & 0 deletions partiql-eval/src/test/resources/junit-platform.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent
5 changes: 5 additions & 0 deletions test/partiql-randomized-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ plugins {
}

dependencies {
// partiql-lang + tests
testImplementation project(':partiql-lang')
testImplementation project(':partiql-lang').sourceSets.test.output
testImplementation testFixtures(project(':partiql-lang'))
// partiql-eval + tests
testImplementation project(':partiql-eval')
testImplementation project(':partiql-eval').sourceSets.test.output
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5'
testImplementation 'pl.pragmatists:JUnitParams:[1.0.0,1.1.0)'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.7.0'
Expand Down

0 comments on commit 5f9bcd1

Please sign in to comment.