MCPcopy Create free account
hub / github.com/davisking/dlib / test_linpiece

Function test_linpiece

dlib/test/matrix4.cpp:1055–1101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1053 }
1054
1055 void test_linpiece()
1056 {
1057 matrix<double,0,1> temp = linpiece(5, linspace(-1, 9, 2));
1058 DLIB_CASSERT(temp.size() == 1,"");
1059 DLIB_CASSERT(std::abs(temp(0) - 6) < 1e-13,"");
1060
1061 temp = linpiece(5, linspace(-1, 9, 6));
1062 DLIB_CASSERT(temp.size() == 5,"");
1063 DLIB_CASSERT(std::abs(temp(0) - 2) < 1e-13,"");
1064 DLIB_CASSERT(std::abs(temp(1) - 2) < 1e-13,"");
1065 DLIB_CASSERT(std::abs(temp(2) - 2) < 1e-13,"");
1066 DLIB_CASSERT(std::abs(temp(3) - 0) < 1e-13,"");
1067 DLIB_CASSERT(std::abs(temp(4) - 0) < 1e-13,"");
1068
1069 temp = linpiece(4, linspace(-1, 9, 6));
1070 DLIB_CASSERT(temp.size() == 5,"");
1071 DLIB_CASSERT(std::abs(temp(0) - 2) < 1e-13,"");
1072 DLIB_CASSERT(std::abs(temp(1) - 2) < 1e-13,"");
1073 DLIB_CASSERT(std::abs(temp(2) - 1) < 1e-13,"");
1074 DLIB_CASSERT(std::abs(temp(3) - 0) < 1e-13,"");
1075 DLIB_CASSERT(std::abs(temp(4) - 0) < 1e-13,"");
1076
1077 temp = linpiece(40, linspace(-1, 9, 6));
1078 DLIB_CASSERT(temp.size() == 5,"");
1079 DLIB_CASSERT(std::abs(temp(0) - 2) < 1e-13,"");
1080 DLIB_CASSERT(std::abs(temp(1) - 2) < 1e-13,"");
1081 DLIB_CASSERT(std::abs(temp(2) - 2) < 1e-13,"");
1082 DLIB_CASSERT(std::abs(temp(3) - 2) < 1e-13,"");
1083 DLIB_CASSERT(std::abs(temp(4) - 2) < 1e-13,"");
1084
1085 temp = linpiece(-40, linspace(-1, 9, 6));
1086 DLIB_CASSERT(temp.size() == 5,"");
1087 DLIB_CASSERT(std::abs(temp(0) - 0) < 1e-13,"");
1088 DLIB_CASSERT(std::abs(temp(1) - 0) < 1e-13,"");
1089 DLIB_CASSERT(std::abs(temp(2) - 0) < 1e-13,"");
1090 DLIB_CASSERT(std::abs(temp(3) - 0) < 1e-13,"");
1091 DLIB_CASSERT(std::abs(temp(4) - 0) < 1e-13,"");
1092
1093 temp = linpiece(0, linspace(-1, 9, 6));
1094 DLIB_CASSERT(temp.size() == 5,"");
1095 DLIB_CASSERT(std::abs(temp(0) - 1) < 1e-13,"");
1096 DLIB_CASSERT(std::abs(temp(1) - 0) < 1e-13,"");
1097 DLIB_CASSERT(std::abs(temp(2) - 0) < 1e-13,"");
1098 DLIB_CASSERT(std::abs(temp(3) - 0) < 1e-13,"");
1099 DLIB_CASSERT(std::abs(temp(4) - 0) < 1e-13,"");
1100
1101 }
1102
1103 class matrix_tester : public tester
1104 {

Callers 1

perform_testMethod · 0.85

Calls 4

linpieceFunction · 0.85
linspaceFunction · 0.85
absFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected