File: Test_type_traits.cpp

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (28 lines) | stat: -rw-r--r-- 906 bytes parent folder | download
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
#include "Test.h"

#include "pymol/type_traits.h"

TEST_CASE("reshape", "[type_traits]")
{
  float flat[] = {1.f, 2.f, 3.f, 4.f, 5.f, 6.f};
  auto shaped = pymol::reshape<3>(flat);
  static_assert(std::is_same<decltype(shaped), float(*)[3]>::value, "");

  typedef float f3array[3];
  f3array* foo = shaped;
  static_assert(std::is_same<decltype(shaped), decltype(foo)>::value, "");

  REQUIRE(std::equal(shaped[0], shaped[0] + 3, flat + 0));
  REQUIRE(std::equal(shaped[1], shaped[1] + 3, flat + 3));
}

TEST_CASE("flatten", "[type_traits]")
{
  float shaped[2][3] = {{1.f, 2.f, 3.f}, {4.f, 5.f, 6.f}};
  const float* flat = pymol::flatten(shaped);
  REQUIRE(std::equal(shaped[0], shaped[0] + 3, flat + 0));
  REQUIRE(std::equal(shaped[1], shaped[1] + 3, flat + 3));
  auto* shaped_ptr = shaped;
  float* flat_from_ptr = pymol::flatten(shaped_ptr);
  REQUIRE(std::equal(flat, flat + 6, flat_from_ptr));
}