Advertisement
Guest User

Tests for Assignment 1

a guest
Jan 19th, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.20 KB | None | 0 0
  1. public class CodeCampTester {
  2.  
  3. // test the CodeCamp methods
  4. public static void main(String[] args) {
  5. // CS314 Students: add tests here.
  6.  
  7. // staring time of the program
  8. double startTime = System.nanoTime();
  9.  
  10. // test 1, hammingDistance
  11. int[] h1 = {12, 15, 1298, 4892, 2984, 209374, 904378, 23947, 239047, 15};
  12. int[] h2 = {12, 16, 1298, 4891, 2984, 209373, 902378, 23947, 239047, 15};
  13. int expected = 4;
  14. int actual = CodeCamp.hammingDistance(h1, h2);
  15. System.out.println("Test 1 hamming distance: expected value: " +
  16. expected + ", actual value: " + actual);
  17. if( expected == actual )
  18. System.out.println(" passed test 1, hamming distance");
  19. else
  20. System.out.println(" ***** FAILED ***** test 1, hamming distance");
  21. System.out.println();
  22.  
  23. // test 2, hammingDistance
  24. h1 = new int[]{1, 2, 3, 4, 5, 5, 7, 8, 9, 10};
  25. h2 = new int[]{10, 9, 8, 7, 5, 5, 4, 3, 2, 1};
  26. expected = 8;
  27. actual = CodeCamp.hammingDistance(h1, h2);
  28. System.out.println("Test 2 hamming distance: expected value: " +
  29. expected + ", actual value: " + actual);
  30. if( expected == actual )
  31. System.out.println(" passed test 2, hamming distance");
  32. else
  33. System.out.println(" ***** FAILED ***** test 2, hamming distance");
  34. System.out.println();
  35.  
  36. // test 3, hammingDistance
  37. h1 = new int[]{Integer.MAX_VALUE, Integer.MIN_VALUE};
  38. h2 = new int[]{Integer.MIN_VALUE, Integer.MAX_VALUE};
  39. expected = 2;
  40. actual = CodeCamp.hammingDistance(h1, h2);
  41. System.out.println("Test 3 hamming distance: expected value: " +
  42. expected + ", actual value: " + actual);
  43. if( expected == actual )
  44. System.out.println(" passed test 3, hamming distance");
  45. else
  46. System.out.println(" ***** FAILED ***** test 3, hamming distance");
  47. System.out.println();
  48.  
  49. // test 4, hammingDistance
  50. h1 = new int[]{Integer.MAX_VALUE, Integer.MIN_VALUE, 0, 150000, Integer.MAX_VALUE / 2};
  51. h2 = new int[]{100000, Integer.MIN_VALUE, Integer.MAX_VALUE / 2, 150000, Integer.MIN_VALUE};
  52. expected = 3;
  53. actual = CodeCamp.hammingDistance(h1, h2);
  54. System.out.println("Test 4 hamming distance: expected value: " +
  55. expected + ", actual value: " + actual);
  56. if( expected == actual )
  57. System.out.println(" passed test 4, hamming distance");
  58. else
  59. System.out.println(" ***** FAILED ***** test 4, hamming distance");
  60. System.out.println();
  61.  
  62. // test 5, hammingDistance
  63. h1 = new int[1_000_000];
  64. h2 = new int[1_000_000];
  65. expected = 0;
  66. actual = CodeCamp.hammingDistance(h1, h2);
  67. System.out.println("Test 5 hamming distance: expected value: " +
  68. expected + ", actual value: " + actual);
  69. if( expected == actual )
  70. System.out.println(" passed test 5, hamming distance");
  71. else
  72. System.out.println(" ***** FAILED ***** test 5, hamming distance");
  73. System.out.println();
  74.  
  75. // test 6, isPermutation
  76. int[] a = {1, 2, 3, 3};
  77. int[] b = {3, 1, 2, 2};
  78. boolean expectedBool = false;
  79. boolean actualBool = CodeCamp.isPermutation(a, b);
  80. System.out.println("Test 6 isPermutation: expected value: "
  81. + expectedBool + ", actual value: " + actualBool);
  82. if ( expectedBool == actualBool )
  83. System.out.println(" passed test 6, isPermutation");
  84. else
  85. System.out.println(" ***** FAILED ***** test 6, isPermutation");
  86. System.out.println();
  87.  
  88. // test 7, isPermutation
  89. a = new int[]{-997745, -991903, -979457, -972533, -971699, -913892, -889505,
  90. -884203, -866389, -859120, -851847, -841195, -838661, -828111, -764839,
  91. -763320, -745368, -727461, -723405, -719959, -684708, -675999, -650649,
  92. -629126, -613501, -609845, -581608, -570814, -549586, -540889, -536376,
  93. -506601, -468543, -467745, -448140, -413413, -393419, -335961, -321413,
  94. -312832, -312515, -304480, -298484, -294319, -219324, -200239, -177542,
  95. -147883, -57512, -15793, -4979, 11019, 12252, 34479, 44935, 47827, 56294,
  96. 64975, 81392, 91511, 127266, 166845, 175957, 194797, 207948, 218361, 235178,
  97. 250571, 316758, 330954, 358810, 399433, 403966, 408021, 420420, 433881, 437965,
  98. 472889, 481623, 485870, 613794, 660668, 679110, 679909, 694653, 706254, 720663,
  99. 744798, 754379, 770462, 775620, 833344, 856080, 867107, 907323, 923154, 933838,
  100. 938729, 961192, 982985};
  101. b = new int[] {250571, 316758, 330954, 358810, 399433, 403966, 408021, 420420, 433881, 437965,
  102. -884203, -866389, -859120, -851847, -841195, -838661, -828111, -764839, -147883, -57512,
  103. -15793, -4979, 11019, 12252, 34479, 44935, 47827, 56294, -312832, -312515, -304480, -298484,
  104. -294319, -219324, -200239, -177542, 744798, 754379, 770462, 775620, 833344, 856080, 867107,
  105. 907323, 923154, 933838, 472889, 481623, 485870, 613794, 660668, 679110, 679909, 694653, 706254,
  106. 720663, 938729, 961192, 982985, -506601, -468543, -467745, -448140, -413413, -393419,
  107. -335961, -321413, -763320, -745368, -727461, -723405, -719959, -684708, -675999, -650649,
  108. -629126, -613501, -609845, -581608, -570814, -549586, -540889, -536376,
  109. -997745, -991903, -979457, -972533, -971699, -913892, -889505, 64975, 81392, 91511, 127266,
  110. 166845, 175957, 194797, 207948, 218361, 235178};
  111. expectedBool = true;
  112. actualBool = CodeCamp.isPermutation(a, b);
  113. System.out.println("Test 7 isPermutation: expected value: "
  114. + expectedBool + ", actual value: " + actualBool);
  115. if ( expectedBool == actualBool )
  116. System.out.println(" passed test 7, isPermutation");
  117. else
  118. System.out.println(" ***** FAILED ***** test 7, isPermutation");
  119. System.out.println();
  120.  
  121. // test 8, isPermutation
  122. a = new int[1_000_001];
  123. b = new int[1_000_000];
  124. expectedBool = false;
  125. actualBool = CodeCamp.isPermutation(a, b);
  126. System.out.println("Test 8 isPermutation: expected value: "
  127. + expectedBool + ", actual value: " + actualBool);
  128. if ( expectedBool == actualBool )
  129. System.out.println(" passed test 8, isPermutation");
  130. else
  131. System.out.println(" ***** FAILED ***** test 8, isPermutation");
  132. System.out.println();
  133.  
  134. // test 9, isPermutation
  135. a = new int[]{0, -1, 1};
  136. b = new int[]{0, -2, 2};
  137. expectedBool = false;
  138. actualBool = CodeCamp.isPermutation(a, b);
  139. System.out.println("Test 9 isPermutation: expected value: "
  140. + expectedBool + ", actual value: " + actualBool);
  141. if ( expectedBool == actualBool )
  142. System.out.println(" passed test 9, isPermutation");
  143. else
  144. System.out.println(" ***** FAILED ***** test 9, isPermutation");
  145. System.out.println();
  146.  
  147. // test 10, isPermutation, stress test
  148. a = new int[1_000_000];
  149. b = new int[1_000_000];
  150. expectedBool = true;
  151. actualBool = CodeCamp.isPermutation(a, b);
  152. System.out.println("(Stress Test) Test 10 isPermutation: expected value: "
  153. + expectedBool + ", actual value: " + actualBool);
  154. if ( expectedBool == actualBool )
  155. System.out.println(" passed test 10, isPermutation");
  156. else
  157. System.out.println(" ***** FAILED ***** test 10, isPermutation");
  158. System.out.println();
  159.  
  160. // test 11, mostVowels
  161. String[] sList = {"bbbbb", "ccccc", "ddddd", "fffff"};
  162. int expectedResult = 0;
  163. int actualResult = CodeCamp.mostVowels(sList);
  164. System.out.println("Test 11 mostVowels: expected result: "
  165. + expectedResult + ", actual result: " + actualResult);
  166. if( actualResult == expectedResult )
  167. System.out.println("passed test 11, mostVowels");
  168. else
  169. System.out.println("***** FAILED ***** test 11, mostVowels");
  170. System.out.println();
  171.  
  172. // test 12, mostVowels
  173. sList = new String[]{null, null, "Hello World!", null, "\ni\n\no\na\n\n\tltse", "!^*&%$#^@&^*$"};
  174. expectedResult = 4;
  175. actualResult = CodeCamp.mostVowels(sList);
  176. System.out.println("Test 12 mostVowels: expected result: "
  177. + expectedResult + ", actual result: " + actualResult);
  178. if( actualResult == expectedResult )
  179. System.out.println("passed test 12, mostVowels");
  180. else
  181. System.out.println("***** FAILED ***** test 12, mostVowels");
  182. System.out.println();
  183.  
  184. // test 13, mostVowels
  185. sList = new String[]{null, null, null, null, null, null, null, null, null, null, "CS314"};
  186. expectedResult = 10;
  187. actualResult = CodeCamp.mostVowels(sList);
  188. System.out.println("Test 13 mostVowels: expected result: "
  189. + expectedResult + ", actual result: " + actualResult);
  190. if( actualResult == expectedResult )
  191. System.out.println("passed test 13, mostVowels");
  192. else
  193. System.out.println("***** FAILED ***** test 13, mostVowels");
  194. System.out.println();
  195.  
  196. // test 14, mostVowels
  197. sList = new String[]{"", "", "Test", "", ""};
  198. expectedResult = 2;
  199. actualResult = CodeCamp.mostVowels(sList);
  200. System.out.println("Test 14 mostVowels: expected result: "
  201. + expectedResult + ", actual result: " + actualResult);
  202. if( actualResult == expectedResult )
  203. System.out.println("passed test 14, mostVowels");
  204. else
  205. System.out.println("***** FAILED ***** test 14, mostVowels");
  206. System.out.println();
  207.  
  208. // test 15, mostVowels, stress test
  209. sList = new String[1_000_000];
  210. sList[50_000] = "";
  211. expectedResult = 50_000;
  212. actualResult = CodeCamp.mostVowels(sList);
  213. System.out.println("(Stress Test) Test 15 mostVowels: expected result: "
  214. + expectedResult + ", actual result: " + actualResult);
  215. if( actualResult == expectedResult )
  216. System.out.println("passed test 15, mostVowels");
  217. else
  218. System.out.println("***** FAILED ***** test 15, mostVowels");
  219. System.out.println();
  220.  
  221. // test 16, sharedBirthdays
  222. int pairs = CodeCamp.sharedBirthdays(365, 365);
  223. System.out.println("Test 16 shared birthdays: expected: > 0, actual: " + pairs);
  224. if( pairs > 0 )
  225. System.out.println("passed test 16, shared birthdays");
  226. else
  227. System.out.println("***** FAILED ***** test 16, shared birthdays");
  228. System.out.println();
  229.  
  230. // test 17, sharedBirthdays
  231. pairs = CodeCamp.sharedBirthdays(1, 365);
  232. System.out.println("Test 17 shared birthdays: expected: 0, actual: " + pairs);
  233. expectedResult = 0;
  234. if( pairs == expectedResult )
  235. System.out.println("passed test 17, shared birthdays");
  236. else
  237. System.out.println("***** FAILED ***** test 17, shared birthdays");
  238. System.out.println();
  239.  
  240. // test 18, sharedBirthdays
  241. pairs = CodeCamp.sharedBirthdays(500, 1);
  242. System.out.println("Test 17 shared birthdays: expected: 124750, actual: " + pairs);
  243. expectedResult = 124750;
  244. if( pairs == expectedResult )
  245. System.out.println("passed test 18, shared birthdays");
  246. else
  247. System.out.println("***** FAILED ***** test 18, shared birthdays");
  248. System.out.println();
  249.  
  250. // test 19, sharedBirthdays
  251. pairs = CodeCamp.sharedBirthdays(500, 5);
  252. System.out.println("Test 19 shared birthdays: expected: > 0, actual: " + pairs);
  253. if( pairs > 0 )
  254. System.out.println("passed test 19, shared birthdays");
  255. else
  256. System.out.println("***** FAILED ***** test 19, shared birthdays");
  257. System.out.println();
  258.  
  259. // test 20, sharedBirthdays, stress test
  260. pairs = CodeCamp.sharedBirthdays(100_000, 365);
  261. System.out.println("(Stress Test) Test 20 shared birthdays: expected: > 0, actual: " + pairs);
  262. if( pairs > 0 )
  263. System.out.println("passed test 20, shared birthdays");
  264. else
  265. System.out.println("***** FAILED ***** test 20, shared birthdays");
  266. System.out.println();
  267.  
  268. // test 21, queensAreASafe
  269. char[][] board = {
  270. {'.', '.', '.'},
  271. {'q', 'q', '.'},
  272. {'.', '.', 'q'}
  273. };
  274. expectedBool = false;
  275. actualBool = CodeCamp.queensAreSafe(board);
  276. System.out.println("Test 21 queensAreSafe: expected value: "
  277. + expectedBool + ", actual value: " + actualBool);
  278. if ( expectedBool == actualBool )
  279. System.out.println(" passed test 21, queensAreSafe");
  280. else
  281. System.out.println(" ***** FAILED ***** test 21, queensAreSafe");
  282. System.out.println();
  283.  
  284. // test 22, queensAreASafe
  285. board = new char[][] {
  286. {'q', '.', '.', '.', '.', '.', '.', '.', '.'},
  287. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  288. {'.', '.', '.', '.', '.', '.', 'q', '.', '.'},
  289. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  290. {'.', '.', '.', '.', '.', '.', '.', 'q', '.'},
  291. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  292. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  293. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  294. {'.', 'q', '.', '.', '.', '.', '.', '.', '.'}
  295. };
  296. expectedBool = true;
  297. actualBool = CodeCamp.queensAreSafe(board);
  298. System.out.println("Test 22 queensAreSafe: expected value: "
  299. + expectedBool + ", actual value: " + actualBool);
  300. if ( expectedBool == actualBool )
  301. System.out.println(" passed test 22, queensAreSafe");
  302. else
  303. System.out.println(" ***** FAILED ***** test 22, queensAreSafe");
  304. System.out.println();
  305.  
  306. // test 23, queensAreASafe
  307. board = new char[][] {
  308. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  309. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  310. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  311. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  312. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  313. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  314. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  315. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  316. {'.', '.', '.', '.', '.', '.', '.', '.', '.'}
  317. };
  318. expectedBool = true;
  319. actualBool = CodeCamp.queensAreSafe(board);
  320. System.out.println("Test 23 queensAreSafe: expected value: "
  321. + expectedBool + ", actual value: " + actualBool);
  322. if ( expectedBool == actualBool )
  323. System.out.println(" passed test 23, queensAreSafe");
  324. else
  325. System.out.println(" ***** FAILED ***** test 23, queensAreSafe");
  326. System.out.println();
  327.  
  328. // test 24, queensAreASafe
  329. board = new char[][] {
  330. {'q', '.', '.', '.', '.', '.', '.', '.', '.'},
  331. {'.', '.', '.', '.', '.', '.', '.', '.', 'q'},
  332. {'.', '.', '.', '.', '.', '.', '.', 'q', '.'},
  333. {'.', '.', '.', 'q', '.', '.', '.', '.', '.'},
  334. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  335. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  336. {'.', '.', '.', '.', '.', 'q', '.', '.', '.'},
  337. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  338. {'.', '.', '.', '.', '.', '.', '.', 'q', '.'}
  339. };
  340. expectedBool = false;
  341. actualBool = CodeCamp.queensAreSafe(board);
  342. System.out.println("Test 24 queensAreSafe: expected value: "
  343. + expectedBool + ", actual value: " + actualBool);
  344. if ( expectedBool == actualBool )
  345. System.out.println(" passed test 24, queensAreSafe");
  346. else
  347. System.out.println(" ***** FAILED ***** test 24, queensAreSafe");
  348. System.out.println();
  349.  
  350. // test 25, queensAreASafe
  351. board = new char[][] {
  352. {'.', '.', '.', 'q', '.', '.', '.', '.', '.'},
  353. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  354. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  355. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  356. {'.', '.', '.', 'q', '.', '.', '.', '.', '.'},
  357. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  358. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  359. {'.', '.', '.', '.', '.', '.', '.', '.', '.'},
  360. {'.', '.', '.', '.', '.', '.', '.', '.', '.'}
  361. };
  362. expectedBool = false;
  363. actualBool = CodeCamp.queensAreSafe(board);
  364. System.out.println("Test 25 queensAreSafe: expected value: "
  365. + expectedBool + ", actual value: " + actualBool);
  366. if ( expectedBool == actualBool )
  367. System.out.println(" passed test 25, queensAreSafe");
  368. else
  369. System.out.println(" ***** FAILED ***** test 25, queensAreSafe");
  370. System.out.println();
  371.  
  372. // test 26, getValueOfMostValuablePlot
  373. int[][] city = new int[][] {
  374. {15, 12, 234, -50, 45},
  375. {12, 2, 4, -5, 4},
  376. {15, 1, 24, -5, 45},
  377. {135, 12, 0, -50, 45},
  378. {54, 12, 87, 9, 45}
  379. };
  380. expected = 702;
  381. actual = CodeCamp.getValueOfMostValuablePlot(city);
  382. System.out.println("(Stress Test) Test 26 getValueOfMostValuablePlot: expected value: "
  383. + expected + ", actual value: " + actual);
  384. if( expected == actual )
  385. System.out.println(" passed test 26, getValueOfMostValuablePlot");
  386. else
  387. System.out.println(" ***** FAILED ***** test 26, getValueOfMostValuablePlot");
  388. System.out.println();
  389.  
  390. // test 27, getValueOfMostValuablePlot
  391. city = new int[][] {
  392. {15, 12, 234, -50, 45},
  393. {12, 2, 4, -5, 4},
  394. {15, 1, 24, -5, 45},
  395. {135, 12, 0, -50, 45},
  396. {54, 12, 87, 9, 45}
  397. };
  398. expected = 702;
  399. actual = CodeCamp.getValueOfMostValuablePlot(city);
  400. System.out.println("Test 27 getValueOfMostValuablePlot: expected value: "
  401. + expected + ", actual value: " + actual);
  402. if( expected == actual )
  403. System.out.println(" passed test 27, getValueOfMostValuablePlot");
  404. else
  405. System.out.println(" ***** FAILED ***** test 27, getValueOfMostValuablePlot");
  406. System.out.println();
  407.  
  408. // test 28, getValueOfMostValuablePlot, stress test
  409. city = new int[][] {
  410. {-1, -67, -234, -3645, -3424, -1324, -2344, -324, -32452},
  411. {-456, -3424, -1324, -2344, -3424, -1324, -2344, -324, -32452},
  412. {-32442, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
  413. {-32442, -2342, -353423, -2657564, -354624, -1324, -2344, -324, -32452},
  414. {-234654, -343574, -32452, -324, -3424, -1324, -2344, -324, -32452},
  415. {-32442, -2342, -3234423, -234, -3424, -178674, -2344, -324, -32452},
  416. {-32442, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
  417. {-234654, -323654, -3234352, -324, -3424, -1324, -2344, -324, -32452},
  418. {-3256742, -2342, -32423, -234, -3424, -154724, -2344, -324, -32452},
  419. {-36787642, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
  420. {-234654, -324, -3232442, -324, -3424, -1879024, -2344, -324, -32452},
  421. {-32442, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
  422. {-327862, -2342, -32423, -234, -3424, -1324, -2344, -324, -32452},
  423. {-234654, -324, -32452, -324, -3544, -1324, -2344, -324, -32452}
  424. };
  425. expected = -1;
  426. actual = CodeCamp.getValueOfMostValuablePlot(city);
  427. System.out.println("(Stress Test) Test 28 getValueOfMostValuablePlot: expected value: "
  428. + expected + ", actual value: " + actual);
  429. if( expected == actual )
  430. System.out.println(" passed test 28, getValueOfMostValuablePlot");
  431. else
  432. System.out.println(" ***** FAILED ***** test 28, getValueOfMostValuablePlot");
  433. System.out.println();
  434.  
  435. // test 29, getValueOfMostValuablePlot, stress test
  436. city = new int[150][150];
  437. expected = 0;
  438. actual = CodeCamp.getValueOfMostValuablePlot(city);
  439. System.out.println("(Stress Test) Test 29 getValueOfMostValuablePlot: expected value: "
  440. + expected + ", actual value: " + actual);
  441. if( expected == actual )
  442. System.out.println(" passed test 29, getValueOfMostValuablePlot");
  443. else
  444. System.out.println(" ***** FAILED ***** test 29, getValueOfMostValuablePlot");
  445. System.out.println();
  446.  
  447. // test 30, getValueOfMostValuablePlot, stress test
  448. city = new int[100][100];
  449. city[0][0] = 5;
  450. expected = 5;
  451. actual = CodeCamp.getValueOfMostValuablePlot(city);
  452. System.out.println("(Stress Test) Test 30 getValueOfMostValuablePlot: expected value: "
  453. + expected + ", actual value: " + actual);
  454. if( expected == actual )
  455. System.out.println(" passed test 30, getValueOfMostValuablePlot");
  456. else
  457. System.out.println(" ***** FAILED ***** test 30, getValueOfMostValuablePlot");
  458. System.out.println();
  459.  
  460. // analyze the time it took for the program to finish
  461. double endTime = System.nanoTime();
  462. double totalSeconds = (endTime - startTime) / 1_000_000_000;
  463. System.out.println("COMPILATION TIME: " + totalSeconds + " SECONDS.");
  464. }
  465. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement