lightweight_test_all_eq_test.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // Negative test for BOOST_TEST_ALL_EQ
  3. //
  4. // Copyright (c) 2017 Bjorn Reese
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. //
  10. #include <vector>
  11. #include <set>
  12. #include <boost/core/lightweight_test.hpp>
  13. int main()
  14. {
  15. int test_cases = 0;
  16. // Array
  17. {
  18. int x[] = { 1 };
  19. int y[] = { 1, 2 };
  20. BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) );
  21. ++test_cases;
  22. }
  23. {
  24. int x[] = { 1, 2 };
  25. int y[] = { 1 };
  26. BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) );
  27. ++test_cases;
  28. }
  29. {
  30. int x[] = { 2 };
  31. int y[] = { 1, 2 };
  32. BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) );
  33. ++test_cases;
  34. }
  35. {
  36. int x[] = { 1, 2, 3, 4 };
  37. int y[] = { 1, 3, 2, 4 };
  38. BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) );
  39. ++test_cases;
  40. }
  41. // Vector
  42. {
  43. std::vector<int> x, y;
  44. x.push_back( 1 );
  45. BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() );
  46. ++test_cases;
  47. }
  48. {
  49. std::vector<int> x, y;
  50. y.push_back( 1 );
  51. BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() );
  52. ++test_cases;
  53. }
  54. {
  55. std::vector<int> x, y;
  56. x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
  57. y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 );
  58. BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() );
  59. ++test_cases;
  60. }
  61. {
  62. std::vector<float> x, y;
  63. x.push_back( 1.0f ); x.push_back( 2.0f ); x.push_back( 3.0f ); x.push_back( 4.0f );
  64. y.push_back( 4.0f ); y.push_back( 2.0f ); y.push_back( 3.0f ); y.push_back( 1.0f );
  65. BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() );
  66. ++test_cases;
  67. }
  68. {
  69. std::vector<int> x, y;
  70. x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 );
  71. y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 );
  72. BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() );
  73. ++test_cases;
  74. }
  75. {
  76. std::vector<int> x, y;
  77. x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 );
  78. y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 );;
  79. BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() );
  80. ++test_cases;
  81. }
  82. // Set
  83. {
  84. std::set<int> x, y;
  85. x.insert(1);
  86. y.insert(1); y.insert(3);
  87. BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() );
  88. ++test_cases;
  89. }
  90. {
  91. std::set<int> x, y;
  92. x.insert(1); x.insert(2);
  93. y.insert(1);
  94. BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() );
  95. ++test_cases;
  96. }
  97. {
  98. std::set<int> x, y;
  99. x.insert(1); x.insert(2);
  100. y.insert(1); y.insert(3);
  101. BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() );
  102. ++test_cases;
  103. }
  104. return boost::report_errors() == test_cases;
  105. }