这是一个本人学习 csapp 的 learning 库

30 line
839 B

  1. //
  2. // Created by GentleCold on 2022/8/17.
  3. //
  4. #ifndef CSAPPLEARNING_TEST_H
  5. #define CSAPPLEARNING_TEST_H
  6. #include <stdio.h>
  7. #include <string.h>
  8. int main_ret = 0;
  9. int test_count = 0;
  10. int test_pass = 0;
  11. #define EXPECT_EQ_BASE(equality, expect, actual, format)\
  12. do {\
  13. test_count++;\
  14. if (equality) {\
  15. test_pass++;\
  16. } else {\
  17. fprintf(stderr, "%s:%d: expect: " format " actual: " format "\n", __FILE__, __LINE__, expect, actual);\
  18. main_ret = 1;\
  19. }\
  20. } while(0)
  21. #define EXPECT_EQ_INT(expect, actual) EXPECT_EQ_BASE((expect) == (actual), expect, actual, "%d")
  22. #define EXPECT_EQ_DOUBLE(expect, actual) EXPECT_EQ_BASE((expect) == (actual), expect, actual, "%lf")
  23. #define EXPECT_EQ_TRUE(actual) EXPECT_EQ_BASE(actual, "true", "false", "%s")
  24. #endif //CSAPPLEARNING_TEST_H