-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbresenham_test.cpp
More file actions
48 lines (42 loc) · 1.54 KB
/
bresenham_test.cpp
File metadata and controls
48 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* bresenham_test.cpp
*
* Created on: Sep 29, 2022 22:18
* Description:
*
* Copyright (c) 2022 Pin Loon Lee (pllee4)
*/
#include "algorithm/robotics/bresenham/bresenham.hpp"
#include "gtest/gtest.h"
using namespace pllee4;
using namespace graph;
TEST(Bresenham, CheckLineFromNegativeTowardsRightDownwards) {
Coordinate start{-5, 2};
Coordinate end{2, 1};
LineGenerator line(start, end);
auto points = line.GetPoints();
std::vector<Coordinate> expected = {{-5, 2}, {-4, 2}, {-3, 2}, {-2, 2},
{-1, 1}, {0, 1}, {1, 1}, {2, 1}};
EXPECT_TRUE(std::equal(std::begin(points), std::end(points),
std::begin(expected), std::end(expected)));
}
TEST(Bresenham, CheckLineFromPositiveTowardsRightUpwards) {
Coordinate start{3, 2};
Coordinate end{15, 5};
LineGenerator line(start, end);
auto points = line.GetPoints();
std::vector<Coordinate> expected = {
{3, 2}, {4, 2}, {5, 3}, {6, 3}, {7, 3}, {8, 3}, {9, 4},
{10, 4}, {11, 4}, {12, 4}, {13, 5}, {14, 5}, {15, 5}};
EXPECT_TRUE(std::equal(std::begin(points), std::end(points),
std::begin(expected), std::end(expected)));
}
TEST(Bresenham, CheckVerticalLineReachesEndYFirst) {
Coordinate start{0, 0};
Coordinate end{1, 3};
LineGenerator line(start, end);
auto points = line.GetPoints();
std::vector<Coordinate> expected = {{0, 0}, {0, 1}, {1, 2}, {1, 3}};
EXPECT_TRUE(std::equal(std::begin(points), std::end(points),
std::begin(expected), std::end(expected)));
}