Skip to content

Commit

Permalink
Merge pull request #5 from terry-codecov/calculator-3
Browse files Browse the repository at this point in the history
Calculator 3
  • Loading branch information
terry-codecov authored May 17, 2022
2 parents 5842249 + 22e5019 commit a0b13e0
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/calculator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Calculator from "./calculator";

describe('Calulator: no starting value', () => {
let calc
beforeEach(() => {
calc = new Calculator();
})

it('returns a value', () => {
expect(calc.total).toEqual(0);
})


it('calculator defaults to graphing mode', () => {
expect(calc.mode).toEqual("graphing");
})

it('can perform addition', () => {
calc.plus(3)
expect(calc.total).toEqual(3);
calc.plus(7)
expect(calc.total).toEqual(10);
calc.plus(3)
expect(calc.total).toEqual(13);
})

// it('can perform subtraction', () => {
// calc.minus(1)
// expect(calc.total).toEqual(-1);
// calc.minus(2)
// expect(calc.total).toEqual(-3);
// calc.minus(3)
// expect(calc.total).toEqual(-6);
// })
});

describe('Calulator: starting value 99', () => {
let calc
beforeEach(() => {
calc = new Calculator();
})

it('returns a value', () => {
expect(calc.total).toEqual(0);
})

it('can zero out the internal value', () => {
calc.c()
expect(calc.total).toEqual(0);
})
});
45 changes: 45 additions & 0 deletions src/calculator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export default class Calculator {
private value = 0;
private calcMode = ""
constructor(scientificMode = false, value = 0) {
this.value = value

if(scientificMode) {
this.calcMode = "science!"
} else if(scientificMode && this.value > 0) {
this.calcMode = "I dont know I'm just making a branching statement"
} else {
this.calcMode = "graphing"
}
}

get total() {
return this.value
}

get mode() {
return this.calcMode
}

plus = (num) => {
this.value = this.value + num
return this.total
}

minus = (num) => {
this.value = this.value - num
return this.total
}


multiply = (num) => {
this.value = this.value * num
return this.total
}

c = () => {
this.value = 0
return this.total
}

}

0 comments on commit a0b13e0

Please sign in to comment.