-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matrix_public_test.cpp
58 lines (42 loc) · 1.4 KB
/
Matrix_public_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "Matrix.hpp"
#include "Matrix_test_helpers.hpp"
#include "unit_test_framework.hpp"
#include <sstream>
using std::ostringstream;
// This is the public Matrix test for which the autograder gives feedback.
// It only tests VERY FEW of the expected behaviors of the Matrix module.
// It will only really tell you if your code compiles and you remembered to
// write the functions. It is not to be trusted. It tells the truth, but not
// the whole truth. It might put you in a blender. You get the point.
// You must write your own comprehensive unit tests in Matrix_tests.cpp!
TEST(test_matrix_basic) {
Matrix *mat = new Matrix;
Matrix_init(mat, 5, 5);
ASSERT_EQUAL(Matrix_width(mat), 5);
ASSERT_EQUAL(Matrix_height(mat), 5);
Matrix_fill(mat, 0);
int *ptr = Matrix_at(mat, 2, 3);
ASSERT_EQUAL(Matrix_row(mat, ptr), 2);
ASSERT_EQUAL(Matrix_column(mat, ptr), 3);
ASSERT_EQUAL(*ptr, 0);
*ptr = 42;
const int *cptr = Matrix_at(mat, 2, 3);
ASSERT_EQUAL(*cptr, 42);
Matrix_fill_border(mat, 2);
ASSERT_EQUAL(*Matrix_at(mat, 0, 0), 2);
ASSERT_EQUAL(Matrix_max(mat), 42);
delete mat;
}
TEST(test_matrix_print) {
Matrix *mat = new Matrix;
Matrix_init(mat, 1, 1);
*Matrix_at(mat, 0, 0) = 42;
ostringstream expected;
expected << "1 1\n"
<< "42 \n";
ostringstream actual;
Matrix_print(mat, actual);
ASSERT_EQUAL(expected.str(), actual.str());
delete mat;
}
TEST_MAIN()