-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactorization_test.go
More file actions
51 lines (45 loc) · 904 Bytes
/
factorization_test.go
File metadata and controls
51 lines (45 loc) · 904 Bytes
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
package powclient
import (
"fmt"
"math/big"
"strings"
"testing"
"time"
)
func TestFactors(t *testing.T) {
p1 := big.NewInt(24801309629)
p2 := big.NewInt(34244502967)
input := (new(big.Int).Mul(p1, p2)).String()
input = strings.TrimSuffix(input, "\n")
N := new(big.Int)
N.SetString(input, 10)
// Start timer
start := time.Now()
// Calculation
factorsList := factors(N)
// End timer
elapsed := time.Since(start)
// Output results
for _, factor := range factorsList {
fmt.Println(factor)
}
fmt.Printf("Elapsed time: %s\n", elapsed)
expected := []*big.Int{
p1,
p2,
}
if !equalSlices(factorsList, expected) {
t.Errorf("factorsList does not match expected values")
}
}
func equalSlices(slice1, slice2 []*big.Int) bool {
if len(slice1) != len(slice2) {
return false
}
for i := range slice1 {
if slice1[i].Cmp(slice2[i]) != 0 {
return false
}
}
return true
}