-
Notifications
You must be signed in to change notification settings - Fork 1
/
karatsuba_test.go
57 lines (50 loc) · 1.48 KB
/
karatsuba_test.go
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
package karatsuba
import "testing"
func TestSub(t *testing.T) {
a := "5678"
b := "1234"
correct := "4444"
if prod := sub(a, b); prod != correct {
t.Fatal(a, "*", b, "is incorrect, expected:", correct, "received:", prod)
}
}
func Test2Digit(t *testing.T) {
a := "12"
b := "43"
correct := "516"
if prod := Multiply(a, b); prod != correct {
t.Fatal(a, "*", b, "is incorrect, expected:", correct, "received:", prod)
}
}
func Test4Digit(t *testing.T) {
a := "1234"
b := "5678"
correct := "7006652"
if prod := Multiply(a, b); prod != correct {
t.Fatal(a, "*", b, "is incorrect, expected:", correct, "received:", prod)
}
}
func Test4DigitSimple(t *testing.T) {
a := "1234"
b := "4321"
correct := "5332114"
if prod := Multiply(a, b); prod != correct {
t.Fatal(a, "*", b, "is incorrect, expected:", correct, "received:", prod)
}
}
func Test64Digit(t *testing.T) {
a := "3141592653589793238462643383279502884197169399375105820974944592"
b := "2718281828459045235360287471352662497757247093699959574966967627"
correct := "8539734222673567065463550869546574495034888535765114961879601127067743044893204848617875072216249073013374895871952806582723184"
if prod := Multiply(a, b); prod != correct {
t.Fatal(a, "*", b, "is incorrect, expected:", correct, "received:", prod)
}
}
func TestUnevenDigits(t *testing.T) {
a := "123"
b := "4567"
correct := "561741"
if prod := Multiply(a, b); prod != correct {
t.Fatal(a, "*", b, "is incorrect, expected:", correct, "received:", prod)
}
}