diff --git a/src/axis.cpp b/src/axis.cpp index 4cb9d12..a145ef0 100644 --- a/src/axis.cpp +++ b/src/axis.cpp @@ -14,7 +14,9 @@ AxisTickLabels *Axis::tickLabels() { return &tickLabels_; } bool Axis::direction() const { return direction_; } double Axis::minimum() const { return minimum_; } +void Axis::setMinimum(const double value) { minimum_ = value; } double Axis::maximum() const { return maximum_; } +void Axis::setMaximum(const double value) { maximum_ = value; } int Axis::tickCount() const { return tics_.size(); } diff --git a/src/axis.h b/src/axis.h index 401097c..51d99d2 100644 --- a/src/axis.h +++ b/src/axis.h @@ -3,14 +3,15 @@ #include "axisTickLabels.h" #include #include +#include class Axis : public QQuick3DGeometry { Q_OBJECT QML_NAMED_ELEMENT(Axis) Q_PROPERTY(double thickness MEMBER thickness_ NOTIFY dataChanged) - Q_PROPERTY(double minimum MEMBER minimum_ NOTIFY dataChanged) - Q_PROPERTY(double maximum MEMBER maximum_ NOTIFY dataChanged) + Q_PROPERTY(double minimum READ minimum WRITE setMinimum NOTIFY dataChanged) + Q_PROPERTY(double maximum READ maximum WRITE setMaximum NOTIFY dataChanged) Q_PROPERTY(bool direction MEMBER direction_ NOTIFY dataChanged) Q_PROPERTY(AxisTickLabels *tickLabels READ tickLabels NOTIFY dataChanged) Q_PROPERTY(int tickCount READ tickCount NOTIFY dataChanged) @@ -21,7 +22,9 @@ class Axis : public QQuick3DGeometry AxisTickLabels *tickLabels(); bool direction() const; double minimum() const; + void setMinimum(const double value); double maximum() const; + void setMaximum(const double value); int tickCount() const; double tick(int index) const; virtual double tickCoord(int index) const; diff --git a/tests/axis.cpp b/tests/axis.cpp index 4a57da9..343f349 100644 --- a/tests/axis.cpp +++ b/tests/axis.cpp @@ -1,8 +1,41 @@ #include "axis.h" +#include "logAxis.h" #include namespace UnitTest { -TEST(AxisTest, TickMarks) { EXPECT_EQ(1, 2); } +void matchAxes(Axis &axis, std::vector &points) +{ + axis.dataChanged(); + ASSERT_EQ(axis.tickCount(), points.size()); + + for (int i = 0; i < axis.tickCount(); i++) + { + EXPECT_DOUBLE_EQ(points[i], axis.tick(i)); + } +} + +TEST(AxisTest, LinearMarks) +{ + Axis axis; + axis.setMinimum(-11.0); + axis.setMaximum(11.0); + + std::vector points = {-10, -5, 0, 5, 10}; + + matchAxes(axis, points); +} + +TEST(AxisTest, LogMarks) +{ + LogAxis axis; + axis.setMinimum(0.1); + axis.setMaximum(10.0); + + std::vector points = {0.1, 0.2, 0.3, 0.5, 0.8, 1.0, 2.0, 3.0, 5.0, 8.0, 10.0}; + + matchAxes(axis, points); +} + } // namespace UnitTest