5
5
#include " partition_regions.h"
6
6
#include " region.h"
7
7
8
+ /* *
9
+ * This file contains unit tests that check the functionality of all classes related to vpr constraints. These classes include
10
+ * VprConstraints, Region, PartitionRegions, and Partition.
11
+ */
12
+
8
13
TEST_CASE (" RegionAccessors" , " [vpr]" ) {
9
14
Region r1;
10
15
11
16
r1.set_region_rect (1 , 2 , 3 , 4 );
12
17
r1.set_sub_tile (2 );
13
18
14
- REQUIRE (r1.get_xmin () == 1 );
15
- REQUIRE (r1.get_ymin () == 2 );
16
- REQUIRE (r1.get_xmax () == 3 );
17
- REQUIRE (r1.get_ymax () == 4 );
19
+ vtr::Rect<int > rect;
20
+ rect = r1.get_region_rect ();
21
+
22
+ REQUIRE (rect.xmin () == 1 );
23
+ REQUIRE (rect.ymin () == 2 );
24
+ REQUIRE (rect.xmax () == 3 );
25
+ REQUIRE (rect.ymax () == 4 );
18
26
REQUIRE (r1.get_sub_tile () == 2 );
27
+
28
+ // checking that default constructor creates an empty rectangle (-1,-1,-1,-1)
29
+ Region def_region;
30
+ bool is_def_empty = false ;
31
+
32
+ vtr::Rect<int > def_rect = def_region.get_region_rect ();
33
+ is_def_empty = def_rect.empty ();
34
+ REQUIRE (is_def_empty == true );
35
+ REQUIRE (def_rect.xmin () == -1 );
19
36
}
20
37
21
38
TEST_CASE (" PartitionRegionsAccessors" , " [vpr]" ) {
22
39
Region r1;
23
40
24
- r1.set_region_rect (0 , 0 , 1 , 1 );
41
+ r1.set_region_rect (2 , 3 , 6 , 7 );
25
42
r1.set_sub_tile (3 );
26
43
27
44
PartitionRegions pr1;
@@ -30,6 +47,12 @@ TEST_CASE("PartitionRegionsAccessors", "[vpr]") {
30
47
31
48
std::vector<Region> pr_regions = pr1.get_partition_regions ();
32
49
REQUIRE (pr_regions[0 ].get_sub_tile () == 3 );
50
+ vtr::Rect<int > rect;
51
+ rect = pr_regions[0 ].get_region_rect ();
52
+ REQUIRE (rect.xmin () == 2 );
53
+ REQUIRE (rect.ymin () == 3 );
54
+ REQUIRE (rect.xmax () == 6 );
55
+ REQUIRE (rect.ymax () == 7 );
33
56
}
34
57
35
58
TEST_CASE (" PartitionAccessors" , " [vpr]" ) {
@@ -50,10 +73,11 @@ TEST_CASE("PartitionAccessors", "[vpr]") {
50
73
REQUIRE (atoms[0 ] == atom_1);
51
74
REQUIRE (atoms[1 ] == atom_2);
52
75
REQUIRE (part.contains_atom (atom_1) == true );
76
+ REQUIRE (part.contains_atom (atom_2) == true );
53
77
54
- // create region and partitionregions objects to test accessors of the Partitions class
78
+ // create region and partitionregions objects to test accessors of the Partition class
55
79
Region r1;
56
- r1.set_region_rect (0 , 0 , 1 , 1 );
80
+ r1.set_region_rect (2 , 3 , 7 , 8 );
57
81
r1.set_sub_tile (3 );
58
82
59
83
PartitionRegions part_reg;
@@ -64,6 +88,12 @@ TEST_CASE("PartitionAccessors", "[vpr]") {
64
88
std::vector<Region> regions = part_reg_2.get_partition_regions ();
65
89
66
90
REQUIRE (regions[0 ].get_sub_tile () == 3 );
91
+ vtr::Rect<int > rect;
92
+ rect = regions[0 ].get_region_rect ();
93
+ REQUIRE (rect.xmin () == 2 );
94
+ REQUIRE (rect.ymin () == 3 );
95
+ REQUIRE (rect.xmax () == 7 );
96
+ REQUIRE (rect.ymax () == 8 );
67
97
}
68
98
69
99
TEST_CASE (" VprConstraintsAccessors" , " [vpr]" ) {
@@ -95,20 +125,48 @@ TEST_CASE("VprConstraintsAccessors", "[vpr]") {
95
125
}
96
126
97
127
TEST_CASE (" RegionIntersect" , " [vpr]" ) {
128
+ // Test partial intersection
98
129
Region region1;
99
130
Region region2;
100
131
101
- region1.set_region_rect (0 , 0 , 2 , 2 );
102
- region2.set_region_rect (1 , 1 , 2 , 2 );
132
+ region1.set_region_rect (1 , 2 , 3 , 5 );
133
+ region2.set_region_rect (2 , 3 , 4 , 6 );
103
134
104
135
Region int_reg;
105
136
106
137
int_reg = region1.regions_intersection (region2);
138
+ vtr::Rect<int > rect = int_reg.get_region_rect ();
139
+
140
+ REQUIRE (rect.xmin () == 2 );
141
+ REQUIRE (rect.ymin () == 3 );
142
+ REQUIRE (rect.xmax () == 3 );
143
+ REQUIRE (rect.ymax () == 5 );
144
+
145
+ // Test full overlap
146
+ Region region3;
147
+ Region region4;
148
+
149
+ region3.set_region_rect (5 ,1 ,8 ,6 );
150
+ region4.set_region_rect (6 ,3 ,8 ,6 );
151
+
152
+ Region int_reg_2;
153
+
154
+ int_reg_2 = region3.regions_intersection (region4);
155
+ vtr::Rect<int > rect_2 = int_reg_2.get_region_rect ();
156
+
157
+ REQUIRE (rect_2.xmin () == 6 );
158
+ REQUIRE (rect_2.ymin () == 3 );
159
+ REQUIRE (rect_2.xmax () == 8 );
160
+ REQUIRE (rect_2.ymax () == 6 );
161
+
162
+ // Test no intersection (rect is empty)
163
+
164
+ Region int_reg_3;
107
165
108
- REQUIRE (int_reg. get_xmin () == 1 );
109
- REQUIRE (int_reg. get_ymin () == 1 );
110
- REQUIRE (int_reg. get_xmax () == 2 );
111
- REQUIRE (int_reg. get_ymax () == 2 );
166
+ int_reg_3 = region1. regions_intersection (region3 );
167
+ vtr::Rect< int > rect_3 = int_reg_3. get_region_rect ( );
168
+
169
+ REQUIRE (rect_3. empty () == TRUE );
112
170
}
113
171
114
172
TEST_CASE (" PartRegionIntersect" , " [vpr]" ) {
@@ -145,15 +203,34 @@ TEST_CASE("PartRegionIntersect", "[vpr]") {
145
203
146
204
TEST_CASE (" RegionLocked" , " [vpr]" ) {
147
205
Region r1;
148
-
149
- r1.set_region_rect (0 , 1 , 0 , 1 ); // xmin = xmax = 0, ymin = ymax =1
150
- r1.set_sub_tile (3 ); // set the region to specific x, y, subtile to lock down
151
-
152
206
bool is_r1_locked = false ;
153
207
208
+ // set the region to a specific x, y, subtile location - region is locked
209
+ r1.set_region_rect (2 ,3 ,2 ,3 ); // point (2,3) to point (2,3) - locking to specific x, y location
210
+ r1.set_sub_tile (3 ); // locking down to subtile 3
211
+
154
212
is_r1_locked = r1.locked ();
155
213
156
214
REQUIRE (is_r1_locked == true );
215
+
216
+ // do not set region to specific x, y location - region is not locked even if a subtile is specified
217
+ r1.set_region_rect (2 ,3 ,5 ,6 ); // point (2,3) to point (5,6) - not locking to specific x, y location
218
+ r1.set_sub_tile (3 ); // locking down to subtile 3
219
+
220
+ is_r1_locked = r1.locked ();
221
+
222
+ REQUIRE (is_r1_locked == false );
223
+
224
+ // do not specify a subtile for the region - region is not locked even if it is set at specific x, y location
225
+ Region r2;
226
+ bool is_r2_locked = true ;
227
+
228
+ r2.set_region_rect (2 ,3 ,2 ,3 );
229
+
230
+ is_r2_locked = r2.locked ();
231
+
232
+ REQUIRE (is_r2_locked == false );
233
+
157
234
}
158
235
159
236
TEST_CASE (" PartRegionIntersect2" , " [vpr]" ) {
0 commit comments