17 #include "my_config.h"
18 #include <gtest/gtest.h>
22 namespace cost_estimate_unittest {
24 TEST(CostEstimateTest, Basics)
31 const double initial_io_cost= 4.5;
33 ce1.
add_io(initial_io_cost);
35 EXPECT_DOUBLE_EQ(initial_io_cost, ce1.
total_cost());
37 const double initial_cpu_cost= 3.3;
40 EXPECT_DOUBLE_EQ(initial_cpu_cost, ce1.get_cpu_cost());
41 EXPECT_DOUBLE_EQ(initial_io_cost, ce1.get_io_cost());
42 EXPECT_DOUBLE_EQ(initial_io_cost + initial_cpu_cost, ce1.
total_cost());
44 EXPECT_EQ(0, ce1.get_mem_cost());
45 EXPECT_EQ(0, ce1.get_import_cost());
47 const double initial_mem_cost= 7;
48 const double initial_import_cost= 11;
52 const double total_initial_cost=
53 initial_io_cost + initial_cpu_cost + initial_import_cost;
54 EXPECT_DOUBLE_EQ(total_initial_cost, ce1.
total_cost());
56 const double added_io_cost= 1.5;
58 EXPECT_DOUBLE_EQ(initial_io_cost + added_io_cost, ce1.get_io_cost());
59 EXPECT_DOUBLE_EQ(total_initial_cost + added_io_cost, ce1.
total_cost());
68 TEST(CostEstimateTest, Operators)
75 const double initial_io_cost= 4.5;
76 ce_io.
add_io(initial_io_cost);
77 EXPECT_DOUBLE_EQ(initial_io_cost, ce_io.
total_cost());
80 const double initial_cpu_cost= 3.3;
81 ce_cpu.
add_cpu(initial_cpu_cost);
82 EXPECT_DOUBLE_EQ(initial_cpu_cost, ce_cpu.total_cost());
83 EXPECT_EQ(0, ce_cpu.get_io_cost());
87 const double added_io_cost= 1.5;
88 ce_io.
add_io(added_io_cost);
89 EXPECT_DOUBLE_EQ(initial_io_cost + added_io_cost, ce_io.
total_cost());
90 EXPECT_DOUBLE_EQ(initial_io_cost, ce_copy.total_cost());
94 EXPECT_DOUBLE_EQ(initial_io_cost + initial_cpu_cost, ce_copy.total_cost());
98 const double copy2_totcost=
99 initial_io_cost + added_io_cost + initial_cpu_cost;
100 EXPECT_DOUBLE_EQ(copy2_totcost, ce_copy2.total_cost());
103 const double import1_mem_cost= 3;
104 const double import1_import_cost= 5;
105 ce_mem_import1.
add_mem(import1_mem_cost);
106 ce_mem_import1.add_import(import1_import_cost);
109 const double import2_mem_cost= 11;
110 const double import2_import_cost= 13;
111 ce_mem_import2.
add_mem(import2_mem_cost);
112 ce_mem_import2.
add_import(import2_import_cost);
116 EXPECT_DOUBLE_EQ(import1_import_cost + import2_import_cost,
118 EXPECT_DOUBLE_EQ(import1_mem_cost + import2_mem_cost,
119 ce_mi_copy.get_mem_cost());
120 EXPECT_DOUBLE_EQ(import1_import_cost + import2_import_cost,
121 ce_mi_copy.get_import_cost());
124 ce_mi_copy+= ce_mem_import1;
125 EXPECT_DOUBLE_EQ(2*import1_import_cost + import2_import_cost,
126 ce_mi_copy.total_cost());
127 EXPECT_DOUBLE_EQ(2*import1_mem_cost + import2_mem_cost,
128 ce_mi_copy.get_mem_cost());
129 EXPECT_DOUBLE_EQ(2*import1_import_cost + import2_import_cost,
130 ce_mi_copy.get_import_cost());
135 EXPECT_DOUBLE_EQ(copy2_totcost, ce_copy3.total_cost());