| 28 | namespace internal { |
| 29 | |
| 30 | TEST(TestDispatchBest, CastBinaryDecimalArgs) { |
| 31 | std::vector<TypeHolder> args; |
| 32 | std::vector<DecimalPromotion> modes = { |
| 33 | DecimalPromotion::kAdd, DecimalPromotion::kMultiply, DecimalPromotion::kDivide}; |
| 34 | |
| 35 | // Any float -> all float |
| 36 | for (auto mode : modes) { |
| 37 | args = {decimal128(3, 2), float32(), float64()}; |
| 38 | ASSERT_OK(CastBinaryDecimalArgs(mode, &args)); |
| 39 | AssertTypeEqual(*args[0], *float64()); |
| 40 | AssertTypeEqual(*args[1], *float64()); |
| 41 | } |
| 42 | |
| 43 | // Integer -> decimal with common scale |
| 44 | args = {decimal128(1, 0), int64()}; |
| 45 | ASSERT_OK(CastBinaryDecimalArgs(DecimalPromotion::kAdd, &args)); |
| 46 | AssertTypeEqual(*args[0], *decimal128(1, 0)); |
| 47 | AssertTypeEqual(*args[1], *decimal128(19, 0)); |
| 48 | |
| 49 | // Add: rescale so all have common scale |
| 50 | args = {decimal128(3, 2), decimal128(3, -2)}; |
| 51 | EXPECT_RAISES_WITH_MESSAGE_THAT( |
| 52 | NotImplemented, ::testing::HasSubstr("Decimals with negative scales not supported"), |
| 53 | CastBinaryDecimalArgs(DecimalPromotion::kAdd, &args)); |
| 54 | |
| 55 | // Non-castable -> unchanged |
| 56 | for (const auto promotion : |
| 57 | {DecimalPromotion::kAdd, DecimalPromotion::kMultiply, DecimalPromotion::kDivide}) { |
| 58 | for (const auto& args : std::vector<std::vector<TypeHolder>>{ |
| 59 | {decimal128(3, 2), boolean()}, |
| 60 | {boolean(), decimal128(3, 2)}, |
| 61 | {decimal128(3, 2), utf8()}, |
| 62 | {utf8(), decimal128(3, 2)}, |
| 63 | }) { |
| 64 | auto args_copy = args; |
| 65 | ASSERT_OK(CastBinaryDecimalArgs(promotion, &args_copy)); |
| 66 | AssertTypeEqual(*args_copy[0], *args[0]); |
| 67 | AssertTypeEqual(*args_copy[1], *args[1]); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | TEST(TestDispatchBest, CastDecimalArgs) { |
| 73 | std::vector<TypeHolder> args; |
nothing calls this directly
no test coverage detected