Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CodeCampTester {
- // test the CodeCamp methods
- public static void main(String[] args) {
- // CS314 Students: add tests here.
- // staring time of the program
- double startTime = System.nanoTime();
- // test 1, hammingDistance
- int[] h1 = {12, 15, 1298, 4892, 2984, 209374, 904378, 23947, 239047, 15};
- int[] h2 = {12, 16, 1298, 4891, 2984, 209373, 902378, 23947, 239047, 15};
- int expected = 4;
- int actual = CodeCamp.hammingDistance(h1, h2);
- System.out.println("Test 1 hamming distance: expected value: " +
- expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 1, hamming distance");
- else
- System.out.println(" ***** FAILED ***** test 1, hamming distance");
- System.out.println();
- // test 2, hammingDistance
- h1 = new int[]{1, 2, 3, 4, 5, 5, 7, 8, 9, 10};
- h2 = new int[]{10, 9, 8, 7, 5, 5, 4, 3, 2, 1};
- expected = 8;
- actual = CodeCamp.hammingDistance(h1, h2);
- System.out.println("Test 2 hamming distance: expected value: " +
- expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 2, hamming distance");
- else
- System.out.println(" ***** FAILED ***** test 2, hamming distance");
- System.out.println();
- // test 3, hammingDistance
- h1 = new int[]{Integer.MAX_VALUE, Integer.MIN_VALUE};
- h2 = new int[]{Integer.MIN_VALUE, Integer.MAX_VALUE};
- expected = 2;
- actual = CodeCamp.hammingDistance(h1, h2);
- System.out.println("Test 3 hamming distance: expected value: " +
- expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 3, hamming distance");
- else
- System.out.println(" ***** FAILED ***** test 3, hamming distance");
- System.out.println();
- // test 4, hammingDistance
- h1 = new int[]{Integer.MAX_VALUE, Integer.MIN_VALUE, 0, 150000, Integer.MAX_VALUE / 2};
- h2 = new int[]{100000, Integer.MIN_VALUE, Integer.MAX_VALUE / 2, 150000, Integer.MIN_VALUE};
- expected = 3;
- actual = CodeCamp.hammingDistance(h1, h2);
- System.out.println("Test 4 hamming distance: expected value: " +
- expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 4, hamming distance");
- else
- System.out.println(" ***** FAILED ***** test 4, hamming distance");
- System.out.println();
- // test 5, hammingDistance
- h1 = new int[1_000_000];
- h2 = new int[1_000_000];
- expected = 0;
- actual = CodeCamp.hammingDistance(h1, h2);
- System.out.println("Test 5 hamming distance: expected value: " +
- expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 5, hamming distance");
- else
- System.out.println(" ***** FAILED ***** test 5, hamming distance");
- System.out.println();
- // test 6, isPermutation
- int[] a = {1, 2, 3, 3};
- int[] b = {3, 1, 2, 2};
- boolean expectedBool = false;
- boolean actualBool = CodeCamp.isPermutation(a, b);
- System.out.println("Test 6 isPermutation: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 6, isPermutation");
- else
- System.out.println(" ***** FAILED ***** test 6, isPermutation");
- System.out.println();
- // test 7, isPermutation
- a = new int[]{-997745, -991903, -979457, -972533, -971699, -913892, -889505,
- -884203, -866389, -859120, -851847, -841195, -838661, -828111, -764839,
- -763320, -745368, -727461, -723405, -719959, -684708, -675999, -650649,
- -629126, -613501, -609845, -581608, -570814, -549586, -540889, -536376,
- -506601, -468543, -467745, -448140, -413413, -393419, -335961, -321413,
- -312832, -312515, -304480, -298484, -294319, -219324, -200239, -177542,
- -147883, -57512, -15793, -4979, 11019, 12252, 34479, 44935, 47827, 56294,
- 64975, 81392, 91511, 127266, 166845, 175957, 194797, 207948, 218361, 235178,
- 250571, 316758, 330954, 358810, 399433, 403966, 408021, 420420, 433881, 437965,
- 472889, 481623, 485870, 613794, 660668, 679110, 679909, 694653, 706254, 720663,
- 744798, 754379, 770462, 775620, 833344, 856080, 867107, 907323, 923154, 933838,
- 938729, 961192, 982985};
- b = new int[] {250571, 316758, 330954, 358810, 399433, 403966, 408021, 420420, 433881, 437965,
- -884203, -866389, -859120, -851847, -841195, -838661, -828111, -764839, -147883, -57512,
- -15793, -4979, 11019, 12252, 34479, 44935, 47827, 56294, -312832, -312515, -304480, -298484,
- -294319, -219324, -200239, -177542, 744798, 754379, 770462, 775620, 833344, 856080, 867107,
- 907323, 923154, 933838, 472889, 481623, 485870, 613794, 660668, 679110, 679909, 694653, 706254,
- 720663, 938729, 961192, 982985, -506601, -468543, -467745, -448140, -413413, -393419,
- -335961, -321413, -763320, -745368, -727461, -723405, -719959, -684708, -675999, -650649,
- -629126, -613501, -609845, -581608, -570814, -549586, -540889, -536376,
- -997745, -991903, -979457, -972533, -971699, -913892, -889505, 64975, 81392, 91511, 127266,
- 166845, 175957, 194797, 207948, 218361, 235178};
- expectedBool = true;
- actualBool = CodeCamp.isPermutation(a, b);
- System.out.println("Test 7 isPermutation: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 7, isPermutation");
- else
- System.out.println(" ***** FAILED ***** test 7, isPermutation");
- System.out.println();
- // test 8, isPermutation
- a = new int[1_000_001];
- b = new int[1_000_000];
- expectedBool = false;
- actualBool = CodeCamp.isPermutation(a, b);
- System.out.println("Test 8 isPermutation: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 8, isPermutation");
- else
- System.out.println(" ***** FAILED ***** test 8, isPermutation");
- System.out.println();
- // test 9, isPermutation
- a = new int[]{0, -1, 1};
- b = new int[]{0, -2, 2};
- expectedBool = false;
- actualBool = CodeCamp.isPermutation(a, b);
- System.out.println("Test 9 isPermutation: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 9, isPermutation");
- else
- System.out.println(" ***** FAILED ***** test 9, isPermutation");
- System.out.println();
- // test 10, isPermutation, stress test
- a = new int[1_000_000];
- b = new int[1_000_000];
- expectedBool = true;
- actualBool = CodeCamp.isPermutation(a, b);
- System.out.println("(Stress Test) Test 10 isPermutation: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 10, isPermutation");
- else
- System.out.println(" ***** FAILED ***** test 10, isPermutation");
- System.out.println();
- // test 11, mostVowels
- String[] sList = {"bbbbb", "ccccc", "ddddd", "fffff"};
- int expectedResult = 0;
- int actualResult = CodeCamp.mostVowels(sList);
- System.out.println("Test 11 mostVowels: expected result: "
- + expectedResult + ", actual result: " + actualResult);
- if( actualResult == expectedResult )
- System.out.println("passed test 11, mostVowels");
- else
- System.out.println("***** FAILED ***** test 11, mostVowels");
- System.out.println();
- // test 12, mostVowels
- sList = new String[]{null, null, "Hello World!", null, "\ni\n\no\na\n\n\tltse", "!^*&%$#^@&^*$"};
- expectedResult = 4;
- actualResult = CodeCamp.mostVowels(sList);
- System.out.println("Test 12 mostVowels: expected result: "
- + expectedResult + ", actual result: " + actualResult);
- if( actualResult == expectedResult )
- System.out.println("passed test 12, mostVowels");
- else
- System.out.println("***** FAILED ***** test 12, mostVowels");
- System.out.println();
- // test 13, mostVowels
- sList = new String[]{null, null, null, null, null, null, null, null, null, null, "CS314"};
- expectedResult = 10;
- actualResult = CodeCamp.mostVowels(sList);
- System.out.println("Test 13 mostVowels: expected result: "
- + expectedResult + ", actual result: " + actualResult);
- if( actualResult == expectedResult )
- System.out.println("passed test 13, mostVowels");
- else
- System.out.println("***** FAILED ***** test 13, mostVowels");
- System.out.println();
- // test 14, mostVowels
- sList = new String[]{"", "", "Test", "", ""};
- expectedResult = 2;
- actualResult = CodeCamp.mostVowels(sList);
- System.out.println("Test 14 mostVowels: expected result: "
- + expectedResult + ", actual result: " + actualResult);
- if( actualResult == expectedResult )
- System.out.println("passed test 14, mostVowels");
- else
- System.out.println("***** FAILED ***** test 14, mostVowels");
- System.out.println();
- // test 15, mostVowels, stress test
- sList = new String[1_000_000];
- sList[50_000] = "";
- expectedResult = 50_000;
- actualResult = CodeCamp.mostVowels(sList);
- System.out.println("(Stress Test) Test 15 mostVowels: expected result: "
- + expectedResult + ", actual result: " + actualResult);
- if( actualResult == expectedResult )
- System.out.println("passed test 15, mostVowels");
- else
- System.out.println("***** FAILED ***** test 15, mostVowels");
- System.out.println();
- // test 16, sharedBirthdays
- int pairs = CodeCamp.sharedBirthdays(365, 365);
- System.out.println("Test 16 shared birthdays: expected: > 0, actual: " + pairs);
- if( pairs > 0 )
- System.out.println("passed test 16, shared birthdays");
- else
- System.out.println("***** FAILED ***** test 16, shared birthdays");
- System.out.println();
- // test 17, sharedBirthdays
- pairs = CodeCamp.sharedBirthdays(1, 365);
- System.out.println("Test 17 shared birthdays: expected: 0, actual: " + pairs);
- expectedResult = 0;
- if( pairs == expectedResult )
- System.out.println("passed test 17, shared birthdays");
- else
- System.out.println("***** FAILED ***** test 17, shared birthdays");
- System.out.println();
- // test 18, sharedBirthdays
- pairs = CodeCamp.sharedBirthdays(500, 1);
- System.out.println("Test 17 shared birthdays: expected: 124750, actual: " + pairs);
- expectedResult = 124750;
- if( pairs == expectedResult )
- System.out.println("passed test 18, shared birthdays");
- else
- System.out.println("***** FAILED ***** test 18, shared birthdays");
- System.out.println();
- // test 19, sharedBirthdays
- pairs = CodeCamp.sharedBirthdays(500, 5);
- System.out.println("Test 19 shared birthdays: expected: > 0, actual: " + pairs);
- if( pairs > 0 )
- System.out.println("passed test 19, shared birthdays");
- else
- System.out.println("***** FAILED ***** test 19, shared birthdays");
- System.out.println();
- // test 20, sharedBirthdays, stress test
- pairs = CodeCamp.sharedBirthdays(100_000, 365);
- System.out.println("(Stress Test) Test 20 shared birthdays: expected: > 0, actual: " + pairs);
- if( pairs > 0 )
- System.out.println("passed test 20, shared birthdays");
- else
- System.out.println("***** FAILED ***** test 20, shared birthdays");
- System.out.println();
- // test 21, queensAreASafe
- char[][] board = {
- {'.', '.', '.'},
- {'q', 'q', '.'},
- {'.', '.', 'q'}
- };
- expectedBool = false;
- actualBool = CodeCamp.queensAreSafe(board);
- System.out.println("Test 21 queensAreSafe: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 21, queensAreSafe");
- else
- System.out.println(" ***** FAILED ***** test 21, queensAreSafe");
- System.out.println();
- // test 22, queensAreASafe
- board = new char[][] {
- {'q', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', 'q', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', 'q', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', 'q', '.', '.', '.', '.', '.', '.', '.'}
- };
- expectedBool = true;
- actualBool = CodeCamp.queensAreSafe(board);
- System.out.println("Test 22 queensAreSafe: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 22, queensAreSafe");
- else
- System.out.println(" ***** FAILED ***** test 22, queensAreSafe");
- System.out.println();
- // test 23, queensAreASafe
- board = new char[][] {
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'}
- };
- expectedBool = true;
- actualBool = CodeCamp.queensAreSafe(board);
- System.out.println("Test 23 queensAreSafe: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 23, queensAreSafe");
- else
- System.out.println(" ***** FAILED ***** test 23, queensAreSafe");
- System.out.println();
- // test 24, queensAreASafe
- board = new char[][] {
- {'q', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', 'q'},
- {'.', '.', '.', '.', '.', '.', '.', 'q', '.'},
- {'.', '.', '.', 'q', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', 'q', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', 'q', '.'}
- };
- expectedBool = false;
- actualBool = CodeCamp.queensAreSafe(board);
- System.out.println("Test 24 queensAreSafe: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 24, queensAreSafe");
- else
- System.out.println(" ***** FAILED ***** test 24, queensAreSafe");
- System.out.println();
- // test 25, queensAreASafe
- board = new char[][] {
- {'.', '.', '.', 'q', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', 'q', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
- {'.', '.', '.', '.', '.', '.', '.', '.', '.'}
- };
- expectedBool = false;
- actualBool = CodeCamp.queensAreSafe(board);
- System.out.println("Test 25 queensAreSafe: expected value: "
- + expectedBool + ", actual value: " + actualBool);
- if ( expectedBool == actualBool )
- System.out.println(" passed test 25, queensAreSafe");
- else
- System.out.println(" ***** FAILED ***** test 25, queensAreSafe");
- System.out.println();
- // test 26, getValueOfMostValuablePlot
- int[][] city = new int[][] {
- {15, 12, 234, -50, 45},
- {12, 2, 4, -5, 4},
- {15, 1, 24, -5, 45},
- {135, 12, 0, -50, 45},
- {54, 12, 87, 9, 45}
- };
- expected = 702;
- actual = CodeCamp.getValueOfMostValuablePlot(city);
- System.out.println("(Stress Test) Test 26 getValueOfMostValuablePlot: expected value: "
- + expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 26, getValueOfMostValuablePlot");
- else
- System.out.println(" ***** FAILED ***** test 26, getValueOfMostValuablePlot");
- System.out.println();
- // test 27, getValueOfMostValuablePlot
- city = new int[][] {
- {15, 12, 234, -50, 45},
- {12, 2, 4, -5, 4},
- {15, 1, 24, -5, 45},
- {135, 12, 0, -50, 45},
- {54, 12, 87, 9, 45}
- };
- expected = 702;
- actual = CodeCamp.getValueOfMostValuablePlot(city);
- System.out.println("Test 27 getValueOfMostValuablePlot: expected value: "
- + expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 27, getValueOfMostValuablePlot");
- else
- System.out.println(" ***** FAILED ***** test 27, getValueOfMostValuablePlot");
- System.out.println();
- // test 28, getValueOfMostValuablePlot, stress test
- city = new int[][] {
- {-1, -67, -234, -3645, -3424, -1324, -2344, -324, -32452},
- {-456, -3424, -1324, -2344, -3424, -1324, -2344, -324, -32452},
- {-32442, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
- {-32442, -2342, -353423, -2657564, -354624, -1324, -2344, -324, -32452},
- {-234654, -343574, -32452, -324, -3424, -1324, -2344, -324, -32452},
- {-32442, -2342, -3234423, -234, -3424, -178674, -2344, -324, -32452},
- {-32442, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
- {-234654, -323654, -3234352, -324, -3424, -1324, -2344, -324, -32452},
- {-3256742, -2342, -32423, -234, -3424, -154724, -2344, -324, -32452},
- {-36787642, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
- {-234654, -324, -3232442, -324, -3424, -1879024, -2344, -324, -32452},
- {-32442, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
- {-327862, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
- {-234654, -324, -32452, -324, -3544, -1324, -2344, -324, -32452}
- };
- expected = -1;
- actual = CodeCamp.getValueOfMostValuablePlot(city);
- System.out.println("(Stress Test) Test 28 getValueOfMostValuablePlot: expected value: "
- + expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 28, getValueOfMostValuablePlot");
- else
- System.out.println(" ***** FAILED ***** test 28, getValueOfMostValuablePlot");
- System.out.println();
- // test 29, getValueOfMostValuablePlot, stress test
- city = new int[150][150];
- expected = 0;
- actual = CodeCamp.getValueOfMostValuablePlot(city);
- System.out.println("(Stress Test) Test 29 getValueOfMostValuablePlot: expected value: "
- + expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 29, getValueOfMostValuablePlot");
- else
- System.out.println(" ***** FAILED ***** test 29, getValueOfMostValuablePlot");
- System.out.println();
- // test 30, getValueOfMostValuablePlot, stress test
- city = new int[100][100];
- city[0][0] = 5;
- expected = 5;
- actual = CodeCamp.getValueOfMostValuablePlot(city);
- System.out.println("(Stress Test) Test 30 getValueOfMostValuablePlot: expected value: "
- + expected + ", actual value: " + actual);
- if( expected == actual )
- System.out.println(" passed test 30, getValueOfMostValuablePlot");
- else
- System.out.println(" ***** FAILED ***** test 30, getValueOfMostValuablePlot");
- System.out.println();
- // analyze the time it took for the program to finish
- double endTime = System.nanoTime();
- double totalSeconds = (endTime - startTime) / 1_000_000_000;
- System.out.println("COMPILATION TIME: " + totalSeconds + " SECONDS.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement