Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. function computeArea(width, height) {
  2. return width*height;
  3. }
  4.  
  5. // tests
  6.  
  7. function testComputeArea() {
  8. var width = 3;
  9. var height = 4;
  10. var expected = 12;
  11. if (computeArea(width, height) === expected) {
  12. console.log('SUCCESS: `computeArea` is working');
  13. }
  14. else {
  15. console.log('FAILURE: `computeArea` is not working');
  16. }
  17. }
  18.  
  19. testComputeArea();
  20.  
  21.  
  22. function celsToFahr(celsTemp) {
  23. return celsTemp*9/5+32
  24. }
  25.  
  26. function fahrToCels(fahrTemp) {
  27. return (fahrTemp-32)*5/9
  28. }
  29.  
  30. // tests
  31.  
  32. function testConversion(fn, input, expected) {
  33. if (fn(input) === expected) {
  34. console.log('SUCCESS: `' + fn.name + '` is working');
  35. return true;
  36. }
  37. else {
  38. console.log('FAILURE: `' + fn.name + '` is not working');
  39. return false;
  40. }
  41. }
  42.  
  43. function testConverters() {
  44. var cel2FahrInput = 100;
  45. var cel2FahrExpect = 212;
  46. var fahr2CelInput = 32;
  47. var fahr2CelExpect = 0;
  48.  
  49. if (testConversion(celsToFahr, cel2FahrInput, cel2FahrExpect) &&
  50. testConversion(fahrToCels, fahr2CelInput, fahr2CelExpect)) {
  51. console.log('SUCCESS: All tests passing');
  52. }
  53. else {
  54. console.log('FAILURE: Some tests are failing');
  55. }
  56. }
  57.  
  58. testConverters();
  59.  
  60.  
  61.  
  62. function isDivisible(divisee, divisor) {
  63. return divisee%divisor===0
  64. }
  65.  
  66. // tests
  67.  
  68. function testIsDivisible() {
  69. if (isDivisible(10, 2) && !isDivisible(11, 2)) {
  70. console.log('SUCCESS: `isDivisible` is working');
  71. }
  72. else {
  73. console.log('FAILURE: `isDivisible` is not working');
  74. }
  75. }
  76.  
  77. testIsDivisible();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement