Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. function celsToFahr(celsTemp) {
  2. return celsTemp * 9/5 + 32;
  3. }
  4.  
  5. function fahrToCels(fahrTemp) {
  6. return (fahrTemp - 32) * 9/5;
  7. }
  8.  
  9.  
  10. /* From here down, you are not expected to
  11. understand.... for now :)
  12.  
  13.  
  14. Nothing to see here!
  15.  
  16. */
  17.  
  18.  
  19.  
  20. // tests
  21.  
  22. function testConversion(fn, input, expected) {
  23. if (fn(input) === expected) {
  24. console.log('SUCCESS: `' + fn.name + '` is working');
  25. return true;
  26. }
  27. else {
  28. console.log('FAILURE: `' + fn.name + '` is not working');
  29. return false;
  30. }
  31. }
  32.  
  33. function testConverters() {
  34. let cel2FahrInput = 100;
  35. let cel2FahrExpect = 212;
  36. let fahr2CelInput = 32;
  37. let fahr2CelExpect = 0;
  38.  
  39. if (testConversion(celsToFahr, cel2FahrInput, cel2FahrExpect) &&
  40. testConversion(fahrToCels, fahr2CelInput, fahr2CelExpect)) {
  41. console.log('SUCCESS: All tests passing');
  42. }
  43. else {
  44. console.log('FAILURE: Some tests are failing');
  45. }
  46. }
  47.  
  48. testConverters();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement