blob: d9595ddf7628220789847e92f11f0e9384841d09 [file] [log] [blame]
Rhys Kiddf667f802018-02-26 01:18:54 -05001#include <gtest/gtest.h>
2#include <hardware/hardware.h>
3
4#include "separate_rects.h"
5
6using namespace separate_rects;
7
8#define RectSet RectSet<TId, TNum>
9#define Rect Rect<TNum>
10#define IdSet IdSet<TId>
11typedef uint64_t TId;
12typedef float TNum;
13
14struct SeparateRectTest : public testing::Test {
15 bool IsEquality(std::vector<RectSet> &out,
16 std::vector<RectSet> &expected_out) {
17 // Test for rects missing from out
18 for (size_t i = 0; i < expected_out.size(); i++) {
19 RectSet &ex_out = expected_out[i];
20 if (std::find(out.begin(), out.end(), ex_out) == out.end()) {
21 return false;
22 }
23 }
24
25 // Test for presence of unexpected rects in out
26 for (size_t i = 0; i < out.size(); i++) {
27 RectSet &actual_out = out[i];
28 if (std::find(expected_out.begin(), expected_out.end(), actual_out) ==
29 expected_out.end()) {
30 return false;
31 }
32 }
33
34 return true;
35 }
36};
37
38TEST_F(SeparateRectTest, test_separate_rect) {
39 std::vector<Rect> in;
40 std::vector<RectSet> out;
41 std::vector<RectSet> expected_out;
42
43 in.push_back({0, 0, 4, 5});
44 in.push_back({2, 0, 6, 6});
45 in.push_back({4, 0, 8, 5});
46 in.push_back({0, 7, 8, 9});
47
48 in.push_back({10, 0, 18, 5});
49 in.push_back({12, 0, 16, 5});
50
51 in.push_back({20, 11, 24, 17});
52 in.push_back({22, 13, 26, 21});
53 in.push_back({32, 33, 36, 37});
54 in.push_back({30, 31, 38, 39});
55
56 in.push_back({40, 43, 48, 45});
57 in.push_back({44, 41, 46, 47});
58
59 in.push_back({50, 51, 52, 53});
60 in.push_back({50, 51, 52, 53});
61 in.push_back({50, 51, 52, 53});
62
63 in.push_back({0, 0, 0, 10});
64 in.push_back({0, 0, 10, 0});
65 in.push_back({10, 0, 0, 10});
66 in.push_back({0, 10, 10, 0});
67
68 for (int i = 0; i < 100000; i++) {
69 out.clear();
70 separate_frects_64(in, &out);
71 }
72
73 expected_out.push_back(RectSet(IdSet(0), Rect(0, 0, 2, 5)));
74 expected_out.push_back(RectSet(IdSet(1), Rect(2, 5, 6, 6)));
75 expected_out.push_back(RectSet(IdSet(1) | 0, Rect(2, 0, 4, 5)));
76 expected_out.push_back(RectSet(IdSet(1) | 2, Rect(4, 0, 6, 5)));
77 expected_out.push_back(RectSet(IdSet(2), Rect(6, 0, 8, 5)));
78 expected_out.push_back(RectSet(IdSet(3), Rect(0, 7, 8, 9)));
79 expected_out.push_back(RectSet(IdSet(4), Rect(10, 0, 12, 5)));
80 expected_out.push_back(RectSet(IdSet(5) | 4, Rect(12, 0, 16, 5)));
81 expected_out.push_back(RectSet(IdSet(4), Rect(16, 0, 18, 5)));
82 expected_out.push_back(RectSet(IdSet(6), Rect(20, 11, 22, 17)));
83 expected_out.push_back(RectSet(IdSet(6) | 7, Rect(22, 13, 24, 17)));
84 expected_out.push_back(RectSet(IdSet(6), Rect(22, 11, 24, 13)));
85 expected_out.push_back(RectSet(IdSet(7), Rect(22, 17, 24, 21)));
86 expected_out.push_back(RectSet(IdSet(7), Rect(24, 13, 26, 21)));
87 expected_out.push_back(RectSet(IdSet(9), Rect(30, 31, 32, 39)));
88 expected_out.push_back(RectSet(IdSet(8) | 9, Rect(32, 33, 36, 37)));
89 expected_out.push_back(RectSet(IdSet(9), Rect(32, 37, 36, 39)));
90 expected_out.push_back(RectSet(IdSet(9), Rect(32, 31, 36, 33)));
91 expected_out.push_back(RectSet(IdSet(9), Rect(36, 31, 38, 39)));
92 expected_out.push_back(RectSet(IdSet(10), Rect(40, 43, 44, 45)));
93 expected_out.push_back(RectSet(IdSet(10) | 11, Rect(44, 43, 46, 45)));
94 expected_out.push_back(RectSet(IdSet(11), Rect(44, 41, 46, 43)));
95 expected_out.push_back(RectSet(IdSet(11), Rect(44, 45, 46, 47)));
96 expected_out.push_back(RectSet(IdSet(10), Rect(46, 43, 48, 45)));
97 expected_out.push_back(RectSet(IdSet(12) | 13 | 14, Rect(50, 51, 52, 53)));
98
99 ASSERT_TRUE(IsEquality(out, expected_out));
100}