// ArduinoJson - https://arduinojson.org // Copyright © 2014-2023, Benoit BLANCHON // MIT License #include #include using namespace ArduinoJson::detail; TEST_CASE("arithmeticCompare()") { SECTION("int vs uint8_t") { CHECK(arithmeticCompare(256, 1) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(41, 42) == COMPARE_RESULT_LESS); CHECK(arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(43, 42) == COMPARE_RESULT_GREATER); } SECTION("unsigned vs int") { CHECK(arithmeticCompare(0, -1) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(42, 43) == COMPARE_RESULT_LESS); } SECTION("float vs int") { CHECK(arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(42, 43) == COMPARE_RESULT_LESS); } SECTION("int vs unsigned") { CHECK(arithmeticCompare(-1, 0) == COMPARE_RESULT_LESS); CHECK(arithmeticCompare(0, 0) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(1, 0) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(42, 43) == COMPARE_RESULT_LESS); } SECTION("unsigned vs unsigned") { CHECK(arithmeticCompare(42, 41) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(42, 42) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(42, 43) == COMPARE_RESULT_LESS); } SECTION("bool vs bool") { CHECK(arithmeticCompare(false, false) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(true, true) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(false, true) == COMPARE_RESULT_LESS); CHECK(arithmeticCompare(true, false) == COMPARE_RESULT_GREATER); } SECTION("bool vs int") { CHECK(arithmeticCompare(false, -1) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(false, 0) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(false, 1) == COMPARE_RESULT_LESS); CHECK(arithmeticCompare(true, 0) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(true, 1) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(true, 2) == COMPARE_RESULT_LESS); } SECTION("bool vs int") { CHECK(arithmeticCompare(0, false) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(1, true) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompare(1, false) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompare(0, true) == COMPARE_RESULT_LESS); } } TEST_CASE("arithmeticCompareNegateLeft()") { SECTION("unsigned vs int") { CHECK(arithmeticCompareNegateLeft(0, 1) == COMPARE_RESULT_LESS); CHECK(arithmeticCompareNegateLeft(42, -41) == COMPARE_RESULT_LESS); CHECK(arithmeticCompareNegateLeft(42, -42) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompareNegateLeft(42, -43) == COMPARE_RESULT_GREATER); } SECTION("unsigned vs unsigned") { CHECK(arithmeticCompareNegateLeft(42, 42) == COMPARE_RESULT_LESS); } } TEST_CASE("arithmeticCompareNegateRight()") { SECTION("int vs unsigned") { CHECK(arithmeticCompareNegateRight(1, 0) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompareNegateRight(-41, 42) == COMPARE_RESULT_GREATER); CHECK(arithmeticCompareNegateRight(-42, 42) == COMPARE_RESULT_EQUAL); CHECK(arithmeticCompareNegateRight(-43, 42) == COMPARE_RESULT_LESS); } SECTION("unsigned vs unsigned") { CHECK(arithmeticCompareNegateRight(42, 42) == COMPARE_RESULT_GREATER); } }