51 lines
1.9 KiB
C++
51 lines
1.9 KiB
C++
#include <render_2D/module/plottable/axis/Axis.hpp>
|
|
#include <gtest/gtest.h>
|
|
namespace {
|
|
using namespace aethera;
|
|
using namespace aethera::render_2d;
|
|
|
|
TEST(Axis, Numeric_Axis_Converts_Both_Orientations) {
|
|
Numeric_Axis::Builder builder;
|
|
builder
|
|
.set<Prop_Tag>(&Abs_Axis::Prop::position, Point_F{10.0, 20.0})
|
|
.set<Prop_Tag>(&Abs_Axis::Prop::pixel_length, 200.0)
|
|
.set<Prop_Tag>(&Numeric_Axis::Prop::coordinate_range, Axis_Range{0.0, 20.0});
|
|
auto axis = builder.build();
|
|
EXPECT_DOUBLE_EQ(axis->coordinate_to_pixel(5.0), 60.0);
|
|
axis->set<Prop_Tag>(&Abs_Axis::Prop::orientation, Axis_Orientation::vertical);
|
|
aethera::detail::model_private(*axis).advance();
|
|
EXPECT_DOUBLE_EQ(axis->point_to_coordinate({90.0, 70.0}), 5.0);
|
|
}
|
|
|
|
TEST(Axis, Numeric_Axis_Handles_Native_Events) {
|
|
Numeric_Axis::Builder builder;
|
|
builder
|
|
.set<Prop_Tag>(&Abs_Axis::Prop::pixel_length, 100.0)
|
|
.set<Prop_Tag>(&Numeric_Axis::Prop::coordinate_range, Axis_Range{0.0, 10.0});
|
|
auto axis = builder.build();
|
|
auto& private_data = aethera::detail::model_private(*axis);
|
|
Wheel_Event wheel;
|
|
wheel.position = {50.0, 0.0};
|
|
wheel.angle_delta_y = 120.0;
|
|
private_data.dispatch_event(wheel);
|
|
ASSERT_TRUE(wheel.is_accepted());
|
|
private_data.advance();
|
|
EXPECT_EQ(axis->coordinate_range(), (Axis_Range{0.5, 9.5}));
|
|
}
|
|
|
|
TEST(Axis, Frequency_And_Time_Axes_Keep_Their_Specialization) {
|
|
auto frequency = Frequency_Axis::Builder{}.build();
|
|
EXPECT_EQ(frequency->tick_label(2'500.0), "2.5 kHz");
|
|
Time_Axis::Builder builder;
|
|
builder
|
|
.set<Prop_Tag>(&Time_Axis::Prop::visible_count, 2);
|
|
auto time = builder.build();
|
|
EXPECT_EQ(time->append_time({1'000}), 0);
|
|
EXPECT_EQ(time->append_time({2'000}), 1);
|
|
EXPECT_EQ(time->append_time({3'000}), 2);
|
|
aethera::detail::model_private(*time).advance();
|
|
EXPECT_EQ(time->time_point_count(), 2U);
|
|
EXPECT_EQ(time->tick_to_time(1), (Time_Of_Day{2'000}));
|
|
}
|
|
} // namespace
|