Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /zad2.js/
- class Calculator {
- constructor(first_number, second_number, operation) {
- this.first_number = first_number;
- this.second_number = second_number;
- this.operation = operation;
- }
- calculate(operation) {
- var res;
- this.operation = operation;
- if (this.operation === "+") {
- res = this.first_number + this.second_number;
- console.log("Addition: " + res);
- return res;
- } else if (this.operation === "-") {
- res = this.first_number - this.second_number;
- console.log("Subtraction: " + res);
- return res;
- } else if (this.operation === "*") {
- res = this.first_number * this.second_number;
- console.log("Multiplication: " + res);
- return res;
- } else if (this.operation === "/") {
- if (this.second_number === 0) {
- throw new Error("Cannot divide by zero");
- }
- res = this.first_number / this.second_number;
- console.log("Division: " + res);
- return res;
- } else {
- throw new Error("Incorrect operation");
- }
- }
- }
- module.exports = Calculator;
- /zad2.test.js/
- const assert = require("chai").assert;
- const Calculator = require("./../zad2");
- let first_number = 10;
- let second_number = 50;
- let operation = "+";
- let testApp = new Calculator(first_number, second_number, operation);
- describe("Calculator testing", function() {
- it("varijable first_number i second_number moraju biti numeričkog tipa ", function() {
- assert.isNumber(testApp.first_number);
- assert.isNumber(testApp.second_number);
- /*assert.isNumber(testApp.calculate(-5, -2, "+"));
- assert.isNumber(testApp.calculate(-5, -2, "-"));
- assert.isNumber(testApp.calculate(-5, -2, "*"));
- assert.isNumber(testApp.calculate(-5, 2, "/"));*/
- });
- /*
- it("Metoda calculate mora primati podatke numeričkog tipa ", function() {
- assert.throws(() => {
- testApp.calculate("+");
- }, Error);
- });*/
- it("Operacije koje se mogu izvršiti su: +,-,*,/", function() {
- var Obj1 = ["+", "-", "/", "*"];
- assert.include(Obj1, testApp.operation);
- });
- it("Rezultat kalkulacije mora biti broj", function() {
- assert.isNumber(testApp.calculate("*"));
- });
- });
- /*
- it("powerStatus mora biti boolean", function() {
- assert.isBoolean(testApp.powerStatus);
- });
- it("metode za paljenje i gašenje stroja moraju vratiti status Boolean tipa", function() {
- assert.isBoolean(testApp.turnMachineOn());
- assert.isBoolean(testApp.turnMachineOff());
- });
- it("Metoda refill mora primati parametre numerickog tipa ", function() {
- assert.throws(() => {
- testApp.refill("kava", "voda");
- }, Error);
- });
- });
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement