Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. /zad2.js/
  2.  
  3. class Calculator {
  4. constructor(first_number, second_number, operation) {
  5. this.first_number = first_number;
  6. this.second_number = second_number;
  7. this.operation = operation;
  8. }
  9.  
  10. calculate(operation) {
  11. var res;
  12. this.operation = operation;
  13. if (this.operation === "+") {
  14. res = this.first_number + this.second_number;
  15. console.log("Addition: " + res);
  16. return res;
  17. } else if (this.operation === "-") {
  18. res = this.first_number - this.second_number;
  19. console.log("Subtraction: " + res);
  20. return res;
  21. } else if (this.operation === "*") {
  22. res = this.first_number * this.second_number;
  23. console.log("Multiplication: " + res);
  24. return res;
  25. } else if (this.operation === "/") {
  26. if (this.second_number === 0) {
  27. throw new Error("Cannot divide by zero");
  28. }
  29. res = this.first_number / this.second_number;
  30. console.log("Division: " + res);
  31. return res;
  32. } else {
  33. throw new Error("Incorrect operation");
  34. }
  35. }
  36. }
  37. module.exports = Calculator;
  38.  
  39.  
  40. /zad2.test.js/
  41.  
  42. const assert = require("chai").assert;
  43.  
  44. const Calculator = require("./../zad2");
  45.  
  46. let first_number = 10;
  47. let second_number = 50;
  48. let operation = "+";
  49. let testApp = new Calculator(first_number, second_number, operation);
  50.  
  51. describe("Calculator testing", function() {
  52. it("varijable first_number i second_number moraju biti numeričkog tipa ", function() {
  53. assert.isNumber(testApp.first_number);
  54. assert.isNumber(testApp.second_number);
  55. /*assert.isNumber(testApp.calculate(-5, -2, "+"));
  56. assert.isNumber(testApp.calculate(-5, -2, "-"));
  57. assert.isNumber(testApp.calculate(-5, -2, "*"));
  58. assert.isNumber(testApp.calculate(-5, 2, "/"));*/
  59. });
  60. /*
  61. it("Metoda calculate mora primati podatke numeričkog tipa ", function() {
  62. assert.throws(() => {
  63. testApp.calculate("+");
  64. }, Error);
  65. });*/
  66.  
  67. it("Operacije koje se mogu izvršiti su: +,-,*,/", function() {
  68. var Obj1 = ["+", "-", "/", "*"];
  69. assert.include(Obj1, testApp.operation);
  70. });
  71.  
  72. it("Rezultat kalkulacije mora biti broj", function() {
  73. assert.isNumber(testApp.calculate("*"));
  74. });
  75. });
  76. /*
  77. it("powerStatus mora biti boolean", function() {
  78. assert.isBoolean(testApp.powerStatus);
  79. });
  80.  
  81. it("metode za paljenje i gašenje stroja moraju vratiti status Boolean tipa", function() {
  82. assert.isBoolean(testApp.turnMachineOn());
  83. assert.isBoolean(testApp.turnMachineOff());
  84. });
  85.  
  86. it("Metoda refill mora primati parametre numerickog tipa ", function() {
  87. assert.throws(() => {
  88. testApp.refill("kava", "voda");
  89. }, Error);
  90. });
  91. });
  92. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement