File: test_matrix.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 (29 lines) | stat: -rw-r--r-- 939 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
22
23
24
25
26
27
28
29
#include <catch2/catch_all.hpp>
#include <libtcod/matrix.hpp>

TEST_CASE("Matrix basics") {
  auto matrix = tcod::Matrix<int, 2>({2, 2});
  REQUIRE(matrix.get_shape() == std::array<int, 2>{2, 2});
  REQUIRE(matrix.at({0, 0}) == 0);  // Matrix is zero-initialized.
  REQUIRE(matrix.in_bounds({0, 0}));
  matrix[{0, 0}] = 1;
  matrix.at({1, 0}) = 2;
  matrix.at({0, 1}) = 3;
  matrix.at({1, 1}) = 4;
  REQUIRE(matrix.get_container() == std::vector<int>{1, 2, 3, 4});
  {
    auto view = tcod::MatrixView<int, 2>{matrix};
    REQUIRE(view[{0, 0}] == 1);
    REQUIRE(view.at({1, 0}) == 2);
    REQUIRE(view.at({0, 1}) == 3);
    REQUIRE(view.at({1, 1}) == 4);
  }
  const auto const_matrix = tcod::Matrix<int, 2>({2, 2}, 7);
  REQUIRE(const_matrix.at({1, 1}) == 7);
  REQUIRE(const_matrix[{1, 1}] == 7);
  {
    auto view = tcod::MatrixView<const int, 2>{const_matrix};
    REQUIRE(view[{1, 1}] == 7);
    REQUIRE(view.at({1, 1}) == 7);
  }
}