Skip to content

Commit

Permalink
test: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kuron99 committed Oct 18, 2023
1 parent cffaa78 commit c4cd768
Showing 1 changed file with 14 additions and 78 deletions.
92 changes: 14 additions & 78 deletions test/jogasaki/executor/process/cast_between_numerics_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,22 @@
#include <cfenv>
#include <gtest/gtest.h>
#include <glog/logging.h>
#include <boost/dynamic_bitset.hpp>

#include <jogasaki/executor/partitioner.h>
#include <jogasaki/executor/comparator.h>

#include <yugawara/storage/configurable_provider.h>
#include <yugawara/binding/factory.h>
#include <yugawara/runtime_feature.h>
#include <yugawara/compiler.h>
#include <yugawara/compiler_options.h>

#include <mizugaki/translator/shakujo_translator.h>

#include <takatori/type/int.h>
#include <takatori/type/float.h>
#include <takatori/value/int.h>
#include <takatori/value/float.h>
#include <takatori/util/string_builder.h>
#include <takatori/util/downcast.h>
#include <takatori/relation/emit.h>
#include <takatori/relation/step/take_flat.h>
#include <takatori/relation/step/offer.h>
#include <takatori/relation/buffer.h>
#include <takatori/relation/scan.h>
#include <takatori/relation/filter.h>
#include <takatori/relation/project.h>
#include <takatori/statement/write.h>
#include <takatori/statement/execute.h>
#include <takatori/scalar/immediate.h>
#include <takatori/plan/process.h>
#include <takatori/plan/forward.h>
#include <takatori/serializer/json_printer.h>
#include <takatori/scalar/binary.h>
#include <takatori/scalar/binary_operator.h>
#include <takatori/scalar/compare.h>
#include <takatori/scalar/comparison_operator.h>
#include <takatori/decimal/triple.h>

#include <jogasaki/utils/field_types.h>
#include <jogasaki/utils/checkpoint_holder.h>
#include <jogasaki/test_utils.h>
#include <jogasaki/test_root.h>

#include <jogasaki/executor/process/processor_info.h>
#include <jogasaki/executor/process/impl/ops/operator_builder.h>
#include <jogasaki/executor/process/impl/variable_table.h>
#include <jogasaki/executor/process/impl/expression/error.h>

#include <jogasaki/executor/process/impl/expression/details/cast_evaluation.h>
#include <jogasaki/executor/process/impl/expression/details/common.h>
#include <jogasaki/executor/process/impl/expression/evaluator_context.h>
Expand All @@ -79,27 +47,12 @@ using namespace std::string_literals;
using namespace std::string_view_literals;
using namespace meta;
using namespace takatori::util;
using namespace yugawara::binding;

using namespace ::mizugaki::translator;
using namespace ::mizugaki;

using namespace testing;

using code = shakujo_translator_code;
using result_kind = shakujo_translator::result_type::kind_type;

namespace type = ::takatori::type;
namespace value = ::takatori::value;
namespace scalar = ::takatori::scalar;
namespace relation = ::takatori::relation;
namespace statement = ::takatori::statement;

using take = relation::step::take_flat;
using offer = relation::step::offer;
using buffer = relation::buffer;

using rgraph = ::takatori::relation::graph_type;

using binary = takatori::scalar::binary;
using binary_operator = takatori::scalar::binary_operator;
Expand All @@ -117,25 +70,6 @@ using namespace details;

class cast_between_numerics_test : public test_root {
public:

yugawara::analyzer::variable_mapping& variables() noexcept {
return *variables_;
}

yugawara::analyzer::expression_mapping& expressions() noexcept {
return *expressions_;
}

std::shared_ptr<yugawara::analyzer::variable_mapping> variables_ = std::make_shared<yugawara::analyzer::variable_mapping>();
std::shared_ptr<yugawara::analyzer::expression_mapping> expressions_ = std::make_shared<yugawara::analyzer::expression_mapping>();

factory f_{};
maybe_shared_ptr<meta::record_meta> meta_{};
variable_table_info info_{};
variable_table vars_{};

compiled_info c_info_{};
expression::evaluator evaluator_{};
memory::page_pool pool_{};
memory::lifo_paged_memory_resource resource_{&pool_};

Expand Down Expand Up @@ -178,18 +112,6 @@ any any_triple(
return any{std::in_place_type<triple>, triple{sign, coefficient_high, coefficient_low, exponent}};
}

any any_int8(
std::int64_t arg
) {
return any{std::in_place_type<std::int64_t>, arg};
}

any any_int4(
std::int32_t arg
) {
return any{std::in_place_type<std::int32_t>, arg};
}

any any_error(
error_kind arg
) {
Expand Down Expand Up @@ -770,5 +692,19 @@ TEST_F(cast_between_numerics_test, float8_to_float4) {
EXPECT_EQ((any{std::in_place_type<float>, std::numeric_limits<float>::min()}), from_float8::to_float4(std::nextafter(static_cast<double>(std::numeric_limits<float>::min()), -std::numeric_limits<double>::infinity()), ctx));
EXPECT_EQ((any{std::in_place_type<float>, -std::numeric_limits<float>::min()}), from_float8::to_float4(std::nextafter(static_cast<double>(-std::numeric_limits<float>::min()), std::numeric_limits<double>::infinity()), ctx));
}

TEST_F(cast_between_numerics_test, decimal_to_decimal) {
evaluator_context ctx{&resource_};
EXPECT_EQ(any_triple(1, 0, 1, 0), from_decimal::to_decimal(make_triple("1"), ctx, {}, {}));
EXPECT_EQ(any_triple(1, 0, 123, 0), from_decimal::to_decimal(make_triple("123"), ctx, {}, {}));
EXPECT_EQ(any_triple(1, 0, 12345, -2), from_decimal::to_decimal(make_triple("123.45"), ctx, {}, {}));

EXPECT_EQ(any_triple(1, 0, 12345, -2), from_decimal::to_decimal(make_triple("123.45"), ctx, 5, 2));
EXPECT_EQ(any_triple(1, 0, 123450, -3), from_decimal::to_decimal(make_triple("123.45"), ctx, 6, 3));
EXPECT_EQ(any_triple(1, 0, 123450, -3), from_decimal::to_decimal(make_triple("123.45"), ctx, {}, 3));
EXPECT_EQ(any_error(error_kind::overflow), from_decimal::to_decimal(make_triple("123.45"), ctx, 4, 2));
EXPECT_EQ(any_error(error_kind::overflow), from_decimal::to_decimal(make_triple("123.45"), ctx, 4, {}));
EXPECT_EQ(any_triple(1, 0, 123, 0), from_decimal::to_decimal(make_triple("123.45"), ctx, {}, 0));
}
}

0 comments on commit c4cd768

Please sign in to comment.