-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e824c6e
commit 7733ede
Showing
2 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <cassert> | ||
#include "Series.h" | ||
#include "Matrix.h" | ||
|
||
void TestGetRowsNumber(){ | ||
Matrix m(3, 4); | ||
std::ifstream inf("test_matrix.txt"); | ||
inf >> m; | ||
assert(m.GetRowsNumber() == 3); | ||
} | ||
|
||
void TestGetColumnsNumber(){ | ||
Matrix m(3, 4); | ||
std::ifstream inf("test_matrix.txt"); | ||
inf >> m; | ||
assert(m.GetColumnsNumber() == 4); | ||
} | ||
|
||
void TestIndexing(){ | ||
Matrix m(3, 4); | ||
std::ifstream inf("test_matrix.txt"); | ||
inf >> m; | ||
assert(m[1][3] == 8); | ||
} | ||
|
||
void TestEqual(){ | ||
Matrix m_1(3, 4); | ||
Matrix m_2(3, 4); | ||
std::ifstream inf("test_matrix.txt"); | ||
inf >> m_1 >> m_2; | ||
assert(m_1 == m_2); | ||
} | ||
|
||
void TestInequal(){ | ||
Matrix m_1(3, 4); | ||
Matrix m_2(3, 4); | ||
std::ifstream inf("test_inequal.txt"); | ||
inf >> m_1 >> m_2; | ||
assert(m_1 != m_2); | ||
} | ||
|
||
void TestAdd(){ | ||
Matrix m_1(3, 4); | ||
Matrix m_2(3, 4); | ||
Matrix m_1_copy(3, 4); | ||
Matrix m_2_copy(3, 4); | ||
Matrix sum(3, 4); | ||
Matrix answer(3, 4); | ||
std::ifstream inf("test_add.txt"); | ||
inf >> m_1 >> m_2 >> answer; | ||
m_1_copy = m_1; | ||
m_2_copy = m_2; | ||
sum = m_1 + m_2; | ||
assert(sum == answer); | ||
//Проверяем, что m_1 и m_2 не изменились. | ||
assert(m_1_copy == m_1 && m_2_copy == m_2); | ||
} | ||
|
||
void TestMulWithAssignment(){ | ||
Matrix m_1(3, 4); | ||
Matrix answer(3, 4); | ||
int x = 10; | ||
std::ifstream inf("test_mul.txt"); | ||
inf >> m_1 >> answer; | ||
m_1 *= x; | ||
assert(m_1 == answer); | ||
} | ||
|
||
void TestOutOfRange(){ | ||
Matrix m_1(3, 4); | ||
bool catch_flag = false; | ||
std::ifstream inf("test_matrix.txt"); | ||
inf >> m_1; | ||
try{ | ||
m_1[3][0]; | ||
} | ||
catch(std::out_of_range& oor){ | ||
catch_flag = true; | ||
} | ||
assert(catch_flag == true); | ||
|
||
catch_flag = false; | ||
try{ | ||
m_1[2][4]; | ||
} | ||
catch(std::out_of_range& oor){ | ||
catch_flag = true; | ||
} | ||
assert(catch_flag == true); | ||
} | ||
|
||
void TestOutput(){ | ||
Matrix res(3, 4); | ||
std::ifstream inf("test_matrix.txt"); | ||
inf >> res; | ||
std::fstream fs("test_output.txt"); | ||
fs << res; | ||
fs.seekg(0); | ||
Matrix m(3, 4); | ||
fs >> m; | ||
assert(m == res); | ||
} | ||
|
||
int main(){ | ||
TestGetRowsNumber(); | ||
TestGetColumnsNumber(); | ||
TestIndexing(); | ||
TestAdd(); | ||
TestMulWithAssignment(); | ||
TestOutOfRange(); | ||
TestOutput(); | ||
std::cout << "All tests passed successfully :)\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1 2 3 4 | ||
5 6 7 8 | ||
9 10 11 12 | ||
100 |