37 lines
1.6 KiB
Go
37 lines
1.6 KiB
Go
package primes
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestFactorize(t *testing.T) {
|
|
assert.Equal(t, []Factor{}, Factorize(-1))
|
|
assert.Equal(t, []Factor{}, Factorize(0))
|
|
assert.Equal(t, []Factor{{1, 1}}, Factorize(1))
|
|
assert.Equal(t, []Factor{{2, 1}, {5, 1}}, Factorize(10))
|
|
assert.Equal(t, []Factor{{3, 1}, {7, 2}}, Factorize(147))
|
|
assert.Equal(t, []Factor{{3, 1}, {7, 1}, {11, 1}, {13, 1}, {37, 1}}, Factorize(111111))
|
|
assert.Equal(t, []Factor{{7, 2}, {73, 1}, {127, 1}, {337, 1}, {92737, 1}, {649657, 1}}, Factorize(9223372036854775807))
|
|
// assert.Equal(t, []Factor{{11, 1}, {41, 1}, {101, 1}, {271, 1}, {3541, 1}, {9091, 1}, {27961, 1}}, Factorize(11111111111111111111))
|
|
}
|
|
|
|
func stringToBigInt(s string) *big.Int {
|
|
var i = big.NewInt(0)
|
|
i, _ = i.SetString(s, 10)
|
|
return i
|
|
}
|
|
|
|
func TestFactorizeBigInt(t *testing.T) {
|
|
assert.Equal(t, []Factor{}, FactorizeBigInt(big.NewInt(-1)))
|
|
assert.Equal(t, []Factor{}, FactorizeBigInt(big.NewInt(0)))
|
|
assert.Equal(t, []Factor{{1, 1}}, FactorizeBigInt(big.NewInt(1)))
|
|
assert.Equal(t, []Factor{{2, 1}, {5, 1}}, FactorizeBigInt(big.NewInt(10)))
|
|
assert.Equal(t, []Factor{{3, 1}, {7, 2}}, FactorizeBigInt(big.NewInt(147)))
|
|
assert.Equal(t, []Factor{{3, 1}, {7, 1}, {11, 1}, {13, 1}, {37, 1}}, FactorizeBigInt(big.NewInt(111111)))
|
|
assert.Equal(t, []Factor{{7, 2}, {73, 1}, {127, 1}, {337, 1}, {92737, 1}, {649657, 1}}, FactorizeBigInt(big.NewInt(9223372036854775807)))
|
|
assert.Equal(t, []Factor{{11, 1}, {41, 1}, {101, 1}, {271, 1}, {3541, 1}, {9091, 1}, {27961, 1}}, FactorizeBigInt(stringToBigInt("11111111111111111111")))
|
|
}
|