1 // This is gel/vtol/tests/test_block.cxx
2 #include "testlib/testlib_test.h"
3 #include <vtol/vtol_vertex_2d_sptr.h>
4 #include <vtol/vtol_vertex_2d.h>
5 #include <vtol/vtol_face_2d.h>
6 #include <vtol/vtol_face_2d_sptr.h>
7 #include <vtol/vtol_two_chain.h>
8 #include <vtol/vtol_two_chain_sptr.h>
9 #include <vtol/vtol_block.h>
10 #include <vtol/vtol_block_sptr.h>
11 
test_block()12 static void test_block()
13 {
14   std::cout << "testing block\n";
15 
16   vtol_vertex_2d_sptr v1 = new vtol_vertex_2d(0.0,0.0);
17   vtol_vertex_2d_sptr v2 = new vtol_vertex_2d(1.0,1.0);
18   vtol_vertex_2d_sptr v3 = new vtol_vertex_2d(2.0,2.0);
19   vtol_vertex_2d_sptr v4 = new vtol_vertex_2d(3.0,3.0);
20 
21   vertex_list v_list1;
22 
23   v_list1.push_back(v1->cast_to_vertex());
24   v_list1.push_back(v2->cast_to_vertex());
25   v_list1.push_back(v3->cast_to_vertex());
26   v_list1.push_back(v4->cast_to_vertex());
27 
28   vtol_face_2d_sptr f1 = new vtol_face_2d(v_list1);
29 
30   vtol_vertex_2d_sptr v5 = new vtol_vertex_2d(1.0,0.0);
31   vtol_vertex_2d_sptr v6 = new vtol_vertex_2d(2.0,1.0);
32   vtol_vertex_2d_sptr v7 = new vtol_vertex_2d(3.0,2.0);
33   vtol_vertex_2d_sptr v8 = new vtol_vertex_2d(4.0,3.0);
34 
35   vertex_list v_list2;
36 
37   v_list2.push_back(v5->cast_to_vertex());
38   v_list2.push_back(v6->cast_to_vertex());
39   v_list2.push_back(v7->cast_to_vertex());
40   v_list2.push_back(v8->cast_to_vertex());
41 
42   vtol_face_2d_sptr f2 = new vtol_face_2d(v_list2);
43 
44   face_list f_list1;
45 
46   f_list1.push_back(f1->cast_to_face());
47   f_list1.push_back(f2->cast_to_face());
48 
49   vtol_two_chain_sptr tc1 = new vtol_two_chain(f_list1);
50   vtol_two_chain_sptr tc1_copy = new vtol_two_chain(f_list1);
51   tc1->describe(std::cout,8);
52 
53   TEST("vtol_two_chain equality", *tc1, *tc1_copy);
54   vtol_block_sptr b1 = new vtol_block(tc1);
55   b1->describe(std::cout,8);
56 
57   std::vector<signed char> dirs;
58 
59   dirs.push_back(1);
60   dirs.push_back(1);
61 
62   vtol_two_chain_sptr tc2 = new vtol_two_chain(f_list1,dirs);
63 
64   vtol_block_sptr b3 = new vtol_block(f_list1);
65   TEST("vtol_block equality", *b3, *b1);
66   b3->describe(std::cout,8);
67 
68   TEST("vtol_block::get_boundary_cycle() is not null", b1->get_boundary_cycle()?true:false, true);
69   TEST("vtol_block::get_boundary_cycle()", b1->get_boundary_cycle(), tc1);
70   TEST("vtol_block::get_boundary_cycle()", *(b1->get_boundary_cycle()), *(b3->get_boundary_cycle()));
71 
72   vtol_block_sptr b1_copy = new vtol_block(b1);
73   TEST("vtol_block deep copy (pseudo copy constructor)", *b1, *b1_copy);
74   b1_copy->describe(std::cout,8);
75 
76   TEST("vtol_block::get_boundary_cycle() is not null", b1->get_boundary_cycle()?true:false, true);
77   TEST("vtol_block::get_boundary_cycle() is not null", b1_copy->get_boundary_cycle()?true:false, true);
78   TEST("vtol_block::get_boundary_cycle()", *(b1->get_boundary_cycle()), *(b1_copy->get_boundary_cycle()));
79 
80   two_chain_list tc_list;
81   tc_list.push_back(tc2);
82   tc_list.push_back(tc1);
83 
84   vtol_block_sptr b2 = new vtol_block(tc_list);
85 
86   TEST("vtol_block inequality", *b2 == *b1, false);
87   TEST("vtol_block::get_boundary_cycle()", *(b2->get_boundary_cycle()), *tc2);
88 
89   vertex_list verts; b2->vertices(verts);
90   TEST("vtol_block::vertices()", verts.size(), 8);
91 
92   vtol_block_sptr b2_copy = new vtol_block(b2);
93   TEST("vtol_block deep copy (pseudo copy constructor)", *b2, *b2_copy);
94 
95   vsol_spatial_object_2d_sptr b2_clone = b2->clone();
96   TEST("vtol_block::clone()", *b2, *b2_clone);
97 
98   TEST("vtol_block::cast_to_block()", b2->cast_to_block()==nullptr, false);
99   TEST("vtol_block::valid_inferior_type()",b1->valid_inferior_type(tc1),true);
100   TEST("vtol_block::valid_superior_type()",b1->valid_superior_type(b1->cast_to_topology_object()),false);
101   TEST("vtol_two_chain::valid_superior_type()",tc1->valid_superior_type(b1),true);
102 
103   vertex_list *v_list = b1->outside_boundary_vertices();
104   TEST("vtol_block::outside_boundary_vertices()", v_list->size(), 8);
105   delete v_list;
106 
107   zero_chain_list *z_list = b1->outside_boundary_zero_chains();
108   TEST("vtol_block::outside_boundary_zero_chains()", z_list->size(), 16);
109   delete z_list;
110 
111   edge_list *ed_list = b1->outside_boundary_edges();
112   TEST("vtol_block::outside_boundary_edges()", ed_list->size(), 8);
113   delete ed_list;
114 
115   one_chain_list *o_list = b1->outside_boundary_one_chains();
116   TEST("vtol_block::outside_boundary_one_chains()", o_list->size(), 2);
117   delete o_list;
118 
119   face_list *f_list = b1->outside_boundary_faces();
120   TEST("vtol_block::outside_boundary_faces()", f_list->size(), 2);
121   delete f_list;
122 
123   two_chain_list *t_list = b1->outside_boundary_two_chains();
124   TEST("vtol_block::outside_boundary_two_chains()", t_list->size(), 1);
125   delete t_list;
126 }
127 
128 TESTMAIN(test_block);
129