/** Example of using unit tests for this assignment. To run them on the command line, make * sure that the junit-cs211.jar is in the same directory. * * On Mac/Linux: * javac -cp .:junit-cs211.jar *.java # compile everything * java -cp .:junit-cs211.jar P1tester # run tests * * On windows replace colons with semicolons: (: with ;) * demo$ javac -cp .;junit-cs211.jar *.java # compile everything * demo$ java -cp .;junit-cs211.jar P1tester # run tests */ import org.junit.*; import static org.junit.Assert.*; import java.util.*; public class P1tester { public static void main(String args[]){ org.junit.runner.JUnitCore.main("P1tester"); } @Test public void mathtoolbox_isPrime_01() { assertEquals( false, MathToolbox.isPrime( 1 ) ); } @Test public void mathtoolbox_isPrime_02() { assertEquals( true, MathToolbox.isPrime( 2 ) ); } @Test public void mathtoolbox_isPrime_03() { assertEquals( true, MathToolbox.isPrime( 3 ) ); } @Test public void mathtoolbox_isPrime_04() { assertEquals( false, MathToolbox.isPrime( 4 ) ); } @Test public void mathtoolbox_isPrime_05() { assertEquals( true, MathToolbox.isPrime( 5 ) ); } @Test public void mathtoolbox_numPrimes_01() { assertEquals( 1, MathToolbox.numPrimes( 2,2 ) ); } @Test public void mathtoolbox_numPrimes_02() { assertEquals( 2, MathToolbox.numPrimes( 2,3 ) ); } @Test public void mathtoolbox_numPrimes_03() { assertEquals( 2, MathToolbox.numPrimes( 2,4 ) ); } @Test public void mathtoolbox_numPrimes_04() { assertEquals( 3, MathToolbox.numPrimes( 2,5 ) ); } @Test public void mathtoolbox_numPrimes_05() { assertEquals( 1, MathToolbox.numPrimes( 3,3 ) ); } @Test public void mathtoolbox_numPrimes_06() { assertEquals( 1, MathToolbox.numPrimes( 3,4 ) ); } @Test public void mathtoolbox_numPrimes_07() { assertEquals( 2, MathToolbox.numPrimes( 3,5 ) ); } @Test public void mathtoolbox_numPrimes_08() { assertEquals( 0, MathToolbox.numPrimes( 4,4 ) ); } @Test public void mathtoolbox_numPrimes_09() { assertEquals( 1, MathToolbox.numPrimes( 4,5 ) ); } @Test public void mathtoolbox_numPrimes_10() { assertEquals( 1, MathToolbox.numPrimes( 5,5 ) ); } @Test public void mathtoolbox_factorial_01() { assertEquals( 1, MathToolbox.factorial( 0 ) ); } @Test public void mathtoolbox_factorial_02() { assertEquals( 1, MathToolbox.factorial( 1 ) ); } @Test public void mathtoolbox_factorial_03() { assertEquals( 2, MathToolbox.factorial( 2 ) ); } @Test public void mathtoolbox_factorial_04() { assertEquals( 6, MathToolbox.factorial( 3 ) ); } @Test public void mathtoolbox_factorial_05() { assertEquals( 24, MathToolbox.factorial( 4 ) ); } @Test public void mathtoolbox_sumPower_01() { assertEquals( 1, MathToolbox.sumPower( 1,1 ), 0.0001 ); } @Test public void mathtoolbox_sumPower_02() { assertEquals( 3, MathToolbox.sumPower( 2,1 ), 0.0001 ); } @Test public void mathtoolbox_sumPower_03() { assertEquals( 6, MathToolbox.sumPower( 3,1 ), 0.0001 ); } @Test public void mathtoolbox_sumPower_04() { assertEquals( 10, MathToolbox.sumPower( 4,1 ), 0.0001 ); } @Test public void mathtoolbox_sumPower_05() { assertEquals( 1, MathToolbox.sumPower( 1,2 ), 0.0001 ); } @Test public void mathtoolbox_sumPower_06() { assertEquals( 5, MathToolbox.sumPower( 2,2 ), 0.0001 ); } @Test public void mathtoolbox_sumPower_07() { assertEquals( 14, MathToolbox.sumPower( 3,2 ), 0.0001 ); } @Test public void mathtoolbox_sumPower_08() { assertEquals( 30, MathToolbox.sumPower( 4,2 ), 0.0001 ); } @Test public void mathtoolbox_boundedSum_01() { assertEquals( 1, MathToolbox.boundedSum( new int[]{4,3,2,1}, 1,1 ) ); } @Test public void mathtoolbox_boundedSum_02() { assertEquals( 3, MathToolbox.boundedSum( new int[]{4,3,2,1}, 1,2 ) ); } @Test public void mathtoolbox_boundedSum_03() { assertEquals( 6, MathToolbox.boundedSum( new int[]{4,3,2,1}, 1,3 ) ); } @Test public void mathtoolbox_boundedSum_04() { assertEquals( 10, MathToolbox.boundedSum( new int[]{4,3,2,1}, 1,4 ) ); } @Test public void mathtoolbox_boundedSum_05() { assertEquals( 2, MathToolbox.boundedSum( new int[]{4,3,2,1}, 2,2 ) ); } @Test public void mathtoolbox_boundedSum_06() { assertEquals( 5, MathToolbox.boundedSum( new int[]{4,3,2,1}, 2,3 ) ); } @Test public void mathtoolbox_boundedSum_07() { assertEquals( 9, MathToolbox.boundedSum( new int[]{4,3,2,1}, 2,4 ) ); } @Test public void mathtoolbox_boundedSum_08() { assertEquals( 3, MathToolbox.boundedSum( new int[]{4,3,2,1}, 3,3 ) ); } @Test public void mathtoolbox_boundedSum_09() { assertEquals( 7, MathToolbox.boundedSum( new int[]{4,3,2,1}, 3,4 ) ); } @Test public void mathtoolbox_boundedSum_10() { assertEquals( 4, MathToolbox.boundedSum( new int[]{4,3,2,1}, 4,4 ) ); } @Test public void mathtoolbox_filteredSum_01() { assertEquals( 0.0, MathToolbox.filteredSum( new double[]{1.0,2.0,3.0}, new double[]{0.0,0.0,0.0} ), 0.001 ); } @Test public void mathtoolbox_filteredSum_02() { assertEquals( 1.0, MathToolbox.filteredSum( new double[]{1.0,2.0,3.0}, new double[]{1.0,0.0,0.0} ), 0.001 ); } @Test public void mathtoolbox_filteredSum_03() { assertEquals( 2.0, MathToolbox.filteredSum( new double[]{1.0,2.0,3.0}, new double[]{0.0,1.0,0.0} ), 0.001 ); } @Test public void mathtoolbox_filteredSum_04() { assertEquals( 3.0, MathToolbox.filteredSum( new double[]{1.0,2.0,3.0}, new double[]{0.0,0.0,1.0} ), 0.001 ); } @Test public void mathtoolbox_filteredSum_05() { assertEquals( 3.0, MathToolbox.filteredSum( new double[]{1.0,2.0,3.0}, new double[]{1.0,1.0,0.0} ), 0.001 ); } @Test public void mathtoolbox_filteredSum_06() { assertEquals( 4.0, MathToolbox.filteredSum( new double[]{1.0,2.0,3.0}, new double[]{1.0,0.0,1.0} ), 0.001 ); } @Test public void mathtoolbox_filteredSum_07() { assertEquals( 5.0, MathToolbox.filteredSum( new double[]{1.0,2.0,3.0}, new double[]{0.0,1.0,1.0} ), 0.001 ); } @Test public void mathtoolbox_filteredSum_08() { assertEquals( 6.0, MathToolbox.filteredSum( new double[]{1.0,2.0,3.0}, new double[]{1.0,1.0,1.0} ), 0.001 ); } @Test public void mathtoolbox_geometricMean_01() { assertEquals( 1.0, MathToolbox.geometricMean( new double[]{1.0} ), 0.001 ); } @Test public void mathtoolbox_geometricMean_02() { assertEquals( 2.0, MathToolbox.geometricMean( new double[]{1.0,4.0} ), 0.001 ); } @Test public void mathtoolbox_geometricMean_03() { assertEquals( 6.0, MathToolbox.geometricMean( new double[]{1.0,4.0,54.0} ), 0.001 ); } @Test public void mathtoolbox_geometricMean_04() { assertEquals( 12.0, MathToolbox.geometricMean( new double[]{1.0,4.0,54.0,96.0} ), 0.001 ); } @Test public void mathtoolbox_geometricMean_05() { assertEquals( 12.0, MathToolbox.geometricMean( new double[]{1.0,4.0,54.0,96.0,12.0} ), 0.001 ); } @Test public void mathtoolbox_largestConsecutiveDiff_01() { assertEquals( 0, MathToolbox.largestConsecutiveDiff( new int[]{} ) ); } @Test public void mathtoolbox_largestConsecutiveDiff_02() { assertEquals( 0, MathToolbox.largestConsecutiveDiff( new int[]{5} ) ); } @Test public void mathtoolbox_largestConsecutiveDiff_03() { assertEquals( 1, MathToolbox.largestConsecutiveDiff( new int[]{5,6} ) ); } @Test public void mathtoolbox_largestConsecutiveDiff_04() { assertEquals( 1, MathToolbox.largestConsecutiveDiff( new int[]{5,6,4} ) ); } @Test public void mathtoolbox_largestConsecutiveDiff_05() { assertEquals( 3, MathToolbox.largestConsecutiveDiff( new int[]{5,6,4,7} ) ); } @Test public void mathtoolbox_largestConsecutiveDiff_06() { assertEquals( 8, MathToolbox.largestConsecutiveDiff( new int[]{5,6,4,7,15} ) ); } @Test public void mathtoolbox_largestElementWithDups_01() { assertEquals( Integer.MIN_VALUE, MathToolbox.largestElementWithDups( new int[]{1} ) ); } @Test public void mathtoolbox_largestElementWithDups_02() { assertEquals( Integer.MIN_VALUE, MathToolbox.largestElementWithDups( new int[]{1,2} ) ); } @Test public void mathtoolbox_largestElementWithDups_03() { assertEquals( 1, MathToolbox.largestElementWithDups( new int[]{1,2,1} ) ); } @Test public void mathtoolbox_largestElementWithDups_04() { assertEquals( 2, MathToolbox.largestElementWithDups( new int[]{1,2,1,2} ) ); } @Test public void mathtoolbox_largestElementWithDups_05() { assertEquals( 2, MathToolbox.largestElementWithDups( new int[]{1,2,1,2,1} ) ); } @Test public void mathtoolbox_largestElementWithDups_06() { assertEquals( 2, MathToolbox.largestElementWithDups( new int[]{1,2,1,2,1,5} ) ); } @Test public void mathtoolbox_largestElementWithDups_07() { assertEquals( 5, MathToolbox.largestElementWithDups( new int[]{1,2,1,2,1,5,5} ) ); } @Test public void mathtoolbox_findElementFreqs_01() { int[] freqs = new int[0]; MathToolbox.findElementFreqs( new int[]{}, freqs ); assertArrayEquals( new int[]{}, freqs ); } @Test public void mathtoolbox_findElementFreqs_02() { int[] freqs = new int[1]; MathToolbox.findElementFreqs( new int[]{1}, freqs ); assertArrayEquals( new int[]{1}, freqs ); } @Test public void mathtoolbox_findElementFreqs_03() { int[] freqs = new int[2]; MathToolbox.findElementFreqs( new int[]{1,2}, freqs ); assertArrayEquals( new int[]{1,1}, freqs ); } @Test public void mathtoolbox_findElementFreqs_04() { int[] freqs = new int[3]; MathToolbox.findElementFreqs( new int[]{1,2,1}, freqs ); assertArrayEquals( new int[]{2,1,2}, freqs ); } @Test public void mathtoolbox_findElementFreqs_05() { int[] freqs = new int[4]; MathToolbox.findElementFreqs( new int[]{1,2,1,2}, freqs ); assertArrayEquals( new int[]{2,2,2,2}, freqs ); } @Test public void mathtoolbox_findElementFreqs_06() { int[] freqs = new int[5]; MathToolbox.findElementFreqs( new int[]{1,2,1,2,1}, freqs ); assertArrayEquals( new int[]{3,2,3,2,3}, freqs ); } }