Skip to content

Commit caa21c2

Browse files
committed
feat(calculator.ts): add tan method
1 parent 8bdc414 commit caa21c2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Calculator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,9 @@ export default class Calculator {
6666
this.current = Math.cos(this.current);
6767
return this;
6868
}
69+
70+
public tan() {
71+
this.current = Math.tan(this.current);
72+
return this;
73+
}
6974
}

tests/Calculator.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { describe, it } from "mocha";
44
import Calculator from "../src/Calculator";
55

66
describe("Calculator", () => {
7+
it("has the correct initial value when no argument is supplied", () => expect(new Calculator().value()).equal(0));
8+
it("has the correct initial value when an argument is supplied", () => expect(new Calculator(3).value()).equal(3));
9+
710
const calculator = new Calculator();
811

912
it("can add", () => expect(calculator.add(2).value()).equal(2));
@@ -14,11 +17,9 @@ describe("Calculator", () => {
1417
// prettier-ignore
1518
it("can exp", () => expect(calculator.sub(1).exp().value()).equal(Math.E));
1619
it("can ln", () => expect(calculator.ln().value()).equal(1));
17-
1820
it("can clear", () => expect(calculator.clear().value()).equal(0));
1921
it("can sin", () => expect(calculator.sin().value()).equal(0));
2022
it("can cos", () => expect(calculator.cos().value()).equal(1));
21-
22-
it("has the correct initial value when no argument is supplied", () => expect(new Calculator().value()).equal(0));
23-
it("has the correct initial value when an argument is supplied", () => expect(new Calculator(3).value()).equal(3));
23+
// prettier-ignore
24+
it("can tan", () => expect(calculator.clear().tan().value()).equal(0));
2425
});

0 commit comments

Comments
 (0)