test_swap.cpp 588 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <catch2/catch_test_macros.hpp>
  2. #include "swap.hpp"
  3. TEST_CASE("Swap value with references", "[swap]") {
  4. int a=5, b=3;
  5. mcl::swap(a, b);
  6. REQUIRE( a == 3 );
  7. REQUIRE( b == 5 );
  8. }
  9. TEST_CASE("Swap value with points", "[swap]") {
  10. int a=5;
  11. int b=3;
  12. int* x=&a;
  13. int* y=&b;
  14. mcl::swap(x, y);
  15. REQUIRE( a == 3 );
  16. REQUIRE( b == 5 );
  17. REQUIRE( *x == 3 );
  18. REQUIRE( *y == 5 );
  19. }
  20. TEST_CASE("Swap points with points", "[swap]") {
  21. int a=5, b=3;
  22. int* x=&a;
  23. int* y=&b;
  24. mcl::swap(&x, &y);
  25. REQUIRE( a == 5 );
  26. REQUIRE( b == 3 );
  27. REQUIRE( *x == 3 );
  28. REQUIRE( *y == 5 );
  29. }