25 #include <boost/test/unit_test.hpp> 29 BOOST_AUTO_TEST_SUITE(ts_UnionFind)
34 BOOST_CHECK_EQUAL(uf.
size(), 5);
35 BOOST_CHECK_EQUAL(uf.
find(0), 0);
36 BOOST_CHECK_EQUAL(uf.
find(1), 1);
37 BOOST_CHECK_EQUAL(uf.
find(2), 2);
38 BOOST_CHECK_EQUAL(uf.
find(3), 3);
39 BOOST_CHECK_EQUAL(uf.
find(4), 4);
43 BOOST_CHECK_EQUAL(uf.
find(0), 0);
44 BOOST_CHECK_EQUAL(uf.
find(1), 0);
45 BOOST_CHECK_EQUAL(uf.
find(2), 2);
46 BOOST_CHECK_EQUAL(uf.
find(3), 2);
47 BOOST_CHECK_EQUAL(uf.
find(4), 4);
50 BOOST_CHECK_EQUAL(uf.
find(0), 0);
51 BOOST_CHECK_EQUAL(uf.
find(1), 0);
52 BOOST_CHECK_EQUAL(uf.
find(2), 2);
53 BOOST_CHECK_EQUAL(uf.
find(3), 2);
54 BOOST_CHECK_EQUAL(uf.
find(4), 2);
60 uf_forward.
merge(0, 3);
61 BOOST_CHECK_EQUAL(uf_forward.
find(0), 0);
62 BOOST_CHECK_EQUAL(uf_forward.
find(1), 0);
63 BOOST_CHECK_EQUAL(uf_forward.
find(2), 0);
64 BOOST_CHECK_EQUAL(uf_forward.
find(3), 0);
65 BOOST_CHECK_EQUAL(uf_forward.
find(4), 0);
67 uf_backward.
merge(3, 0);
68 BOOST_CHECK_EQUAL(uf_backward.
find(0), 2);
69 BOOST_CHECK_EQUAL(uf_backward.
find(1), 2);
70 BOOST_CHECK_EQUAL(uf_backward.
find(2), 2);
71 BOOST_CHECK_EQUAL(uf_backward.
find(3), 2);
72 BOOST_CHECK_EQUAL(uf_backward.
find(4), 2);
77 BOOST_CHECK_EQUAL(uf.
size(), 7);
78 BOOST_CHECK_EQUAL(uf.
find(0), 0);
79 BOOST_CHECK_EQUAL(uf.
find(1), 0);
80 BOOST_CHECK_EQUAL(uf.
find(2), 2);
81 BOOST_CHECK_EQUAL(uf.
find(3), 2);
82 BOOST_CHECK_EQUAL(uf.
find(4), 2);
83 BOOST_CHECK_EQUAL(uf.
find(5), 5);
84 BOOST_CHECK_EQUAL(uf.
find(6), 6);
89 BOOST_CHECK_EQUAL(uf.
find(0), 0);
90 BOOST_CHECK_EQUAL(uf.
find(1), 0);
91 BOOST_CHECK_EQUAL(uf.
find(2), 2);
92 BOOST_CHECK_EQUAL(uf.
find(3), 2);
93 BOOST_CHECK_EQUAL(uf.
find(4), 2);
94 BOOST_CHECK_EQUAL(uf.
find(5), 2);
95 BOOST_CHECK_EQUAL(uf.
find(6), 2);
98 BOOST_CHECK_EQUAL(uf.
find(0), 2);
99 BOOST_CHECK_EQUAL(uf.
find(1), 2);
100 BOOST_CHECK_EQUAL(uf.
find(2), 2);
101 BOOST_CHECK_EQUAL(uf.
find(3), 2);
102 BOOST_CHECK_EQUAL(uf.
find(4), 2);
103 BOOST_CHECK_EQUAL(uf.
find(5), 2);
104 BOOST_CHECK_EQUAL(uf.
find(6), 2);
107 BOOST_AUTO_TEST_SUITE_END()
void merge(std::size_t x, std::size_t y)
std::size_t find(std::size_t x)
void grow(const std::size_t n=1)
Enlarges the data structure by n elements.
BOOST_AUTO_TEST_CASE(UnionFindTest)