-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_test.cpp
135 lines (111 loc) · 5.76 KB
/
simple_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <list>
#include "multiplicator.hh"
#include "float_value_factory.hh"
#include "sparse_matrix_value_generator.hh"
#include "compressed_sparse_row/compressed_sparse_row.hh"
#include "coordinate_list/coordinate_list.hh"
#include "dictionary_of_keys/dictionary_of_keys.hh"
#include "../scylla_modern_cpp_driver/include/session.hh"
#include "list_of_lists/list_of_lists_wrapper.hh"
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE simple_test
#include <boost/test/unit_test.hpp>
const char *IP_ADDRESS = "172.19.0.2";
enum class implementation {
COORDINATE_LIST,
COMPRESSED_SPARSE_ROW,
DICTIONARY_OF_KEYS,
LIST_OF_LISTS
};
std::list<matrix_value<float>> get_multiplied_vals(size_t dimension, size_t vals,
std::unique_ptr<multiplicator<float>> multiplicator, int seed) {
std::shared_ptr factory = std::make_shared<float_value_factory>(0.0, 100.0, 0);
multiplicator->load_matrix(sparse_matrix_value_generator<float>(dimension, dimension, vals, seed, factory));
multiplicator->load_matrix(sparse_matrix_value_generator<float>(dimension, dimension, vals, 18121 * seed + 12, factory));
multiplicator->multiply();
std::list<matrix_value<float>> ret;
for (int i = 1; i <= dimension; i++) {
for (int j = 1; j <= dimension; j++) {
auto result = multiplicator->get_result({i, j});
if (result != 0) {
ret.emplace_back(i, j, result);
}
}
}
return ret;
}
std::list<matrix_value<float>> get_result(implementation from, size_t dimension, size_t vals,
std::shared_ptr<connector> conn, std::shared_ptr<scmd::session> conn2, int seed) {
std::unique_ptr<multiplicator<float>> multiplicator;
switch(from) {
case implementation::COORDINATE_LIST:
multiplicator = std::make_unique<COO<float>>(conn);
break;
case implementation::COMPRESSED_SPARSE_ROW:
multiplicator = std::make_unique<CSR<float>>(conn);
break;
case implementation::DICTIONARY_OF_KEYS:
multiplicator = std::make_unique<DOK<float>>(conn);
break;
case implementation::LIST_OF_LISTS:
multiplicator = std::make_unique<LIL_wrapper<float>>(conn2);
break;
}
return get_multiplied_vals(dimension, vals, std::move(multiplicator), seed);
}
BOOST_TEST_SPECIALIZED_COLLECTION_COMPARE(std::list<matrix_value<float>>)
BOOST_AUTO_TEST_SUITE(simple_cross_antitest)
BOOST_AUTO_TEST_CASE(test_fail) {
std::shared_ptr<connector> conn = std::make_shared<connector>(IP_ADDRESS);
std::shared_ptr<scmd::session> conn2 = std::make_shared<scmd::session>(IP_ADDRESS);
auto _coo = get_result(implementation::COORDINATE_LIST, 10, 10, conn, conn2, 1);
auto _csr = get_result(implementation::COMPRESSED_SPARSE_ROW, 10, 10, conn, conn2, 111);
BOOST_TEST(_coo != _csr);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(simple_cross_test)
BOOST_AUTO_TEST_CASE(test_all_implementations0) {
std::shared_ptr<connector> conn = std::make_shared<connector>(IP_ADDRESS);
std::shared_ptr<scmd::session> conn2 = std::make_shared<scmd::session>(IP_ADDRESS);
auto _coo = get_result(implementation::COORDINATE_LIST, 3, 3, conn, conn2, 2);
auto _csr = get_result(implementation::COMPRESSED_SPARSE_ROW, 3, 3, conn, conn2, 2);
auto _dok = get_result(implementation::DICTIONARY_OF_KEYS, 3, 3, conn, conn2, 2);
auto _lil = get_result(implementation::LIST_OF_LISTS, 3, 3, conn, conn2, 2);
BOOST_TEST(_coo == _csr);;
BOOST_TEST(_coo == _dok);
BOOST_TEST(_coo == _lil);
}
BOOST_AUTO_TEST_CASE(test_all_implementations1) {
std::shared_ptr<connector> conn = std::make_shared<connector>(IP_ADDRESS);
std::shared_ptr<scmd::session> conn2 = std::make_shared<scmd::session>(IP_ADDRESS);
auto _coo = get_result(implementation::COORDINATE_LIST, 10, 10, conn, conn2, 1);
auto _csr = get_result(implementation::COMPRESSED_SPARSE_ROW, 10, 10, conn, conn2, 1);
auto _dok = get_result(implementation::DICTIONARY_OF_KEYS, 10, 10, conn, conn2, 1);
auto _lil = get_result(implementation::LIST_OF_LISTS, 10, 10, conn, conn2, 1);
BOOST_TEST(_coo == _csr);
BOOST_TEST(_coo == _dok);
BOOST_TEST(_coo == _lil);
}
BOOST_AUTO_TEST_CASE(test_all_implementations2) {
std::shared_ptr<connector> conn = std::make_shared<connector>(IP_ADDRESS);
std::shared_ptr<scmd::session> conn2 = std::make_shared<scmd::session>(IP_ADDRESS);
auto _coo = get_result(implementation::COORDINATE_LIST, 20, 20, conn, conn2, 3);
auto _csr = get_result(implementation::COMPRESSED_SPARSE_ROW, 20, 20, conn, conn2, 3);
auto _dok = get_result(implementation::DICTIONARY_OF_KEYS, 20, 20, conn, conn2, 3);
auto _lil = get_result(implementation::LIST_OF_LISTS, 20, 20, conn, conn2, 3);
BOOST_TEST(_coo == _csr);
BOOST_TEST(_coo == _dok);
BOOST_TEST(_coo == _lil);
}
BOOST_AUTO_TEST_CASE(test_all_implementations3) {
std::shared_ptr<connector> conn = std::make_shared<connector>(IP_ADDRESS);
std::shared_ptr<scmd::session> conn2 = std::make_shared<scmd::session>(IP_ADDRESS);
auto _coo = get_result(implementation::COORDINATE_LIST, 6, 30, conn, conn2, 42);
auto _csr = get_result(implementation::COMPRESSED_SPARSE_ROW, 6, 30, conn, conn2, 42);
auto _dok = get_result(implementation::DICTIONARY_OF_KEYS, 6, 30, conn, conn2, 42);
auto _lil = get_result(implementation::LIST_OF_LISTS, 6, 30, conn, conn2, 42);
BOOST_TEST(_coo == _csr);
BOOST_TEST(_coo == _dok);
BOOST_TEST(_coo == _lil);
}
BOOST_AUTO_TEST_SUITE_END()