package solutions.bitbadger.documents import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import solutions.bitbadger.documents.integration.TEST_TABLE import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue /** * Unit tests for the `ComparisonBetween` class */ @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(7, 11)).isNumeric, "A BETWEEN with bytes should be numeric") @Test @DisplayName("isNumeric is true with shorts") fun isNumericTrueForShortAndBetween() = assertTrue(ComparisonBetween(Pair(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()).op, "In comparison should have IN op") @Test @DisplayName("isNumeric is false for empty list of values") fun isNumericFalseForEmptyList() = assertFalse(ComparisonIn(listOf()).isNumeric, "An IN with empty list should not be numeric") @Test @DisplayName("isNumeric is false with strings") fun isNumericFalseForStringsAndIn() = assertFalse(ComparisonIn(listOf("a", "b", "c")).isNumeric, "An IN with strings should not be numeric") @Test @DisplayName("isNumeric is true with bytes") fun isNumericTrueForByteAndIn() = assertTrue(ComparisonIn(listOf(4, 8)).isNumeric, "An IN with bytes should be numeric") @Test @DisplayName("isNumeric is true with shorts") fun isNumericTrueForShortAndIn() = assertTrue(ComparisonIn(listOf(18, 22)).isNumeric, "An IN with shorts should be numeric") @Test @DisplayName("isNumeric is true with ints") fun isNumericTrueForIntAndIn() = assertTrue(ComparisonIn(listOf(7, 8, 9)).isNumeric, "An IN with ints should be numeric") @Test @DisplayName("isNumeric is true with longs") fun isNumericTrueForLongAndIn() = assertTrue(ComparisonIn(listOf(3L)).isNumeric, "An IN with longs should be numeric") } /** * Unit tests for the `ComparisonInArray` class */ @DisplayName("ComparisonInArray") class ComparisonInArrayTest { @Test @DisplayName("op is set to IN_ARRAY") fun op() = assertEquals( Op.IN_ARRAY, ComparisonInArray(Pair(TEST_TABLE, listOf())).op, "InArray comparison should have IN_ARRAY op" ) @Test @DisplayName("isNumeric is false for empty list of values") fun isNumericFalseForEmptyList() = assertFalse(ComparisonIn(listOf()).isNumeric, "An IN_ARRAY with empty list should not be numeric") @Test @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 false with bytes") fun isNumericTrueForByteAndIn() = assertTrue(ComparisonIn(listOf(4, 8)).isNumeric, "An IN_ARRAY with bytes should not be numeric") @Test @DisplayName("isNumeric is false with shorts") fun isNumericTrueForShortAndIn() = assertTrue(ComparisonIn(listOf(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(ComparisonSingle(Op.EQUAL, "80").isNumeric, "A string should not be numeric") @Test @DisplayName("isNumeric is true for byte value") fun isNumericTrueForByte() = assertTrue(ComparisonSingle(Op.EQUAL, 47.toByte()).isNumeric, "A byte should be numeric") @Test @DisplayName("isNumeric is true for short value") fun isNumericTrueForShort() = assertTrue(ComparisonSingle(Op.EQUAL, 2.toShort()).isNumeric, "A short should be numeric") @Test @DisplayName("isNumeric is true for int value") fun isNumericTrueForInt() = assertTrue(ComparisonSingle(Op.EQUAL, 555).isNumeric, "An int should be numeric") @Test @DisplayName("isNumeric is true for long value") fun isNumericTrueForLong() = assertTrue(ComparisonSingle(Op.EQUAL, 82L).isNumeric, "A long should be numeric") }