Fix count tests; use types for varying comparison values
This commit is contained in:
@@ -2,94 +2,165 @@ package solutions.bitbadger.documents
|
||||
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Unit tests for the `Comparison` class
|
||||
* Unit tests for the `ComparisonBetween` class
|
||||
*/
|
||||
@DisplayName("Comparison")
|
||||
class ComparisonTest {
|
||||
@DisplayName("ComparisonBetween")
|
||||
class ComparisonBetweenTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("op is set to BETWEEN")
|
||||
fun op() =
|
||||
assertEquals(Op.BETWEEN, ComparisonBetween(Pair(0, 0)).op, "Between comparison should have BETWEEN op")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is false with strings")
|
||||
fun isNumericFalseForStringsAndBetween() =
|
||||
assertFalse(ComparisonBetween(Pair("eh", "zed")).isNumeric,
|
||||
"A BETWEEN with strings should not be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true with bytes")
|
||||
fun isNumericTrueForByteAndBetween() =
|
||||
assertTrue(ComparisonBetween(Pair<Byte, Byte>(7, 11)).isNumeric, "A BETWEEN with bytes should be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true with shorts")
|
||||
fun isNumericTrueForShortAndBetween() =
|
||||
assertTrue(ComparisonBetween(Pair<Short, Short>(0, 9)).isNumeric,
|
||||
"A BETWEEN with shorts should be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true with ints")
|
||||
fun isNumericTrueForIntAndBetween() =
|
||||
assertTrue(ComparisonBetween(Pair(15, 44)).isNumeric, "A BETWEEN with ints should be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true with longs")
|
||||
fun isNumericTrueForLongAndBetween() =
|
||||
assertTrue(ComparisonBetween(Pair(9L, 12L)).isNumeric, "A BETWEEN with longs should be numeric")
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit tests for the `ComparisonIn` class
|
||||
*/
|
||||
@DisplayName("ComparisonIn")
|
||||
class ComparisonInTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("op is set to IN")
|
||||
fun op() =
|
||||
assertEquals(Op.IN, ComparisonIn(listOf<String>()).op, "In comparison should have IN op")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is false for empty list of values")
|
||||
fun isNumericFalseForEmptyList() =
|
||||
assertFalse(InComparison(Op.IN, listOf<Int>()).isNumeric, "An IN with empty list should not be numeric")
|
||||
assertFalse(ComparisonIn(listOf<Int>()).isNumeric, "An IN with empty list should not be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is false for IN with strings")
|
||||
@DisplayName("isNumeric is false with strings")
|
||||
fun isNumericFalseForStringsAndIn() =
|
||||
assertFalse(InComparison(Op.IN, listOf("a", "b", "c")).isNumeric, "An IN with strings should not be numeric")
|
||||
assertFalse(ComparisonIn(listOf("a", "b", "c")).isNumeric, "An IN with strings should not be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for IN with bytes")
|
||||
@DisplayName("isNumeric is true with bytes")
|
||||
fun isNumericTrueForByteAndIn() =
|
||||
assertTrue(InComparison(Op.IN, listOf<Byte>(4, 8)).isNumeric, "An IN with bytes should be numeric")
|
||||
assertTrue(ComparisonIn(listOf<Byte>(4, 8)).isNumeric, "An IN with bytes should be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for IN with shorts")
|
||||
@DisplayName("isNumeric is true with shorts")
|
||||
fun isNumericTrueForShortAndIn() =
|
||||
assertTrue(InComparison(Op.IN, listOf<Short>(18, 22)).isNumeric, "An IN with shorts should be numeric")
|
||||
assertTrue(ComparisonIn(listOf<Short>(18, 22)).isNumeric, "An IN with shorts should be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for IN with ints")
|
||||
@DisplayName("isNumeric is true with ints")
|
||||
fun isNumericTrueForIntAndIn() =
|
||||
assertTrue(InComparison(Op.IN, listOf(7, 8, 9)).isNumeric, "An IN with ints should be numeric")
|
||||
assertTrue(ComparisonIn(listOf(7, 8, 9)).isNumeric, "An IN with ints should be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for IN with longs")
|
||||
@DisplayName("isNumeric is true with longs")
|
||||
fun isNumericTrueForLongAndIn() =
|
||||
assertTrue(InComparison(Op.IN, listOf(3L)).isNumeric, "An IN with longs should be numeric")
|
||||
assertTrue(ComparisonIn(listOf(3L)).isNumeric, "An IN with longs should be numeric")
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit tests for the `ComparisonInArray` class
|
||||
*/
|
||||
@DisplayName("ComparisonInArray")
|
||||
class ComparisonInArrayTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is false for BETWEEN with strings")
|
||||
fun isNumericFalseForStringsAndBetween() =
|
||||
assertFalse(BetweenComparison(Op.BETWEEN, Pair("eh", "zed")).isNumeric,
|
||||
"A BETWEEN with strings should not be numeric")
|
||||
@DisplayName("op is set to IN_ARRAY")
|
||||
fun op() =
|
||||
assertEquals(
|
||||
Op.IN_ARRAY,
|
||||
ComparisonInArray(Pair(TEST_TABLE, listOf<String>())).op,
|
||||
"InArray comparison should have IN_ARRAY op"
|
||||
)
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for BETWEEN with bytes")
|
||||
fun isNumericTrueForByteAndBetween() =
|
||||
assertTrue(BetweenComparison(Op.BETWEEN, Pair<Byte, Byte>(7, 11)).isNumeric, "A BETWEEN with bytes should be numeric")
|
||||
@DisplayName("isNumeric is false for empty list of values")
|
||||
fun isNumericFalseForEmptyList() =
|
||||
assertFalse(ComparisonIn(listOf<Int>()).isNumeric, "An IN_ARRAY with empty list should not be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for BETWEEN with shorts")
|
||||
fun isNumericTrueForShortAndBetween() =
|
||||
assertTrue(BetweenComparison(Op.BETWEEN, Pair<Short, Short>(0, 9)).isNumeric,
|
||||
"A BETWEEN with shorts should be numeric")
|
||||
@DisplayName("isNumeric is false with strings")
|
||||
fun isNumericFalseForStringsAndIn() =
|
||||
assertFalse(ComparisonIn(listOf("a", "b", "c")).isNumeric, "An IN_ARRAY with strings should not be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for BETWEEN with ints")
|
||||
fun isNumericTrueForIntAndBetween() =
|
||||
assertTrue(BetweenComparison(Op.BETWEEN, Pair(15, 44)).isNumeric, "A BETWEEN with ints should be numeric")
|
||||
@DisplayName("isNumeric is false with bytes")
|
||||
fun isNumericTrueForByteAndIn() =
|
||||
assertTrue(ComparisonIn(listOf<Byte>(4, 8)).isNumeric, "An IN_ARRAY with bytes should not be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for BETWEEN with longs")
|
||||
fun isNumericTrueForLongAndBetween() =
|
||||
assertTrue(BetweenComparison(Op.BETWEEN, Pair(9L, 12L)).isNumeric, "A BETWEEN with longs should be numeric")
|
||||
@DisplayName("isNumeric is false with shorts")
|
||||
fun isNumericTrueForShortAndIn() =
|
||||
assertTrue(ComparisonIn(listOf<Short>(18, 22)).isNumeric, "An IN_ARRAY with shorts should not be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is false with ints")
|
||||
fun isNumericTrueForIntAndIn() =
|
||||
assertTrue(ComparisonIn(listOf(7, 8, 9)).isNumeric, "An IN_ARRAY with ints should not be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is false with longs")
|
||||
fun isNumericTrueForLongAndIn() =
|
||||
assertTrue(ComparisonIn(listOf(3L)).isNumeric, "An IN_ARRAY with longs should not be numeric")
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit tests for the `ComparisonSingle` class
|
||||
*/
|
||||
@DisplayName("ComparisonSingle")
|
||||
class ComparisonSingleTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is false for string value")
|
||||
fun isNumericFalseForString() =
|
||||
assertFalse(SingleComparison(Op.EQUAL, "80").isNumeric, "A string should not be numeric")
|
||||
assertFalse(ComparisonSingle(Op.EQUAL, "80").isNumeric, "A string should not be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for byte value")
|
||||
fun isNumericTrueForByte() =
|
||||
assertTrue(SingleComparison(Op.EQUAL, 47.toByte()).isNumeric, "A byte should be numeric")
|
||||
assertTrue(ComparisonSingle(Op.EQUAL, 47.toByte()).isNumeric, "A byte should be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for short value")
|
||||
fun isNumericTrueForShort() =
|
||||
assertTrue(SingleComparison(Op.EQUAL, 2.toShort()).isNumeric, "A short should be numeric")
|
||||
assertTrue(ComparisonSingle(Op.EQUAL, 2.toShort()).isNumeric, "A short should be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for int value")
|
||||
fun isNumericTrueForInt() =
|
||||
assertTrue(SingleComparison(Op.EQUAL, 555).isNumeric, "An int should be numeric")
|
||||
assertTrue(ComparisonSingle(Op.EQUAL, 555).isNumeric, "An int should be numeric")
|
||||
|
||||
@Test
|
||||
@DisplayName("isNumeric is true for long value")
|
||||
fun isNumericTrueForLong() =
|
||||
assertTrue(SingleComparison(Op.EQUAL, 82L).isNumeric, "A long should be numeric")
|
||||
assertTrue(ComparisonSingle(Op.EQUAL, 82L).isNumeric, "A long should be numeric")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user