Advertisement
PaulPaulAga

Untitled

May 12th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <numeric>
  3. #include <algorithm>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. #include "../headers/matrix/matrix.h"
  9. #include "../headers/test_runner.h"
  10.  
  11. void testMatrix()
  12. {
  13.     Matrix<int> matrix(10, 10);
  14.     iota(matrix.begin(), matrix.end(), 0);
  15.     cout << matrix;
  16. }
  17.  
  18. void testMatrixCopy()
  19. {
  20.     {
  21.         Matrix<int> matrix(10, 10);
  22.         iota(matrix.begin(), matrix.end(), 0);
  23.         stringstream expected, result;
  24.         Matrix<int> matrix_copy(matrix);
  25.         expected << matrix;
  26.         result << matrix_copy;
  27.         ASSERT_EQUAL(expected.str(), result.str());
  28.         expected.clear();
  29.         result.clear();
  30.     }
  31.     {
  32.         Matrix<int> matrix(10, 10);
  33.         iota(matrix.begin(), matrix.end(), 0);
  34.         stringstream expected, result;
  35.         Matrix<int> matrix_copy = matrix;
  36.         expected << matrix;
  37.         result << matrix_copy;
  38.         ASSERT_EQUAL(expected.str(), result.str());
  39.         expected.clear();
  40.         result.clear();
  41.     }
  42. };
  43.  
  44. void testMatrixInitializerList()
  45. {
  46.  
  47.     Matrix<int> matrix(3, 3);
  48.     iota(matrix.begin(), matrix.end(), 0);
  49.     stringstream expected, result;
  50.     expected << matrix;
  51.     Matrix<int> matrix_initializer_list({{0, 1, 2},
  52.                                          {3, 4, 5},
  53.                                          {6, 7, 8}});
  54.     result << matrix_initializer_list;
  55.     ASSERT_EQUAL(expected.str(), result.str());
  56.  
  57. };
  58.  
  59. void testMatrixMove()
  60. {
  61.     {
  62.         Matrix<int> src(3, 3);
  63.         iota(src.begin(), src.end(), 0);
  64.         Matrix<int> dst(move(src));
  65.         ASSERT_EQUAL(src.getN(), 0);
  66.         ASSERT_EQUAL(src.getM(), 0);
  67.         ASSERT_EQUAL(dst.getN(), 3);
  68.         ASSERT_EQUAL(dst.getM(), 3);
  69.         Matrix<int> iota_filled({{0, 1, 2},
  70.                                  {3, 4, 5},
  71.                                  {6, 7, 8}});
  72.         stringstream expected, result;
  73.         result << dst;
  74.         expected << iota_filled;
  75.         ASSERT_EQUAL(expected.str(), result.str());
  76.     }
  77.     {
  78.         Matrix<int> src(3, 3);
  79.         iota(src.begin(), src.end(), 0);
  80.         Matrix<int> dst = move(src);
  81.         ASSERT_EQUAL(src.getN(), 0);
  82.         ASSERT_EQUAL(src.getM(), 0);
  83.         ASSERT_EQUAL(dst.getN(), 3);
  84.         ASSERT_EQUAL(dst.getM(), 3);
  85.         Matrix<int> iota_filled({{0, 1, 2},
  86.                                  {3, 4, 5},
  87.                                  {6, 7, 8}});
  88.         stringstream expected, result;
  89.         result << dst;
  90.         expected << iota_filled;
  91.         ASSERT_EQUAL(expected.str(), result.str());
  92.     }
  93. }
  94.  
  95. void testAll()
  96. {
  97.     TestRunner tr;
  98.     RUN_TEST(tr, testMatrixCopy);
  99.     RUN_TEST(tr, testMatrixInitializerList);
  100.     RUN_TEST(tr, testMatrixMove);
  101. }
  102.  
  103. int main()
  104. {
  105.     testAll();
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement