func TestMethod(t *testing.T) { s := swing.New(tcs[len(tcs)-1].n) var f big.Int for _, tc := range tcs { if sf := s.SwingingFactorial(&f, tc.n).String(); sf != tc.s { t.Errorf("wrong swinging factorial for %d. Expected %s, got %s:", tc.n, tc.s, sf) } } }
func TestSmallOdd(t *testing.T) { s0 := swing.SmallOddSwing swing.SmallOddSwing = nil s := swing.New(uint(len(s0))) var f big.Int for n := 4; n < len(s0); n++ { if sc := s.OddSwing(&f, uint(n)).Int64(); sc != s0[n] { t.Errorf("SmallOddSwing(%d) expected %d, got %d", n, s0[n], sc) } } swing.SmallOddSwing = s0 }
func TestDoubleFactorialS(t *testing.T) { p := swing.New(tcs[len(tcs)-1].n + 1) d := new(big.Int) answer := new(big.Int) for _, tc := range tcs { if _, ok := answer.SetString(tc.s, 10); !ok { t.Error("invalid test case", tc) continue } switch _ = double.DoubleFactorialS(d, p, tc.n); { case d == nil: t.Error("nil result. test case", tc) case d.Cmp(answer) != 0: t.Log("wrong answer, test case", tc) t.Error("got", answer) } } }
"testing" "github.com/soniakeys/integer/factorial/prime" "github.com/soniakeys/integer/swing" ) func TestPrime(t *testing.T) { var f big.Int for _, tc := range tcs { if fs := prime.Factorial(&f, tc.n).String(); fs != tc.s { t.Errorf("%d! incorrect. expected %s, got %s", tc.n, tc.s, fs) } } } var ps = swing.New(1e5) func TestPrimeS(t *testing.T) { var f big.Int for _, tc := range tcs { if fs := prime.FactorialS(&f, ps, tc.n).String(); fs != tc.s { t.Errorf("%d! incorrect. expected %s, got %s", tc.n, tc.s, fs) } } } func Benchmark1e2(b *testing.B) { var f big.Int for i := 0; i < b.N; i++ { prime.Factorial(&f, 1e2) }
// Factorial computes n!, leaving the result in z. func Factorial(z *big.Int, n uint) *big.Int { return FactorialS(z, swing.New(n), n) }
func init() { s = swing.New(2e5) }
func BenchmarkFunction1e5(b *testing.B) { var f big.Int for i := 0; i < b.N; i++ { swing.SwingingFactorial(&f, 1e5) } } func BenchmarkFunction1e6(b *testing.B) { var f big.Int for i := 0; i < b.N; i++ { swing.SwingingFactorial(&f, 1e6) } } var s = swing.New(1e6) func BenchmarkMethod1e2(b *testing.B) { var f big.Int for i := 0; i < b.N; i++ { s.SwingingFactorial(&f, 1e2) } } func BenchmarkMethod1e3(b *testing.B) { var f big.Int for i := 0; i < b.N; i++ { s.SwingingFactorial(&f, 1e3) } }