Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

48 lines
1.2KB

  1. #include <stdint.h>
  2. #include <iostream>
  3. #define CATCH_CONFIG_RUNNER
  4. #include "catch.hpp"
  5. #include "test_cases.h"
  6. /*#pragma comment(lib, "advanced_instructions.obj")
  7. #pragma comment(lib, "simple_tests.obj")
  8. #pragma comment(lib, "backwards.obj")*/
  9. static Catch::Session session;
  10. _declspec(dllexport) void SelfTest() {
  11. session.run();
  12. }
  13. TEST_CASE("Simple functions work as expected, unhooked") {
  14. REQUIRE(_small() == 0);
  15. REQUIRE(_branch(1) == 0);
  16. REQUIRE(_branch(0) == 0);
  17. for (int i = 0; i < 1000; i++) {
  18. REQUIRE(_rip_relative() == rand());
  19. }
  20. }
  21. TEST_CASE("Advanced instruction functions work as expected, unhokked") {
  22. double result[4];
  23. _AVX(9., static_cast<void*>(result));
  24. REQUIRE((result[0] - result[1]) < DBL_EPSILON);
  25. REQUIRE((result[1] - result[2]) < DBL_EPSILON);
  26. REQUIRE((result[2] - result[3]) < DBL_EPSILON);
  27. REQUIRE((result[0] - 3.) < DBL_EPSILON);
  28. }
  29. TEST_CASE("Loops & tail recursion work as expected, unhook") {
  30. REQUIRE(_loop(2, 3) == 8);
  31. REQUIRE(_loop(5, 3) == 125);
  32. REQUIRE(_loop(5, 0) == 1);
  33. REQUIRE(_loop(5, 1) == 5);
  34. REQUIRE(_tail_recursion(0) == 1);
  35. REQUIRE(_tail_recursion(1) == 1);
  36. REQUIRE(_tail_recursion(2) == 2);
  37. REQUIRE(_tail_recursion(5) == 120);
  38. }