forked from codecov/typescript-standard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from terry-codecov/calculator-3
Calculator 3
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |