diff --git a/include/mata/utils/partition.hh b/include/mata/utils/partition.hh index f6193615f..4a77ff5ac 100644 --- a/include/mata/utils/partition.hh +++ b/include/mata/utils/partition.hh @@ -301,6 +301,8 @@ class Partition { } const Node& node(void) const { return block().node(); } const BlockItem& repr(void) const { return node().repr(); } + const BlockItem& first(void) const { return node().first(); } + const BlockItem& last(void) const { return node().last(); } }; /** @@ -430,6 +432,12 @@ class Partition { size_t size(void) const { return last().idx() - first().idx() + 1; } + + bool contains_block(size_t block_idx) const { + const Block& block = partition_.get_block(block_idx); + return first_ <= block.first().idx() && + last_ >= block.last().idx(); + } }; public: diff --git a/tests/partition.cc b/tests/partition.cc index df63be8f2..1f53b6f8e 100644 --- a/tests/partition.cc +++ b/tests/partition.cc @@ -23,6 +23,8 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.get_block_idx(i) == 0); CHECK(p.get_block_item(i).node().idx() == 0); CHECK(p.get_block_item(i).repr().idx() == 0); + CHECK(p.get_block_item(i).first().idx() == 0); + CHECK(p.get_block_item(i).last().idx() == 9); CHECK(p.get_block_item(i).node().first().idx() == 0); CHECK(p.get_block_item(i).node().last().idx() == 9); CHECK(p[i].idx() == i); @@ -30,11 +32,14 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.get_block(0).idx() == 0); CHECK(p.get_block(0).node().idx() == 0); CHECK(p.get_block(0).repr().idx() == 0); + CHECK(p.get_block(0).first().idx() == 0); + CHECK(p.get_block(0).last().idx() == 9); CHECK(p.get_block(0).size() == 10); CHECK(p.get_node(0).idx() == 0); CHECK(p.get_node(0).first().idx() == 0); CHECK(p.get_node(0).last().idx() == 9); CHECK(p.get_node(0).size() == 10); + CHECK(p.get_node(0).contains_block(0)); for(auto& block_item : p.get_block(0)) { CHECK(block_item.block().idx() == 0); } @@ -62,6 +67,8 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.get_block_item(i).block().idx() == 0); CHECK(p.get_block_item(i).node().idx() == 0); CHECK(p.get_block_item(i).repr().idx() == 0); + CHECK(p.get_block_item(i).first().idx() == 0); + CHECK(p.get_block_item(i).last().idx() == 9); CHECK(p.get_block_item(i).node().first().idx() == 0); CHECK(p.get_block_item(i).node().last().idx() == 9); CHECK(p[i].idx() == i); @@ -69,11 +76,14 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.get_block(0).idx() == 0); CHECK(p.get_block(0).node().idx() == 0); CHECK(p.get_block(0).repr().idx() == 0); + CHECK(p.get_block(0).first().idx() == 0); + CHECK(p.get_block(0).last().idx() == 9); CHECK(p.get_block(0).size() == 10); CHECK(p.get_node(0).idx() == 0); CHECK(p.get_node(0).first().idx() == 0); CHECK(p.get_node(0).last().idx() == 9); CHECK(p.get_node(0).size() == 10); + CHECK(p.get_node(0).contains_block(0)); for(auto& block_item : p.get_block(0)) { CHECK(block_item.block().idx() == 0); } @@ -103,8 +113,14 @@ TEST_CASE("mata::utils::Partition") { CHECK(p[0].block().idx() == 0); CHECK(p[0].node().idx() == 0); CHECK(p.get_block_item(0).node().idx() == 0); + CHECK(p.get_block_item(0).repr().idx() == 0); + CHECK(p.get_block_item(0).first().idx() == 0); + CHECK(p.get_block_item(0).last().idx() == 2); CHECK(p[1].idx() == 3); CHECK(p.get_block_item(3).state() == 1); + CHECK(p.get_block_item(3).repr().state() == 1); + CHECK(p.get_block_item(3).first().state() == 1); + CHECK(p.get_block_item(3).last().state() == 9); CHECK(p[1].block().idx() == 1); CHECK(p[1].node().idx() == 1); CHECK(p.get_block_item(3).block().idx() == 1); @@ -117,12 +133,16 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.get_block(1).size() == 7); CHECK(p.get_node(0).repr().state() == 0); CHECK(p.get_node(0).repr().block().idx() == 0); + CHECK(p.get_node(0).contains_block(0)); + CHECK(!p.get_node(0).contains_block(1)); CHECK(p.get_node(1).repr().state() == 1); CHECK(p.get_node(1).repr().block().idx() == 1); CHECK(p.get_node(0).first().idx() == 0); CHECK(p.get_node(0).last().idx() == 2); CHECK(p.get_node(1).first().idx() == 3); CHECK(p.get_node(1).last().idx() == 9); + CHECK(!p.get_node(1).contains_block(0)); + CHECK(p.get_node(1).contains_block(1)); CHECK(p.get_block(0).node().idx() == 0); CHECK(p.get_block(1).node().idx() == 1); CHECK(p.states_in_same_block(0).size() == 3); @@ -150,11 +170,17 @@ TEST_CASE("mata::utils::Partition") { CHECK(p[0].block().idx() == 0); CHECK(p[0].node().idx() == 0); CHECK(p.get_block_item(0).block().idx() == 0); + CHECK(p.get_block_item(0).repr().idx() == 0); + CHECK(p.get_block_item(0).first().idx() == 0); + CHECK(p.get_block_item(0).last().idx() == 0); CHECK(p.get_block(0).node().idx() == 0); CHECK(p[1].block().idx() == 1); CHECK(p[1].node().idx() == 1); CHECK(p.get_block_item(1).block().idx() == 1); CHECK(p.get_block_item(1).node().idx() == 1); + CHECK(p.get_block_item(1).repr().idx() == 1); + CHECK(p.get_block_item(1).first().idx() == 1); + CHECK(p.get_block_item(1).last().idx() == 2); CHECK(p.get_block(0).repr().state() == 0); CHECK(p.get_block(1).repr().state() == 1); CHECK(p.get_block(2).repr().state() == 3); @@ -166,13 +192,25 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.get_node(1).first().idx() == 1); CHECK(p.get_node(1).last().idx() == 2); CHECK(p.get_node(2).first().idx() == 3); - CHECK(p.get_node(2).last().idx() == 5); + CHECK(p.get_node(2).last().idx() == 5); + CHECK(p.get_node(0).contains_block(0)); + CHECK(!p.get_node(0).contains_block(1)); + CHECK(!p.get_node(0).contains_block(2)); + CHECK(!p.get_node(1).contains_block(0)); + CHECK(p.get_node(1).contains_block(1)); + CHECK(!p.get_node(1).contains_block(2)); + CHECK(!p.get_node(2).contains_block(0)); + CHECK(!p.get_node(2).contains_block(1)); + CHECK(p.get_node(2).contains_block(2)); CHECK(p.get_block(0).node().idx() == 0); CHECK(p.get_block(1).node().idx() == 1); CHECK(p.get_block(2).node().idx() == 2); CHECK(p.get_block(0).size() == 1); CHECK(p.get_block(1).size() == 2); CHECK(p.get_block(2).size() == 3); + CHECK(p.get_block_item(3).repr().idx() == 3); + CHECK(p.get_block_item(3).first().idx() == 3); + CHECK(p.get_block_item(3).last().idx() == 5); CHECK(p.states_in_same_block(0).size() == 1); CHECK(p.states_in_same_block(1).size() == 2); CHECK(p.states_in_same_block(3).size() == 3); @@ -191,6 +229,7 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.states_in_same_block(0).size() == 10); CHECK(p.partition().size() == 1); CHECK(p.get_block(0).size() == 10); + CHECK(p.get_node(0).contains_block(0)); p.split_blocks({0, 1, 2, 3, 4}); CHECK(p.num_of_states() == 10); CHECK(p.num_of_block_items() == 10); @@ -205,6 +244,12 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.partition().size() == 2); CHECK(p.get_block(0).size() == 5); CHECK(p.get_block(1).size() == 5); + CHECK(p.get_node(0).contains_block(0)); + CHECK(p.get_node(0).contains_block(1)); + CHECK(p.get_node(1).contains_block(0)); + CHECK(!p.get_node(1).contains_block(1)); + CHECK(!p.get_node(2).contains_block(0)); + CHECK(p.get_node(2).contains_block(1)); p.split_blocks({0, 1, 2, 5, 6, 7}); CHECK(p.num_of_states() == 10); CHECK(p.num_of_block_items() == 10); @@ -221,6 +266,34 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.states_in_same_block(5).size() == 3); CHECK(p.states_in_same_block(8).size() == 2); CHECK(p.partition().size() == 4); + CHECK(p.get_node(0).contains_block(0)); + CHECK(p.get_node(0).contains_block(1)); + CHECK(p.get_node(0).contains_block(2)); + CHECK(p.get_node(0).contains_block(3)); + CHECK(p.get_node(1).contains_block(0)); + CHECK(!p.get_node(1).contains_block(1)); + CHECK(p.get_node(1).contains_block(2)); + CHECK(!p.get_node(1).contains_block(3)); + CHECK(!p.get_node(2).contains_block(0)); + CHECK(p.get_node(2).contains_block(1)); + CHECK(!p.get_node(2).contains_block(2)); + CHECK(p.get_node(2).contains_block(3)); + CHECK(p.get_node(3).contains_block(0)); + CHECK(!p.get_node(3).contains_block(1)); + CHECK(!p.get_node(3).contains_block(2)); + CHECK(!p.get_node(3).contains_block(3)); + CHECK(!p.get_node(4).contains_block(0)); + CHECK(!p.get_node(4).contains_block(1)); + CHECK(p.get_node(4).contains_block(2)); + CHECK(!p.get_node(4).contains_block(3)); + CHECK(!p.get_node(5).contains_block(0)); + CHECK(p.get_node(5).contains_block(1)); + CHECK(!p.get_node(5).contains_block(2)); + CHECK(!p.get_node(5).contains_block(3)); + CHECK(!p.get_node(6).contains_block(0)); + CHECK(!p.get_node(6).contains_block(1)); + CHECK(!p.get_node(6).contains_block(2)); + CHECK(p.get_node(6).contains_block(3)); p.split_blocks({0, 3, 5, 8}); CHECK(p.num_of_states() == 10); CHECK(p.num_of_block_items() == 10); @@ -370,11 +443,17 @@ TEST_CASE("mata::utils::Partition") { CHECK(p[0].block().idx() == 0); CHECK(p[0].node().idx() == 0); CHECK(p.get_block_item(0).block().idx() == 0); + CHECK(p.get_block_item(0).repr().idx() == 0); + CHECK(p.get_block_item(0).first().idx() == 0); + CHECK(p.get_block_item(0).last().idx() == 0); CHECK(p.get_block(0).node().idx() == 0); CHECK(p[1].block().idx() == 1); CHECK(p[1].node().idx() == 1); CHECK(p.get_block_item(1).block().idx() == 1); CHECK(p.get_block_item(1).node().idx() == 1); + CHECK(p.get_block_item(1).repr().idx() == 1); + CHECK(p.get_block_item(1).first().idx() == 1); + CHECK(p.get_block_item(1).last().idx() == 2); CHECK(p.get_block(0).repr().state() == 0); CHECK(p.get_block(1).repr().state() == 1); CHECK(p.get_block(2).repr().state() == 3); @@ -390,6 +469,9 @@ TEST_CASE("mata::utils::Partition") { CHECK(p.get_block(0).node().idx() == 0); CHECK(p.get_block(1).node().idx() == 1); CHECK(p.get_block(2).node().idx() == 2); + CHECK(p.get_block_item(3).repr().idx() == 3); + CHECK(p.get_block_item(3).first().idx() == 3); + CHECK(p.get_block_item(3).last().idx() == 5); CHECK(p.states_in_same_block(0).size() == 1); CHECK(p.states_in_same_block(1).size() == 2); CHECK(p.states_in_same_block(3).size() == 3);