-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcalculator.ts
43 lines (32 loc) · 943 Bytes
/
calculator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/// <reference path="../../references.ts" />
module Calculator {
export interface Expression {
eval: () => number
}
export class NumberExpression implements Expression {
constructor(private val:number) {
}
eval() {
return this.val
}
}
export class AddExpression implements Expression {
constructor(private left:Expression, private right:Expression) {
}
eval() {
return this.left.eval() + this.right.eval()
}
}
// REMOVE THESE LINES WHEN START THE EXERCISE
/* istanbul ignore next */
export class ExpressionComparer {
constructor(private left:Expression, private right:Expression) {
}
equals():Boolean {
return this.left.eval() == this.right.eval()
}
greaterThan():Boolean {
return this.left.eval() < this.right.eval()
}
}
}