Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <numeric>
- #include <algorithm>
- #include <iomanip>
- using namespace std;
- #include "../headers/matrix/matrix.h"
- #include "../headers/test_runner.h"
- void testMatrix()
- {
- Matrix<int> matrix(10, 10);
- iota(matrix.begin(), matrix.end(), 0);
- cout << matrix;
- }
- void testMatrixCopy()
- {
- {
- Matrix<int> matrix(10, 10);
- iota(matrix.begin(), matrix.end(), 0);
- stringstream expected, result;
- Matrix<int> matrix_copy(matrix);
- expected << matrix;
- result << matrix_copy;
- ASSERT_EQUAL(expected.str(), result.str());
- expected.clear();
- result.clear();
- }
- {
- Matrix<int> matrix(10, 10);
- iota(matrix.begin(), matrix.end(), 0);
- stringstream expected, result;
- Matrix<int> matrix_copy = matrix;
- expected << matrix;
- result << matrix_copy;
- ASSERT_EQUAL(expected.str(), result.str());
- expected.clear();
- result.clear();
- }
- };
- void testMatrixInitializerList()
- {
- Matrix<int> matrix(3, 3);
- iota(matrix.begin(), matrix.end(), 0);
- stringstream expected, result;
- expected << matrix;
- Matrix<int> matrix_initializer_list({{0, 1, 2},
- {3, 4, 5},
- {6, 7, 8}});
- result << matrix_initializer_list;
- ASSERT_EQUAL(expected.str(), result.str());
- };
- void testMatrixMove()
- {
- {
- Matrix<int> src(3, 3);
- iota(src.begin(), src.end(), 0);
- Matrix<int> dst(move(src));
- ASSERT_EQUAL(src.getN(), 0);
- ASSERT_EQUAL(src.getM(), 0);
- ASSERT_EQUAL(dst.getN(), 3);
- ASSERT_EQUAL(dst.getM(), 3);
- Matrix<int> iota_filled({{0, 1, 2},
- {3, 4, 5},
- {6, 7, 8}});
- stringstream expected, result;
- result << dst;
- expected << iota_filled;
- ASSERT_EQUAL(expected.str(), result.str());
- }
- {
- Matrix<int> src(3, 3);
- iota(src.begin(), src.end(), 0);
- Matrix<int> dst = move(src);
- ASSERT_EQUAL(src.getN(), 0);
- ASSERT_EQUAL(src.getM(), 0);
- ASSERT_EQUAL(dst.getN(), 3);
- ASSERT_EQUAL(dst.getM(), 3);
- Matrix<int> iota_filled({{0, 1, 2},
- {3, 4, 5},
- {6, 7, 8}});
- stringstream expected, result;
- result << dst;
- expected << iota_filled;
- ASSERT_EQUAL(expected.str(), result.str());
- }
- }
- void testAll()
- {
- TestRunner tr;
- RUN_TEST(tr, testMatrixCopy);
- RUN_TEST(tr, testMatrixInitializerList);
- RUN_TEST(tr, testMatrixMove);
- }
- int main()
- {
- testAll();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement