Cheetah Software  1.0
test_utilities.cpp File Reference

Test Utilities functions. More...

#include "Math/MathUtilities.h"
#include "Utilities/utilities.h"
#include "cppTypes.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string>
#include <unordered_map>
#include "include/Utilities/Utilities_print.h"
+ Include dependency graph for test_utilities.cpp:

Go to the source code of this file.

Functions

 TEST (Utilities, strintToVec3)
 
 TEST (Utilities, coerce)
 
 TEST (Utilities, sgn)
 
 TEST (Utilities, uMapContains)
 
 TEST (Utilities, mapContains)
 
 TEST (Utilities, mapToRange)
 
 TEST (Utilities, colorPrint)
 

Detailed Description

Test Utilities functions.

Test the various utilities

Definition in file test_utilities.cpp.

Function Documentation

TEST ( Utilities  ,
strintToVec3   
)

Definition at line 18 of file test_utilities.cpp.

References almostEqual().

18  {
19  std::vector<std::string> strings = {"[1.1, 2.2, 3.3]",
20  " [ 1.1 , 2.2 ,3.3 ] ",
21  "[1.1,2.2 ,3.3]", "[1.1, 2.2, 3.3]"};
22 
23  Vec3<double> ref(1.1, 2.2, 3.3);
24  Vec3<double> v1 = stringToVec3<double>("[1.1,2.2,3.3]");
25 
26  EXPECT_TRUE(almostEqual(ref, v1, .0000001));
27 
28  for (auto& str : strings) {
29  Vec3<double> vv = stringToVec3<double>(str);
30  EXPECT_TRUE(almostEqual(ref, vv, .0000001));
31  }
32 }
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
bool almostEqual(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b, T2 tol)
Definition: MathUtilities.h:23

+ Here is the call graph for this function:

TEST ( Utilities  ,
coerce   
)

Test the coerce function

Definition at line 37 of file test_utilities.cpp.

References f().

37  {
38  EXPECT_EQ(0.1f, coerce<float>(0.5f, 0.f, 0.1f));
39  EXPECT_EQ(-0.1f, coerce<float>(-0.5f, -0.1f, 0.1f));
40  EXPECT_EQ(0.5f, coerce<float>(0.5f, -1.f, 1.f));
41 }
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

TEST ( Utilities  ,
sgn   
)

Definition at line 43 of file test_utilities.cpp.

43  {
44  EXPECT_EQ(1, sgn<int>(10));
45  EXPECT_EQ(-1, sgn<int>(-10));
46  EXPECT_EQ(0, sgn<int>(0));
47 
48  EXPECT_EQ(1, sgn<double>(13.23));
49  EXPECT_EQ(-1, sgn<double>(-.23));
50  EXPECT_EQ(0, sgn<double>(0.));
51 }
TEST ( Utilities  ,
uMapContains   
)

Definition at line 53 of file test_utilities.cpp.

References uMapContains().

53  {
54  std::unordered_map<std::string, int> s;
55  EXPECT_FALSE(uMapContains(s, std::string("test")));
56  s["test"] = 2;
57  EXPECT_TRUE(uMapContains(s, std::string("test")));
58 }
bool uMapContains(const std::unordered_map< T1, T2 > &set, T1 key)
Definition: utilities.h:112

+ Here is the call graph for this function:

TEST ( Utilities  ,
mapContains   
)

Definition at line 60 of file test_utilities.cpp.

References mapContains().

60  {
61  std::map<std::string, int> s;
62  EXPECT_FALSE(mapContains(s, std::string("test")));
63  s["test"] = 2;
64  EXPECT_TRUE(mapContains(s, std::string("test")));
65 }
bool mapContains(const std::map< T1, T2 > &set, T1 key)
Definition: utilities.h:120

+ Here is the call graph for this function:

TEST ( Utilities  ,
mapToRange   
)

Definition at line 67 of file test_utilities.cpp.

References fpEqual(), and mapToRange().

67  {
68  EXPECT_TRUE(fpEqual(2.0, mapToRange(0.4, 0.2, 1.2, 0.0, 10.0), .00001));
69 }
bool fpEqual(T a, T b, T tol)
Definition: utilities.h:15
T mapToRange(T x, T inputMin, T inputMax, T outputMin, T outputMax)
Definition: utilities.h:142

+ Here is the call graph for this function:

TEST ( Utilities  ,
colorPrint   
)

Definition at line 71 of file test_utilities.cpp.

References Blue, Cyan, Default, Green, Magenta, printf_color(), Red, and Yellow.

71  {
72  printf_color(PrintColor::Default, "default\n");
73  printf_color(PrintColor::Red, "red\n");
74  printf_color(PrintColor::Green, "green\n");
75  printf_color(PrintColor::Blue, "blue\n");
76  printf_color(PrintColor::Yellow, "yellow\n");
77  printf_color(PrintColor::Magenta, "magenta\n");
78  printf_color(PrintColor::Cyan, "cyan\n");
79  printf_color(PrintColor::Default, "default!\n");

+ Here is the call graph for this function: