File: test_bsp.cpp

package info (click to toggle)
libtcod 1.24.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,728 kB
  • sloc: ansic: 46,186; cpp: 13,523; python: 4,814; makefile: 44; sh: 25
file content (21 lines) | stat: -rw-r--r-- 829 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#include <catch2/catch_all.hpp>
#include <libtcod/bsp.hpp>

TEST_CASE("BSP traversal") {
  auto root = TCODBsp{};
  root.splitOnce(0, 0);
  root.getLeft()->splitOnce(0, 0);

  auto pre_order = std::vector<TCODBsp*>{};
  REQUIRE(root.traversePreOrder([&](TCODBsp& node) { pre_order.push_back(&node); }));
  REQUIRE(pre_order.at(0) == &root);
  REQUIRE(pre_order.at(1) == root.getLeft());
  REQUIRE(pre_order.at(2) == root.getLeft()->getLeft());
  REQUIRE(pre_order.at(3) == root.getLeft()->getRight());
  REQUIRE(pre_order.at(4) == root.getRight());
  REQUIRE(root.traverseInOrder([&](TCODBsp&) { return true; }));
  REQUIRE(root.traversePostOrder([&](TCODBsp&) { return true; }));
  REQUIRE(root.traverseLevelOrder([&](TCODBsp&) { return true; }));
  REQUIRE(root.traverseInvertedLevelOrder([&](TCODBsp&) { return true; }));
};