Skip to content

Commit

Permalink
Check coordinates are okay
Browse files Browse the repository at this point in the history
  • Loading branch information
rprospero committed Jun 18, 2024
1 parent 71434de commit 26d59fc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/axis.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#include "axis.h"
#include "logAxis.h"
#include <algorithm>
#include <gtest/gtest.h>

namespace UnitTest
{

void matchAxes(Axis &axis, std::vector<double> &points)
void matchAxes(Axis &axis, std::vector<double> &points, std::vector<double> &coords)
{
axis.dataChanged();
ASSERT_EQ(axis.tickCount(), points.size());
ASSERT_EQ(axis.tickCount(), coords.size());

for (int i = 0; i < axis.tickCount(); i++)
{
EXPECT_DOUBLE_EQ(points[i], axis.tick(i));
EXPECT_DOUBLE_EQ(coords[i], axis.tickCoord(i));
}
}

Expand All @@ -23,8 +26,9 @@ TEST(AxisTest, LinearMarks)
axis.setMaximum(11.0);

std::vector<double> points = {-10, -5, 0, 5, 10};
std::vector<double> coords = {1.0 / 11.0, 6.0 / 11.0, 1.0, 16.0 / 11.0, 21.0 / 11.0};

matchAxes(axis, points);
matchAxes(axis, points, coords);
}

TEST(AxisTest, LogMarks)
Expand All @@ -34,8 +38,10 @@ TEST(AxisTest, LogMarks)
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};
std::vector<double> coords(points.size());
std::transform(points.begin(), points.end(), coords.begin(), [](const auto x) { return log10(x) + 1.0; });

matchAxes(axis, points);
matchAxes(axis, points, coords);
}

} // namespace UnitTest

0 comments on commit 26d59fc

Please sign in to comment.