package maths import ( "exp/bignum" "testing" ) var dataBignum = map[uint] string { 0 : "1" , 1 : "1" , 2 : "2" , 3 : "6" , 4 : "24" , 5 : "120" , 6 : "720" , 7 : "5040" , 8 : "40320" , 9 : "362880" , 10 : "3628800" , 11 : "39916800" , 12 : "479001600" , 13 : "6227020800" , 14 : "87178291200" , 20 : "2432902008176640000" , 30 : "265252859812191058636308480000000" , 40 : "815915283247897734345611269596115894272000000000" , } func testFactorialBignumCorrectResults ( function func (uint) bignum.Natural , label string , t *testing.T ) { for parameter , expectedString := range dataBignum { expected , _ , _ := bignum.NatFromString ( expectedString , 10 ) if actual := function ( parameter ) ; actual.Cmp ( expected ) != 0 { t.Errorf ( "%s of %d failed, expected %s, got %s\n" , label , parameter , expectedString , actual.ToString ( 10 ) ) } } } func TestFactorialBignumCorrectIterative ( t *testing.T ) { testFactorialBignumCorrectResults ( factorial_bignum_iterative , "Iterative" , t ) } func TestFactorialBignumCorrectRecursive ( t *testing.T ) { testFactorialBignumCorrectResults ( factorial_bignum_recursive , "Recursive" , t ) } func TestFactorialBignumCorrectTailRecursive ( t *testing.T ) { testFactorialBignumCorrectResults ( factorial_bignum_tailRecursive , "Tail Recursive" , t ) }