Skip to content

Commit 904ed8e

Browse files
committedJul 1, 2023
add tests for basic vedic algo
1 parent 0d0e82c commit 904ed8e

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
 

‎tests/tests.cpp

+150
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,156 @@ TEST_CASE("Vedic multiplication") {
183183
}
184184
}
185185

186+
TEST_CASE("Basic Vedic multiplication") {
187+
SUBCASE("Single digit multiplication") {
188+
Mul calc("0", "1");
189+
CHECK_EQ(calc.basicVedic(), "0");
190+
191+
Mul calc1("0", "0");
192+
CHECK_EQ(calc1.basicVedic(), "0");
193+
194+
Mul calc2("9", "9");
195+
CHECK_EQ(calc2.basicVedic(), "81");
196+
}
197+
198+
SUBCASE("Strings are same length") {
199+
Mul calc("10", "16");
200+
CHECK_EQ(calc.basicVedic(), "160");
201+
202+
Mul calc1("849", "321");
203+
CHECK_EQ(calc1.basicVedic(), "272529");
204+
205+
Mul calc2("999 639 239", "995 639 737");
206+
CHECK_EQ(calc2.basicVedic(), "995280549012840143");
207+
}
208+
209+
SUBCASE("Strings are different length") {
210+
Mul calc("1043", "16");
211+
CHECK_EQ(calc.basicVedic(), "16688");
212+
213+
Mul calc1("943256", "3");
214+
CHECK_EQ(calc1.basicVedic(), "2829768");
215+
216+
Mul calc2("999 639 239", "995");
217+
CHECK_EQ(calc2.basicVedic(), "994641042805");
218+
}
219+
220+
SUBCASE("Large strings") {
221+
Mul calc1("999 639 239", "995 639 737");
222+
CHECK_EQ(calc1.basicVedic(), "995280549012840143");
223+
224+
Mul calc2("389257953890572905723057239572952952735027589027523",
225+
"34872974238375294329049085623563925632564392563290562369");
226+
CHECK_EQ(calc2.basicVedic(),
227+
"13574582598108627114973360345699834051651571386469912043240018567"
228+
"816426604207069012288725029059644489081987");
229+
Mul calc3(string(2000, '9'), string(5000, '1'));
230+
CHECK_EQ(
231+
calc3.basicVedic(),
232+
"1111111111111111111111111111111111111111111111111111111111111111111111"
233+
"1111111111111111111111111111111111111111111111111111111111111111111111"
234+
"1111111111111111111111111111111111111111111111111111111111111111111111"
235+
"1111111111111111111111111111111111111111111111111111111111111111111111"
236+
"1111111111111111111111111111111111111111111111111111111111111111111111"
237+
"1111111111111111111111111111111111111111111111111111111111111111111111"
238+
"1111111111111111111111111111111111111111111111111111111111111111111111"
239+
"1111111111111111111111111111111111111111111111111111111111111111111111"
240+
"1111111111111111111111111111111111111111111111111111111111111111111111"
241+
"1111111111111111111111111111111111111111111111111111111111111111111111"
242+
"1111111111111111111111111111111111111111111111111111111111111111111111"
243+
"1111111111111111111111111111111111111111111111111111111111111111111111"
244+
"1111111111111111111111111111111111111111111111111111111111111111111111"
245+
"1111111111111111111111111111111111111111111111111111111111111111111111"
246+
"1111111111111111111111111111111111111111111111111111111111111111111111"
247+
"1111111111111111111111111111111111111111111111111111111111111111111111"
248+
"1111111111111111111111111111111111111111111111111111111111111111111111"
249+
"1111111111111111111111111111111111111111111111111111111111111111111111"
250+
"1111111111111111111111111111111111111111111111111111111111111111111111"
251+
"1111111111111111111111111111111111111111111111111111111111111111111111"
252+
"1111111111111111111111111111111111111111111111111111111111111111111111"
253+
"1111111111111111111111111111111111111111111111111111111111111111111111"
254+
"1111111111111111111111111111111111111111111111111111111111111111111111"
255+
"1111111111111111111111111111111111111111111111111111111111111111111111"
256+
"1111111111111111111111111111111111111111111111111111111111111111111111"
257+
"1111111111111111111111111111111111111111111111111111111111111111111111"
258+
"1111111111111111111111111111111111111111111111111111111111111111111111"
259+
"1111111111111111111111111111111111111111111111111111111111111111111111"
260+
"1111111111111111111111111111111111111110999999999999999999999999999999"
261+
"9999999999999999999999999999999999999999999999999999999999999999999999"
262+
"9999999999999999999999999999999999999999999999999999999999999999999999"
263+
"9999999999999999999999999999999999999999999999999999999999999999999999"
264+
"9999999999999999999999999999999999999999999999999999999999999999999999"
265+
"9999999999999999999999999999999999999999999999999999999999999999999999"
266+
"9999999999999999999999999999999999999999999999999999999999999999999999"
267+
"9999999999999999999999999999999999999999999999999999999999999999999999"
268+
"9999999999999999999999999999999999999999999999999999999999999999999999"
269+
"9999999999999999999999999999999999999999999999999999999999999999999999"
270+
"9999999999999999999999999999999999999999999999999999999999999999999999"
271+
"9999999999999999999999999999999999999999999999999999999999999999999999"
272+
"9999999999999999999999999999999999999999999999999999999999999999999999"
273+
"9999999999999999999999999999999999999999999999999999999999999999999999"
274+
"9999999999999999999999999999999999999999999999999999999999999999999999"
275+
"9999999999999999999999999999999999999999999999999999999999999999999999"
276+
"9999999999999999999999999999999999999999999999999999999999999999999999"
277+
"9999999999999999999999999999999999999999999999999999999999999999999999"
278+
"9999999999999999999999999999999999999999999999999999999999999999999999"
279+
"9999999999999999999999999999999999999999999999999999999999999999999999"
280+
"9999999999999999999999999999999999999999999999999999999999999999999999"
281+
"9999999999999999999999999999999999999999999999999999999999999999999999"
282+
"9999999999999999999999999999999999999999999999999999999999999999999999"
283+
"9999999999999999999999999999999999999999999999999999999999999999999999"
284+
"9999999999999999999999999999999999999999999999999999999999999999999999"
285+
"9999999999999999999999999999999999999999999999999999999999999999999999"
286+
"9999999999999999999999999999999999999999999999999999999999999999999999"
287+
"9999999999999999999999999999999999999999999999999999999999999999999999"
288+
"9999999999999999999999999999999999999999999999999999999999999999999999"
289+
"9999999999999999999999999999999999999999999999999999999999999999999999"
290+
"9999999999999999999999999999999999999999999999999999999999999999999999"
291+
"9999999999999999999999999999999999999999999999999999999999999999999999"
292+
"9999999999999999999999999999999999999999999999999999999999999999999999"
293+
"9999999999999999999999999999999999999999999999999999999999999999999999"
294+
"9999999999999999999999999999999999999999999999999999999999999999999999"
295+
"9999999999999999999999999999999999999999999999999999999999999999999999"
296+
"9999999999999999999999999999999999999999999999999999999999999999999999"
297+
"9999999999999999999999999999999999999999999999999999999999999999999999"
298+
"9999999999999999999999999999999999999999999999999999999999999999999999"
299+
"9999999999999999999999999999999999999999999999999999999999999999999999"
300+
"9999999999999999999999999999999999999999999999999999999999999999999999"
301+
"9999999999999999999999999999999999999999999999999999999999999999999999"
302+
"9999999999999999999999999999999999999999999999999999999999999999999999"
303+
"9999999999999999999999999999998888888888888888888888888888888888888888"
304+
"8888888888888888888888888888888888888888888888888888888888888888888888"
305+
"8888888888888888888888888888888888888888888888888888888888888888888888"
306+
"8888888888888888888888888888888888888888888888888888888888888888888888"
307+
"8888888888888888888888888888888888888888888888888888888888888888888888"
308+
"8888888888888888888888888888888888888888888888888888888888888888888888"
309+
"8888888888888888888888888888888888888888888888888888888888888888888888"
310+
"8888888888888888888888888888888888888888888888888888888888888888888888"
311+
"8888888888888888888888888888888888888888888888888888888888888888888888"
312+
"8888888888888888888888888888888888888888888888888888888888888888888888"
313+
"8888888888888888888888888888888888888888888888888888888888888888888888"
314+
"8888888888888888888888888888888888888888888888888888888888888888888888"
315+
"8888888888888888888888888888888888888888888888888888888888888888888888"
316+
"8888888888888888888888888888888888888888888888888888888888888888888888"
317+
"8888888888888888888888888888888888888888888888888888888888888888888888"
318+
"8888888888888888888888888888888888888888888888888888888888888888888888"
319+
"8888888888888888888888888888888888888888888888888888888888888888888888"
320+
"8888888888888888888888888888888888888888888888888888888888888888888888"
321+
"8888888888888888888888888888888888888888888888888888888888888888888888"
322+
"8888888888888888888888888888888888888888888888888888888888888888888888"
323+
"8888888888888888888888888888888888888888888888888888888888888888888888"
324+
"8888888888888888888888888888888888888888888888888888888888888888888888"
325+
"8888888888888888888888888888888888888888888888888888888888888888888888"
326+
"8888888888888888888888888888888888888888888888888888888888888888888888"
327+
"8888888888888888888888888888888888888888888888888888888888888888888888"
328+
"8888888888888888888888888888888888888888888888888888888888888888888888"
329+
"8888888888888888888888888888888888888888888888888888888888888888888888"
330+
"8888888888888888888888888888888888888888888888888888888888888888888888"
331+
"888888888888888888888888888888888888888888888888888888888888888888888"
332+
"9");
333+
}
334+
}
335+
186336
TEST_CASE("Karatsuba multiplication") {
187337
SUBCASE("Single digit multiplication") {
188338
Mul calc("0", "1");

0 commit comments

Comments
 (0)
Please sign in to comment.