internal-tests-types.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include "catch.h"
5 #include <cmath>
6 #include <iostream>
7 #include <chrono>
8 #include <ctime>
9 #include <algorithm>
10 #include <type_traits>
11 #include <librealsense2/rs.hpp>
13 #include "../../common/tiny-profiler.h"
14 #include "./../src/environment.h"
15 
16 using namespace librealsense;
17 using namespace librealsense::platform;
18 
19 TEST_CASE("copy_array", "[code]")
20 {
21  size_t elem = 0;
22  float src_float[] = { 1.1f, 2.2f, 3.3f, -5.5f, 0.f, 123534.f };
23  double src_double[] = { 0.00000000000000000001, -2222222222222222222222222.222222, 334529087543.30875246784, -5.51234533524532345254645234256, 5888985940.4535, -0.0000000000001 };
24 
25  const size_t src_size = 6;
26 
27  float tgt_float[src_size] = { 0 };
28  double tgt_double[src_size] = { 0 };
29 
30  // Check that precision is preserved when using identical or a larger data type
31  elem = librealsense::copy_array(tgt_float, src_float);
32  REQUIRE(elem == src_size);
33  elem = librealsense::copy_array(tgt_double, src_float);
34  REQUIRE(elem == src_size);
35 
36  // Check that precision is preserved when expanding o using similar data types
37  for (size_t i = 0; i < src_size; ++i)
38  {
39  CAPTURE(src_double[i]);
40  CAPTURE(tgt_float[i]);
41  CAPTURE(tgt_double[i]);
42  REQUIRE(src_float[i] == (tgt_float[i]));
43  REQUIRE(src_float[i] == (tgt_double[i]));
44  }
45 
46  // Check that precision is lost when narrowing data type
47  memset(&tgt_float, 0, sizeof(float)*src_size);
48  elem = librealsense::copy_array<true>(tgt_float, src_double);
49  REQUIRE(elem == src_size);
50 
51  for (size_t i = 0; i < src_size; ++i)
52  {
53  CAPTURE(src_double[i]);
54  CAPTURE(tgt_float[i]);
55  REQUIRE(src_double[i] != tgt_float[i]);
56  }
57 }
58 
59 TEST_CASE("copy_2darray", "[code]")
60 {
61  size_t elem = 0;
62  float src_float[2][6] = { { 1.1f, 2.2f, 3.3f, -5.5f, 0.f, 123534.f },
63  { 764.07f, -2342.2f, 2453.653f, -445.215f, 0.11324f, 1224.8209f } };
64  double src_double[2][6] = { { -254354352341.1, 765732052.21124, 3.4432007654764633233554, -524432.5432650645, 0.0000000000000000112, 123534.4234254673 },
65  { 764.07654343263, -242675463465342.243, -9876322453.6342453, -42315432545.2153542, 0.1345521543251324, -0.0000123413242329 } };
66 
67  const size_t src_size = arr_size(src_float);
68 
69  // Get the internal dimension sizes
72 
73  float tgt_float[2][6] = { 0 };
74  double tgt_double[2][6] = { 0 };
75 
76  // Check that precision is preserved when using identical or a larger data type
77  elem = librealsense::copy_2darray(tgt_float, src_float);
78  REQUIRE(elem == src_size);
79  elem = librealsense::copy_2darray(tgt_double, src_float);
80  REQUIRE(elem == src_size);
81 
82  for (size_t i = 0; i < h; ++i)
83  for (size_t j = 0; j < w; ++j)
84  {
85  CAPTURE(src_float[i][j]);
86  CAPTURE(tgt_float[i][j]);
87  CAPTURE(tgt_double[i][j]);
88  REQUIRE(src_float[i][j] == (tgt_float[i][j]));
89  REQUIRE(src_float[i][j] == (tgt_double[i][j]));
90  }
91 
92  // Check that precision is lost when narrowing data type
93  memset(&tgt_float, 0, sizeof(float)*src_size);
94  elem = librealsense::copy_2darray<true>(tgt_float, src_double);
95  REQUIRE(elem == src_size);
96 
97  for (size_t i = 0; i < h; ++i)
98  for (size_t j = 0; j < w; ++j)
99  {
100  CAPTURE(src_double[i][j]);
101  CAPTURE(tgt_float[i][j]);
102  REQUIRE(src_double[i][j] != tgt_float[i][j]);
103  }
104 }
GLfloat value
GLdouble GLdouble GLdouble w
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1960
constexpr size_t arr_size(T const &)
Definition: src/types.h:105
TEST_CASE("copy_array","[code]")
#define CAPTURE(...)
Definition: catch.hpp:17432
REQUIRE(n_callbacks==1)
GLint j
size_t copy_2darray(T(&dst)[tgt_m][tgt_n], const S(&src)[src_m][src_n])
Definition: src/types.h:151
size_t copy_array(T(&dst)[size_tgt], const S(&src)[size_src])
Definition: src/types.h:133
int i


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:17