summary refs log tree commit diff stats
path: root/Test/PanelExtractionTests.cpp
blob: dfb9b9e52aca00e62dbde71ad5d04be4ebe77fc4 (plain) (blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "gtest/gtest.h"
#include "Panel.h"

class PanelExtractionTests : public testing::Test
{
protected:
	Panel _panel;
	// std::shared_ptr<Panel> _panel;

	void SetPanelSize(int width, int height) {
		// _panel = std::make_shared<Panel>();
		_panel._width = width;
		_panel._height = height;
	}

	std::tuple<int, int> loc_to_xy(int location) {
		return _panel.loc_to_xy(location);
	}

	int xy_to_loc(int x, int y) {
		return _panel.xy_to_loc(x, y);
	}
};

TEST_F(PanelExtractionTests, LocToXY_7x5) {
	SetPanelSize(7, 5);
	/* Here's the panel, with the correct location order
	8 . 9 . 10. 11 (_width = 7)
	. . . . . . .
	4 . 5 . 6 . 7
	. . . . . . .
	0 . 1 . 2 . 3
	(_height = 5)
	*/
	ASSERT_EQ(0, xy_to_loc(0, 4));
	ASSERT_EQ(1, xy_to_loc(2, 4));
	ASSERT_EQ(2, xy_to_loc(4, 4));
	ASSERT_EQ(3, xy_to_loc(6, 4));

	ASSERT_EQ(4, xy_to_loc(0, 2));
	ASSERT_EQ(5, xy_to_loc(2, 2));
	ASSERT_EQ(6, xy_to_loc(4, 2));
	ASSERT_EQ(7, xy_to_loc(6, 2));

	ASSERT_EQ(8, xy_to_loc(0, 0));
	ASSERT_EQ(9, xy_to_loc(2, 0));
	ASSERT_EQ(10, xy_to_loc(4, 0));
	ASSERT_EQ(11, xy_to_loc(6, 0));
}

TEST_F(PanelExtractionTests, LocToXY_3x3) {
	SetPanelSize(3, 3);
	/* Here's the panel, with the correct location order
	2 . 3 (_width = 3)
	. . .
	0 . 1
	(_height = 3)
	*/
	ASSERT_EQ(0, xy_to_loc(0, 2));
	ASSERT_EQ(1, xy_to_loc(2, 2));
	ASSERT_EQ(2, xy_to_loc(0, 0));
	ASSERT_EQ(3, xy_to_loc(2, 0));
}