|
25 | 25 | using namespace bc; |
26 | 26 | using namespace bc::wallet; |
27 | 27 |
|
| 28 | +bool intersects(dictionary alpha, dictionary beta) |
| 29 | +{ |
| 30 | + return std::any_of(alpha.begin(), alpha.end(), |
| 31 | + [&](const char* test_right) |
| 32 | + { |
| 33 | +#if defined _MSC_VER && (!defined NDEBUG) |
| 34 | + // MSVC build error mitigation. |
| 35 | + return std::find_if(beta.begin(), beta.end(), |
| 36 | + [&](const char test_left[]) |
| 37 | + { |
| 38 | + return (std::strcmp(test_left, test_right) == 0); |
| 39 | + }) != std::end(beta); |
| 40 | +#else |
| 41 | + return std::find(beta.begin(), beta.end(), |
| 42 | + test_right) != std::end(beta); |
| 43 | +#endif |
| 44 | + }); |
| 45 | +} |
| 46 | + |
| 47 | +dictionary::size_type intersection_count(dictionary alpha, dictionary beta) |
| 48 | +{ |
| 49 | + return std::count_if(alpha.begin(), alpha.end(), |
| 50 | + [&](const char* test_right) |
| 51 | + { |
| 52 | +#if defined _MSC_VER && (!defined NDEBUG) |
| 53 | + // MSVC build error mitigation. |
| 54 | + return std::find_if(beta.begin(), beta.end(), |
| 55 | + [&](const char test_left[]) |
| 56 | + { |
| 57 | + return (std::strcmp(test_left, test_right) == 0); |
| 58 | + }) != std::end(beta); |
| 59 | +#else |
| 60 | + return std::find(beta.begin(), beta.end(), |
| 61 | + test_right) != std::end(beta); |
| 62 | +#endif |
| 63 | + |
| 64 | + }); |
| 65 | +} |
| 66 | + |
28 | 67 | BOOST_AUTO_TEST_SUITE(mnemonic_tests) |
29 | 68 |
|
30 | 69 | BOOST_AUTO_TEST_CASE(mnemonic__decode_mnemonic__no_passphrase) |
@@ -117,121 +156,49 @@ BOOST_AUTO_TEST_CASE(mnemonic__create_mnemonic__giant) |
117 | 156 |
|
118 | 157 | BOOST_AUTO_TEST_CASE(mnemonic__dictionary__en_es__no_intersection) |
119 | 158 | { |
120 | | - const auto intersection = std::any_of(language::en.begin(), language::en.end(), |
121 | | - [&](const char* test_right) |
122 | | - { |
123 | | - return std::find_if(language::es.begin(), language::es.end(), |
124 | | - [&](const char test_left[]) |
125 | | - { |
126 | | - return (std::strcmp(test_left, test_right) == 0); |
127 | | - }) != std::end(language::es); |
128 | | - }); |
129 | | - |
| 159 | + const auto intersection = intersects(language::en, language::es); |
130 | 160 | BOOST_REQUIRE(!intersection); |
131 | 161 | } |
132 | 162 |
|
133 | 163 | BOOST_AUTO_TEST_CASE(mnemonic__dictionary__it_en__no_intersection) |
134 | 164 | { |
135 | | - const auto intersection = std::any_of(language::it.begin(), language::it.end(), |
136 | | - [&](const char* test_right) |
137 | | - { |
138 | | - return std::find_if(language::en.begin(), language::en.end(), |
139 | | - [&](const char test_left[]) |
140 | | - { |
141 | | - return (std::strcmp(test_left, test_right) == 0); |
142 | | - }) != std::end(language::en); |
143 | | - }); |
144 | | - |
| 165 | + const auto intersection = intersects(language::it, language::en); |
145 | 166 | BOOST_REQUIRE(!intersection); |
146 | 167 | } |
147 | 168 |
|
148 | 169 | BOOST_AUTO_TEST_CASE(mnemonic__dictionary__fr_es__no_intersection) |
149 | 170 | { |
150 | | - const auto intersection = std::any_of(language::fr.begin(), language::fr.end(), |
151 | | - [&](const char* test_right) |
152 | | - { |
153 | | - return std::find_if(language::es.begin(), language::es.end(), |
154 | | - [&](const char test_left[]) |
155 | | - { |
156 | | - return (std::strcmp(test_left, test_right) == 0); |
157 | | - }) != std::end(language::es); |
158 | | - }); |
159 | | - |
| 171 | + const auto intersection = intersects(language::fr, language::es); |
160 | 172 | BOOST_REQUIRE(!intersection); |
161 | 173 | } |
162 | 174 |
|
163 | 175 | BOOST_AUTO_TEST_CASE(mnemonic__dictionary__it_es__no_intersection) |
164 | 176 | { |
165 | | - const auto intersection = std::any_of(language::it.begin(), language::it.end(), |
166 | | - [&](const char* test_right) |
167 | | - { |
168 | | - return std::find_if(language::es.begin(), language::es.end(), |
169 | | - [&](const char test_left[]) |
170 | | - { |
171 | | - return (std::strcmp(test_left, test_right) == 0); |
172 | | - }) != std::end(language::es); |
173 | | - }); |
174 | | - |
| 177 | + const auto intersection = intersects(language::it, language::es); |
175 | 178 | BOOST_REQUIRE(!intersection); |
176 | 179 | } |
177 | 180 |
|
178 | 181 | BOOST_AUTO_TEST_CASE(mnemonic__dictionary__fr_it__no_intersection) |
179 | 182 | { |
180 | | - const auto intersection = std::any_of(language::fr.begin(), language::fr.end(), |
181 | | - [&](const char* test_right) |
182 | | - { |
183 | | - return std::find_if(language::it.begin(), language::it.end(), |
184 | | - [&](const char test_left[]) |
185 | | - { |
186 | | - return (std::strcmp(test_left, test_right) == 0); |
187 | | - })!= std::end(language::it); |
188 | | - }); |
189 | | - |
| 183 | + const auto intersection = intersects(language::fr, language::it); |
190 | 184 | BOOST_REQUIRE(!intersection); |
191 | 185 | } |
192 | 186 |
|
193 | 187 | BOOST_AUTO_TEST_CASE(mnemonic__dictionary__cs_pt__no_intersection) |
194 | 188 | { |
195 | | - const auto intersection = std::any_of(language::cs.begin(), language::cs.end(), |
196 | | - [&](const char* test_right) |
197 | | - { |
198 | | - return std::find_if(language::pt.begin(), language::pt.end(), |
199 | | - [&](const char test_left[]) |
200 | | - { |
201 | | - return (std::strcmp(test_left, test_right) == 0); |
202 | | - }) != std::end(language::pt); |
203 | | - }); |
204 | | - |
| 189 | + const auto intersection = intersects(language::cs, language::pt); |
205 | 190 | BOOST_REQUIRE(!intersection); |
206 | 191 | } |
207 | 192 |
|
208 | 193 | BOOST_AUTO_TEST_CASE(mnemonic__dictionary__ko_zh_Hans__no_intersection) |
209 | 194 | { |
210 | | - const auto intersection = std::any_of(language::ko.begin(), language::ko.end(), |
211 | | - [&](const char* test_right) |
212 | | - { |
213 | | - return std::find_if(language::zh_Hans.begin(), language::zh_Hans.end(), |
214 | | - [&](const char test_left[]) |
215 | | - { |
216 | | - return (std::strcmp(test_left, test_right) == 0); |
217 | | - }) != std::end(language::zh_Hans); |
218 | | - }); |
219 | | - |
| 195 | + const auto intersection = intersects(language::ko, language::zh_Hans); |
220 | 196 | BOOST_REQUIRE(!intersection); |
221 | 197 | } |
222 | 198 |
|
223 | 199 | BOOST_AUTO_TEST_CASE(mnemonic__dictionary__zh_Hans_Hant__1275_intersections) |
224 | 200 | { |
225 | | - const auto intersections = std::count_if(language::zh_Hans.begin(), language::zh_Hans.end(), |
226 | | - [&](const char* test_right) |
227 | | - { |
228 | | - return std::find_if(language::zh_Hant.begin(), language::zh_Hant.end(), |
229 | | - [&](const char test_left[]) |
230 | | - { |
231 | | - return (std::strcmp(test_left, test_right) == 0); |
232 | | - }) != std::end(language::zh_Hant); |
233 | | - }); |
234 | | - |
| 201 | + const auto intersections = intersection_count(language::zh_Hans, language::zh_Hant); |
235 | 202 | BOOST_REQUIRE_EQUAL(intersections, 1275u); |
236 | 203 | } |
237 | 204 |
|
|
0 commit comments