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

Function test_call_if_valid

dlib/test/metaprogramming.cpp:74–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72
73
74 void test_call_if_valid()
75 {
76 int value = 0;
77
78 auto foo = [&](int a, int b) { value += a + b; };
79 auto bar = [&](std::string) { value++; };
80 auto baz = [&]() { value++; };
81
82 DLIB_TEST(value == 0);
83 DLIB_TEST(call_if_valid(baz));
84 DLIB_TEST(value == 1);
85 DLIB_TEST(!call_if_valid(foo));
86 DLIB_TEST(value == 1);
87 DLIB_TEST(!call_if_valid(bar));
88 DLIB_TEST(value == 1);
89 DLIB_TEST(call_if_valid(bar, "stuff"));
90 DLIB_TEST(value == 2);
91 DLIB_TEST(!call_if_valid(baz, "stuff"));
92 DLIB_TEST(value == 2);
93 DLIB_TEST(call_if_valid(foo, 3, 1));
94 DLIB_TEST(value == 6);
95 DLIB_TEST(!call_if_valid(bar, 3, 1));
96 DLIB_TEST(value == 6);
97
98
99 // make sure stateful lambdas are modified when called
100 value = 0;
101 int i = 0;
102 auto stateful = [&value, i]() mutable { ++i; value = i; };
103 DLIB_TEST(call_if_valid(stateful));
104 DLIB_TEST(value == 1);
105 DLIB_TEST(call_if_valid(stateful));
106 DLIB_TEST(value == 2);
107 DLIB_TEST(call_if_valid(stateful));
108 DLIB_TEST(value == 3);
109 }
110
111
112 class metaprogramming_tester : public tester

Callers 1

perform_testMethod · 0.85

Calls 1

call_if_validFunction · 0.85

Tested by

no test coverage detected