Skip to content

Commit

Permalink
Polish the unittest.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xreki committed Jan 26, 2022
1 parent 5fc0bc5 commit 3a2ca8f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
13 changes: 13 additions & 0 deletions tests/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,22 @@
#include <stdexcept>
#include <vector>
#include <random>
#include <string>

#include <ctc.h>

#define CHECK_STATUS(func_call, status) \
{ \
bool s = func_call; \
std::string funcname = #func_call; \
if (s) { \
std::cout << "-- TEST " << funcname << " PASS!\n"; \
} else { \
std::cout << "-- TEST " << funcname << " FAILED!\n"; \
} \
status &= s; \
}

inline void throw_on_error(ctcStatus_t status, const char* message) {
if (status != CTC_STATUS_SUCCESS) {
throw std::runtime_error(message + (", stat = " +
Expand Down
12 changes: 6 additions & 6 deletions tests/test_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,16 @@ int main(void) {
std::cout << "Running CPU tests" << std::endl;

bool status = true;
status &= small_test();
status &= options_test();
status &= inf_test();
status &= run_tests();
CHECK_STATUS(small_test(), status);
CHECK_STATUS(options_test(), status);
CHECK_STATUS(inf_test(), status);
CHECK_STATUS(run_tests(), status);

if (status) {
std::cout << "Tests pass" << std::endl;
std::cout << "All tests PASS!" << std::endl;
return 0;
} else {
std::cout << "Some or all tests fail" << std::endl;
std::cout << "Some or all tests FAILED!" << std::endl;
return 1;
}
}
12 changes: 6 additions & 6 deletions tests/test_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -678,16 +678,16 @@ int main(void) {
#endif

bool status = true;
status &= small_test();
status &= options_test();
status &= inf_test();
status &= run_tests();
CHECK_STATUS(small_test(), status);
CHECK_STATUS(options_test(), status);
CHECK_STATUS(inf_test(), status);
CHECK_STATUS(run_tests(), status);

if (status) {
std::cout << "Tests pass" << std::endl;
std::cout << "All tests PASS!" << std::endl;
return 0;
} else {
std::cout << "Some or all tests fail" << std::endl;
std::cout << "Some or all tests FAILED!" << std::endl;
return 1;
}
}

0 comments on commit 3a2ca8f

Please sign in to comment.