#! /usr/bin/env groovyt //import static org.testng.Assert.assertEquals import org.testng.Assert class Factorial_BigInteger_TestNGroove { def data = [ [ 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 , 6227020800G ] , // Have to force the correct type here for some reason. [ 14 , 87178291200G ] , // Have to force the correct type here for some reason. [ 20 , 2432902008176640000G ] , // Have to force the correct type here for some reason. [ 30 , 265252859812191058636308480000000 ] , [ 40 , 815915283247897734345611269596115894272000000000 ] ] @Test void correctIterative ( ) { data.each { datum -> Assert.assertEquals ( datum[1] , Factorial_BigInteger.iterative ( datum[0] ) ) } } @Test void correctRecursive ( ) { data.each { datum -> Assert.assertEquals ( datum[1] , Factorial_BigInteger.recursive ( datum[0] ) ) } } @Test ( expectedExceptions = [ RuntimeException ] ) void negativeIterative ( ) { ( -20 .. -1 ).each { i -> Factorial_BigInteger.iterative ( i ) } } @Test ( expectedExceptions = [ RuntimeException ] ) void negativeRecursive ( ) { ( -20 .. -1 ).each { i -> Factorial_BigInteger.recursive ( i ) } } @Test ( expectedExceptions = [ MissingMethodException ] ) void floatingPointIterative ( ) { ( -12 .. 2 ).each { i -> Factorial_BigInteger.iterative ( i + 0.5 ) } } @Test ( expectedExceptions = [ MissingMethodException ] ) void floatingPointRecursive ( ) { ( -12 .. 2 ).each { i -> Factorial_BigInteger.recursive ( i + 0.5 ) } } }