Skip to content

Commit

Permalink
Rework ACAlgorithm test to use double type values as expected values
Browse files Browse the repository at this point in the history
  • Loading branch information
Popov-Dmitriy-Ivanovich authored and polyntsov committed Dec 9, 2023
1 parent 9320b47 commit 0fd3148
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
47 changes: 21 additions & 26 deletions src/tests/test_ac_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@
#include "types.h"

namespace {
void AssertRanges(std::vector<std::string>& expected_ranges,
void AssertRanges(std::vector<model::Double>& expected_ranges,
algos::RangesCollection const& byte_ranges) {
ASSERT_EQ(expected_ranges.size(), byte_ranges.ranges.size());

auto expected = std::unique_ptr<std::byte[]>(byte_ranges.col_pair.num_type->Allocate());
model::DoubleType double_type;
for (size_t i = 0; i < expected_ranges.size(); ++i) {
// FIXME:
/* Для значения "7.4": сравнение через num_type->Compare() значений в виде std::byte
* (полученных с помощью num_type->ValueFromStr()) возвращает, что они не равны,
* однако при использовании на этих же значениях num_type->ValueToString()
* полученные строки оказываются равными */
byte_ranges.col_pair.num_type->ValueFromStr(expected.get(), expected_ranges[i]);
EXPECT_EQ(byte_ranges.col_pair.num_type->ValueToString(expected.get()),
byte_ranges.col_pair.num_type->ValueToString(byte_ranges.ranges[i]));
auto expected = std::unique_ptr<std::byte[]>(double_type.MakeValue(expected_ranges[i]));
double_type.CastTo(expected.get(), byte_ranges.col_pair.num_type->GetTypeId());
EXPECT_EQ(byte_ranges.col_pair.num_type->Compare(expected.get(), byte_ranges.ranges[i]),
model::CompareResult::kEqual);
}
}

Expand Down Expand Up @@ -88,7 +84,7 @@ TEST_F(ACAlgorithmTest, NonFuzzyBumpsDetection1) {
a->Execute();
auto& ranges_collection = a->GetRangesByColumns(0, 2);

std::vector<std::string> expected_ranges = {"5.4", "7.4", "8.1", "8.5", "9.1", "14.6"};
std::vector<model::Double> expected_ranges = {5.4, 7.4, 8.1, 8.5, 9.1, 14.6};

AssertRanges(expected_ranges, ranges_collection);
}
Expand All @@ -99,7 +95,7 @@ TEST_F(ACAlgorithmTest, NonFuzzyBumpsDetection2) {
a->Execute();
auto& ranges_collection = a->GetRangesByColumns(2, 3);

std::vector<std::string> expected_ranges = {"1.2", "2.3", "4.1", "9.2"};
std::vector<model::Double> expected_ranges = {1.2, 2.3, 4.1, 9.2};

AssertRanges(expected_ranges, ranges_collection);
}
Expand All @@ -117,7 +113,7 @@ TEST_F(ACAlgorithmTest, SubNonFuzzy) {
a->Execute();
auto& ranges_collection = a->GetRangesByColumns(1, 3);

std::vector<std::string> expected_ranges = {"0.3", "2.0", "2.7", "4.0"};
std::vector<model::Double> expected_ranges = {0.3, 2.0, 2.7, 4.0};

AssertRanges(expected_ranges, ranges_collection);
}
Expand All @@ -127,7 +123,7 @@ TEST_F(ACAlgorithmTest, MulNonFuzzy) {
a->Execute();
auto& ranges_collection = a->GetRangesByColumns(2, 3);

std::vector<std::string> expected_ranges = {"0.11", "0.96", "3.3", "15.87"};
std::vector<model::Double> expected_ranges = {0.11, 0.96, 3.3, 15.87};

AssertRanges(expected_ranges, ranges_collection);
}
Expand All @@ -138,17 +134,17 @@ TEST_F(ACAlgorithmTest, DivNonFuzzy) {
auto& ranges_collection01 = a->GetRangesByColumns(0, 1);
auto& ranges_collection10 = a->GetRangesByColumns(1, 0);

std::vector<std::string> expected_ranges01 = {"0", "1", "10", "10"};
std::vector<std::string> true_ranges10 = {"0", "0", "1", "1"};
std::vector<model::Double> expected_ranges01 = {0, 1, 10, 10};
std::vector<model::Double> true_ranges10 = {0, 0, 1, 1};

AssertRanges(expected_ranges01, ranges_collection01);
AssertRanges(true_ranges10, ranges_collection10);

auto& ranges_collection02 = a->GetRangesByColumns(0, 2);
auto& ranges_collection20 = a->GetRangesByColumns(2, 0);

std::vector<std::string> expected_ranges02 = {"1", "1"};
std::vector<std::string> expected_ranges20 = {"0", "0", "1", "1"};
std::vector<model::Double> expected_ranges02 = {1, 1};
std::vector<model::Double> expected_ranges20 = {0, 0, 1, 1};

AssertRanges(expected_ranges02, ranges_collection02);
AssertRanges(expected_ranges20, ranges_collection20);
Expand All @@ -162,10 +158,9 @@ TEST_F(ACAlgorithmTest, FuzzyBumpsDetection) {
auto& ranges_collection02 = a->GetRangesByColumns(0, 2);
auto& ranges_collection12 = a->GetRangesByColumns(1, 2);

std::vector<std::string> expected_ranges01 = {"3", "3", "4", "4", "5", "5",
"6", "6", "7", "7", "8", "8"};
std::vector<std::string> expected_ranges02 = {"2", "2", "8", "9", "12", "13"};
std::vector<std::string> expected_ranges12 = {"9", "9", "11", "11"};
std::vector<model::Double> expected_ranges01 = {3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8};
std::vector<model::Double> expected_ranges02 = {2, 2, 8, 9, 12, 13};
std::vector<model::Double> expected_ranges12 = {9, 9, 11, 11};

AssertRanges(expected_ranges01, ranges_collection01);
AssertRanges(expected_ranges02, ranges_collection02);
Expand All @@ -181,9 +176,9 @@ TEST_F(ACAlgorithmTest, NullAndEmptyIgnoring) {
auto& ranges_collection02 = a->GetRangesByColumns(0, 2);
auto& ranges_collection12 = a->GetRangesByColumns(0, 3);

std::vector<std::string> expected_ranges01 = {"3", "3"};
std::vector<std::string> expected_ranges02 = {"4", "4"};
std::vector<std::string> expected_ranges03 = {"2", "2"};
std::vector<model::Double> expected_ranges01 = {3, 3};
std::vector<model::Double> expected_ranges02 = {4, 4};
std::vector<model::Double> expected_ranges03 = {2, 2};

AssertRanges(expected_ranges01, ranges_collection01);
AssertRanges(expected_ranges02, ranges_collection02);
Expand Down Expand Up @@ -216,7 +211,7 @@ TEST_F(ACAlgorithmTest, RangesReconstruction) {
auto a = CreateACAlgorithmInstance("iris.csv", ',', false, algos::Binop::Subtraction, 0.0);
a->Execute();
auto ranges_collection = a->ReconstructRangesByColumns(1, 3, 1);
std::vector<std::string> expected_ranges = {"0.3", "4.0"};
std::vector<model::Double> expected_ranges = {0.3, 4.0};

AssertRanges(expected_ranges, ranges_collection);
}
Expand Down
28 changes: 14 additions & 14 deletions src/tests/test_double_compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class DoubleCompare : public ::testing::Test {
std::byte* double_max;
std::byte* result;

static void add(std::byte* a, std::byte* b, std::byte* res) {
static void Add(std::byte* a, std::byte* b, std::byte* res) {
model::DoubleType double_type;
double_type.Add(a, b, res);
}
static void sub(std::byte* a, std::byte* b, std::byte* res) {
static void Sub(std::byte* a, std::byte* b, std::byte* res) {
model::DoubleType double_type;
double_type.Sub(a, b, res);
}
static void mul(std::byte* a, std::byte* b, std::byte* res) {
static void Mul(std::byte* a, std::byte* b, std::byte* res) {
model::DoubleType double_type;
double_type.Mul(a, b, res);
}
static void div(std::byte* a, std::byte* b, std::byte* res) {
static void Div(std::byte* a, std::byte* b, std::byte* res) {
model::DoubleType double_type;
double_type.Div(a, b, res);
}
Expand Down Expand Up @@ -115,23 +115,23 @@ TEST_F(DoubleCompare, ComprasionFromAcAlgorithm) {
}

TEST_F(DoubleCompare, AddNumbers) {
TestArithmetic(7.7, 8.8, 7.7 + 8.8, add);
TestArithmetic(777.777, 888.888, 777.777 + 888.888, add);
TestArithmetic(7.7, 8.8, 7.7 + 8.8, Add);
TestArithmetic(777.777, 888.888, 777.777 + 888.888, Add);
}

TEST_F(DoubleCompare, SubNumbers) {
TestArithmetic(7.7, 8.8, 7.7 - 8.8, sub);
TestArithmetic(777.777, 888.888, 777.777 - 888.888, sub);
TestArithmetic(7.7, 8.8, 7.7 - 8.8, Sub);
TestArithmetic(777.777, 888.888, 777.777 - 888.888, Sub);
}

TEST_F(DoubleCompare, MulNumbers) {
TestArithmetic(7.7, 8.8, 7.7 * 8.8, mul);
TestArithmetic(777.777, 888.888, 777.777 * 888.888, mul);
TestArithmetic(7.7, 8.8, 7.7 * 8.8, Mul);
TestArithmetic(777.777, 888.888, 777.777 * 888.888, Mul);
}

TEST_F(DoubleCompare, DivNumbers) {
TestArithmetic(7.7, 8.8, 7.7 / 8.8, div);
TestArithmetic(777.777, 888.888, 777.777 / 888.888, div);
TestArithmetic(7.7, 8.8, 7.7 / 8.8, Div);
TestArithmetic(777.777, 888.888, 777.777 / 888.888, Div);
}

TEST_F(DoubleCompare, TwoSmallNumbers) {
Expand All @@ -153,11 +153,11 @@ TEST_F(DoubleCompare, EpsilonMin) {
}
TEST_F(DoubleCompare, LowFractionalNumber) {
std::unique_ptr<std::byte[]> ten_power_minus_2(double_type.MakeValue(1e-2));
std::unique_ptr<std::byte[]> ten_power_minus_2_plus_eps_div_ten(
std::unique_ptr<std::byte[]> ten_power_minus_2_plus_eps_Div_ten(
double_type.MakeValue(1e-2 + 2.5e-17));

ASSERT_EQ(double_type_ref.Compare(ten_power_minus_2.get(),
ten_power_minus_2_plus_eps_div_ten.get()),
ten_power_minus_2_plus_eps_Div_ten.get()),
model::CompareResult::kLess);
}
TEST_F(DoubleCompare, BigFractionalNumber) {
Expand Down

0 comments on commit 0fd3148

Please sign in to comment.