File: Test_type_traits.cpp

package info (click to toggle)
pymol 2.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 43,312 kB
  • sloc: cpp: 480,106; python: 79,860; ansic: 28,343; javascript: 6,792; sh: 47; makefile: 30; csh: 8
file content (28 lines) | stat: -rw-r--r-- 916 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
#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(pymol::equal(shaped[0], shaped[0] + 3, flat + 0));
  REQUIRE(pymol::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(pymol::equal(shaped[0], shaped[0] + 3, flat + 0));
  REQUIRE(pymol::equal(shaped[1], shaped[1] + 3, flat + 3));
  auto* shaped_ptr = shaped;
  float* flat_from_ptr = pymol::flatten(shaped_ptr);
  REQUIRE(pymol::equal(flat, flat + 6, flat_from_ptr));
}