1 /* ///////////////////////////////////////////////////////////////////////
2 * File: sparse_matrix_test.h
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_CONTAINER_SPARSE_MATRIX_TEST_H
13 #define EXTL_CONTAINER_SPARSE_MATRIX_TEST_H
15 /* ///////////////////////////////////////////////////////////////////////
16 * ::unit_test namespace
19 EXTL_TEST_NAME_BEGIN_NAMESPACE(sparse_matrix_test
)
21 /* ///////////////////////////////////////////////////////////////////////
24 static int sparse_matrix_test()
26 typedef sparse_matrix
<int> sparse_matrix_type
;
27 sparse_matrix_type
sm(5);
40 EXTL_TEST_TRACE(_T("sparse_matrix test:"));
41 EXTL_TEST_TRACE(_T("\nelement:"));
42 for (sparse_matrix_type::const_iterator p
= sm
.begin(); p
!= sm
.end(); ++p
)
44 EXTL_TEST_TRACE(_T("%d "), *p
);
47 EXTL_TEST_TRACE(_T("\nrow(0):"));
48 for (sparse_matrix_type::const_rowe_iterator prowe
= sm
.rowe_begin(0); prowe
!= sm
.rowe_end(0); ++prowe
)
50 EXTL_TEST_TRACE(_T("%d "), *prowe
);
53 EXTL_TEST_TRACE(_T("\nreverse row(0):"));
54 for (sparse_matrix_type::const_rowe_reverse_iterator rprowe
= sm
.rowe_rbegin(0); rprowe
!= sm
.rowe_rend(0); ++rprowe
)
56 EXTL_TEST_TRACE(_T("%d "), *rprowe
);
59 EXTL_TEST_TRACE(_T("\ncol(0):"));
60 for (sparse_matrix_type::const_cole_iterator pcole
= sm
.cole_begin(0); pcole
!= sm
.cole_end(0); ++pcole
)
62 EXTL_TEST_TRACE(_T("%d "), *pcole
);
65 EXTL_TEST_TRACE(_T("\nreverse col(0):"));
66 for (sparse_matrix_type::const_cole_reverse_iterator rpcole
= sm
.cole_rbegin(0); rpcole
!= sm
.cole_rend(0); ++rpcole
)
68 EXTL_TEST_TRACE(_T("%d "), *rpcole
);
70 EXTL_TEST_TRACE(_T("sparse matrix:"));
71 for (i
= 0; i
< sm
.dim0(); ++i
)
73 EXTL_TEST_TRACE(_T("%d %d %d %d %d "), sm
[i
][0], sm
[i
][1], sm
[i
][2], sm
[i
][3], sm
[i
][4]);
75 EXTL_TEST_TRACE(_T(""));
78 EXTL_TEST_TRACE(_T("erase(1, 1) sparse matrix:"));
79 for (i
= 0; i
< sm
.dim0(); ++i
)
81 EXTL_TEST_TRACE(_T("%d %d %d %d %d "), sm
[i
][0], sm
[i
][1], sm
[i
][2], sm
[i
][3], sm
[i
][4]);
83 EXTL_TEST_TRACE(_T(""));
86 EXTL_TEST_TRACE(_T("erase_row(1) sparse matrix:"));
87 for (i
= 0; i
< sm
.dim0(); ++i
)
89 EXTL_TEST_TRACE(_T("%d %d %d %d %d "), sm
[i
][0], sm
[i
][1], sm
[i
][2], sm
[i
][3], sm
[i
][4]);
91 EXTL_TEST_TRACE(_T(""));
94 EXTL_TEST_TRACE(_T("erase_col(1) sparse matrix:"));
95 for (i
= 0; i
< sm
.dim0(); ++i
)
97 EXTL_TEST_TRACE(_T("%d %d %d %d %d "), sm
[i
][0], sm
[i
][1], sm
[i
][2], sm
[i
][3], sm
[i
][4]);
99 EXTL_TEST_TRACE(_T(""));
103 int sparse_matrix_test_ret
= sparse_matrix_test();
105 /* ///////////////////////////////////////////////////////////////////////
106 * ::unit_test namespace
108 EXTL_TEST_NAME_END_NAMESPACE(sparse_matrix_test
)
110 /* //////////////////////////////////////////////////////////////////// */
111 #endif /* EXTL_CONTAINER_SPARSE_MATRIX_TEST_H */
112 /* //////////////////////////////////////////////////////////////////// */