MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestRho

Function TestRho

math/pollard_test.go:35–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func TestRho(t *testing.T) {
36 tests := []struct {
37 name string
38 n *big.Int
39 g func(n *big.Int) func(*big.Int) *big.Int
40 want *big.Int
41 wantErr bool
42 }{
43 {"Factor of n: 11235 ", big.NewInt(11235), DefaultPolynomial, big.NewInt(21), false},
44 {"Factor of n: 111155 ", big.NewInt(111155), DefaultPolynomial, big.NewInt(11), false},
45 {"Factor of n: 8080 ", big.NewInt(8080), DefaultPolynomial, big.NewInt(16), false},
46 {"Factor of n: 8536 ", big.NewInt(8536), DefaultPolynomial, big.NewInt(88), false},
47 {"Factor of n: 666 ", big.NewInt(666), DefaultPolynomial, big.NewInt(3), false},
48 {"Factor of n: 2 ", big.NewInt(2), DefaultPolynomial, big.NewInt(2), true},
49 }
50 for _, test := range tests {
51 t.Run(test.name, func(t *testing.T) {
52 got, err := PollardsRhoFactorization(test.n, test.g)
53 if err != nil && !test.wantErr {
54 t.Errorf("PollardsRhoFactorization() error = %v, wantErr %v", err, test.wantErr)
55 return
56 } else if err != nil && test.wantErr {
57 return
58 }
59 if !reflect.DeepEqual(got, test.want) {
60 t.Errorf("PollardsRhoFactorization() got = %v, want %v", got, test.want)
61 }
62 })
63 }
64}
65
66func BenchmarkDefaultPolynomial(b *testing.B) {
67 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 1

PollardsRhoFactorizationFunction · 0.85

Tested by

no test coverage detected