remove \r
[extl.git] / extl / container / test / sparse_matrix_test.h
blob7047dcbdbbb3c1cb510a7d3ca79cfe534ab5f28b
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: sparse_matrix_test.h
4 * Created: 08.12.08
5 * Updated: 08.12.08
7 * Brief: Unit-testing
9 * [<Home>]
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
18 EXTL_BEGIN_NAMESPACE
19 EXTL_TEST_NAME_BEGIN_NAMESPACE(sparse_matrix_test)
21 /* ///////////////////////////////////////////////////////////////////////
22 * Unit-testing
24 static int sparse_matrix_test()
26 typedef sparse_matrix<int> sparse_matrix_type;
27 sparse_matrix_type sm(5);
28 e_size_t i;
30 sm.at(0, 0) = 1;
31 sm.at(0, 1) = 2;
32 sm.at(0, 2) = 3;
33 sm.at(1, 0) = 4;
34 sm.at(1, 1) = 5;
35 sm.at(1, 2) = 6;
36 sm.at(2, 0) = 7;
37 sm.at(2, 1) = 8;
38 sm.at(2, 2) = 9;
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(""));
77 sm.erase(1, 1);
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(""));
85 sm.erase_row(1);
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(""));
93 sm.erase_col(1);
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(""));
101 return 0;
103 int sparse_matrix_test_ret = sparse_matrix_test();
105 /* ///////////////////////////////////////////////////////////////////////
106 * ::unit_test namespace
108 EXTL_TEST_NAME_END_NAMESPACE(sparse_matrix_test)
109 EXTL_END_NAMESPACE
110 /* //////////////////////////////////////////////////////////////////// */
111 #endif /* EXTL_CONTAINER_SPARSE_MATRIX_TEST_H */
112 /* //////////////////////////////////////////////////////////////////// */