File: bipartitions.cpp

package info (click to toggle)
terraphast 0.0%2Bgit20200413.8af2e4c%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 792 kB
  • sloc: cpp: 5,923; sh: 83; ansic: 55; makefile: 25
file content (48 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download | duplicates (3)
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
#include <catch.hpp>

#include <iostream>

#include "../lib/bipartitions.hpp"
#include "../lib/ranked_bitvector.hpp"
#include "../lib/union_find.hpp"

namespace terraces {
namespace tests {

TEST_CASE("bipartition1", "[bipartition]") {
	auto fl = utils::free_list{};
	auto alloc = utils::stack_allocator<index_t>{fl, 4};
	union_find u(4, alloc);
	ranked_bitvector s{4, alloc};
	s.set(0);
	s.set(1);
	s.set(2);
	s.set(3);
	s.update_ranks();
	u.merge(0, 1);
	u.compress();
	bipartitions bip_it(s, u, alloc);
	CHECK(bip_it.end_bip() == 4);
	CHECK(bip_it.num_bip() == 3);
	CHECK(bip_it.begin_bip() == 1);
	auto set = bip_it.get_first_set(1, alloc);
	CHECK(!set.get(0));
	CHECK(!set.get(1));
	CHECK(set.get(2));
	CHECK(!set.get(3));
	set = bip_it.get_first_set(2, alloc);
	CHECK(!set.get(0));
	CHECK(!set.get(1));
	CHECK(!set.get(2));
	CHECK(set.get(3));
	set = bip_it.get_first_set(3, alloc);
	CHECK(!set.get(0));
	CHECK(!set.get(1));
	CHECK(set.get(2));
	CHECK(set.get(3));
	CHECK(bip_it.end_bip() == 4);
	CHECK(bip_it.num_bip() == 3);
}

} // namespace tests
} // namespace terraces