#! /usr/bin/env groovyt import static org.testng.Assert.assertEquals class Factorial_J_BigInteger_TestNGroove { @DataProvider ( name = "theData" ) public Object[][] createData ( ) { [ [ 0G , 1G ] , [ 1G , 1G ] , [ 2G , 2G ] , [ 3G , 6G ] , [ 4G , 24G ] , [ 5G , 120G ] , [ 6G , 720G ] , [ 7G , 5040G ] , [ 8G , 40320G ] , [ 9G , 362880G ] , [ 10G , 3628800G ] , [ 11G , 39916800G ] , [ 12G , 479001600G ] , [ 13G , 6227020800G ] , [ 14G , 87178291200G ] , [ 20G , 2432902008176640000G ] , [ 30G , 265252859812191058636308480000000G ] , [ 40G , 815915283247897734345611269596115894272000000000G ] ] as Object[][] } @Test ( dataProvider = "theData" ) public void correctIterative ( BigInteger n , BigInteger expected ) { assertEquals ( expected , Factorial_J_BigInteger.iterative ( n ) ) ; } @Test ( dataProvider = "theData" ) public void correctRecursive ( BigInteger n , BigInteger expected ) { assertEquals ( expected , Factorial_J_BigInteger.recursive ( n ) ) ; } @Test ( dataProvider = "theData" ) public void correctTailRecursive ( BigInteger n , BigInteger expected ) { assertEquals ( expected , Factorial_J_BigInteger.tailRecursive ( n ) ) ; } @DataProvider ( name = "theNegative" ) public Object[][] createNegative ( ) { [ [ -20G ] , [ -15G ] , [ -10G ] , [ -5G ] , [ -2G ] , [ -1G ] ] as Object[][] } @Test ( dataProvider = "theNegative" , expectedExceptions = [ FactorialIllegalArgumentException ] ) public void negativeIterative ( BigInteger n ) { Factorial_J_BigInteger.iterative ( n ) ; } @Test ( dataProvider = "theNegative" , expectedExceptions = [ FactorialIllegalArgumentException ] ) public void negativeRecursive ( BigInteger n ) { Factorial_J_BigInteger.recursive ( n ) ; } @Test ( dataProvider = "theNegative" , expectedExceptions = [ FactorialIllegalArgumentException ] ) public void negativeTailRecursive ( BigInteger n ) { Factorial_J_BigInteger.tailRecursive ( n ) ; } @Test public void iterativeEnormousSucceeds ( ) { Factorial_J_BigInteger.iterative ( 10000 ) ; } @Test ( expectedExceptions = [ StackOverflowError ] ) public void recursiveEnormousSucceeds ( ) { Factorial_J_BigInteger.recursive ( 8500 ) ; } @Test ( expectedExceptions = [ StackOverflowError ] ) public void tailRecursiveEnormousSucceeds ( ) { Factorial_J_BigInteger.tailRecursive ( 8700 ) ; } @DataProvider ( name = "theFloats" ) public Object[][] createFloats ( ) { [ [ -20.5 ] , [ -15.5 ] , [ 10.5 ] , [ 5.5 ] ] as Object[][] } @Test ( dataProvider = "theFloats" , expectedExceptions = [ MissingMethodException ] ) public void floatingPointIterative ( n ) { Factorial_J_BigInteger.iterative ( n ) ; } @Test ( dataProvider = "theFloats" , expectedExceptions = [ MissingMethodException ] ) public void floatingPointRecursive ( n ) { Factorial_J_BigInteger.recursive ( n ) ; } @Test ( dataProvider = "theFloats" , expectedExceptions = [ MissingMethodException ] ) public void floatingPointTailRecursive ( n ) { Factorial_J_BigInteger.tailRecursive ( n ) ; } }