diff --git a/src/calculator.spec.ts b/src/calculator.spec.ts new file mode 100644 index 0000000..f8dede2 --- /dev/null +++ b/src/calculator.spec.ts @@ -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); + }) +}); diff --git a/src/calculator.ts b/src/calculator.ts new file mode 100644 index 0000000..420213b --- /dev/null +++ b/src/calculator.ts @@ -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 + } + +}