Skip to content

Commit

Permalink
Test tick labels
Browse files Browse the repository at this point in the history
  • Loading branch information
rprospero committed Jun 18, 2024
1 parent c0689c2 commit 71434de
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

Expand Down
7 changes: 5 additions & 2 deletions src/axis.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#include "axisTickLabels.h"
#include <QQuick3DGeometry>
#include <QVector3D>
#include <gtest/gtest.h>

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)
Expand All @@ -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;
Expand Down
35 changes: 34 additions & 1 deletion tests/axis.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
#include "axis.h"
#include "logAxis.h"
#include <gtest/gtest.h>

namespace UnitTest
{

TEST(AxisTest, TickMarks) { EXPECT_EQ(1, 2); }
void matchAxes(Axis &axis, std::vector<double> &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<double> points = {-10, -5, 0, 5, 10};

matchAxes(axis, points);
}

TEST(AxisTest, LogMarks)
{
LogAxis axis;
axis.setMinimum(0.1);
axis.setMaximum(10.0);

std::vector<double> 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

0 comments on commit 71434de

Please sign in to comment.