Guest User

Untitled

a guest
Oct 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. /*
  2.  
  3. Write an "assertEqual" function from scratch, from memory.
  4.  
  5. Please DO NOT simply PASTE in from before.
  6.  
  7. If you have to go back and look at your previously-implemented code once, fine, but come back here and write it from memory.
  8.  
  9. Then use your assertion function in a series of test cases to thoroughly test the code.
  10.  
  11. Use categorical reasoning to consider all the useful cases.
  12.  
  13. Debug the code under test, if necessary.
  14.  
  15. */
  16.  
  17. // Assertion function:
  18.  
  19. function assertEqual(actual, expected, testName) {
  20. if(actual === expected){
  21. console.log("passed");
  22. } else {
  23. console.log("FAILED " + [testName] + "Expected " + expected + " but got" + actual);
  24. }
  25. }
  26.  
  27.  
  28. // Code Under Test:
  29.  
  30. function square(n) {
  31. return n * n;
  32. }
  33.  
  34. var output = square(5);
  35. assertEqual(output, 25, "it squares 5, ")
  36.  
  37. // Calls to 'assertEqual':
Add Comment
Please, Sign In to add comment