Skip to content

Commit

Permalink
Add division/multiplication
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilin committed Dec 1, 2013
1 parent 8a95120 commit 84f41ad
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion grammar.ebnf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
expr = number | operation
operation = number op number
op = "+" | "-"
op = "+" | "-" | "/" | "*"
number = integer | floating
floating = #"\d+\.\d+"
integer = #"\d+"
2 changes: 2 additions & 0 deletions src/math_interp/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
(case op
"+" +
"-" -
"*" *
"/" /
)
)

Expand Down
9 changes: 8 additions & 1 deletion test/math_interp/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
(is (= 8 (math-eval "10 - 2")))
(is (= -2 (math-eval "4 - 6"))))

(deftest division
(is (= 2 (math-eval "8 / 4"))))

(deftest multiplication
(is (= 10 (math-eval "5 * 2"))))

(deftest coercion
(let [res (math-eval "1 + 0.55")]
(is (== (+ 1 0.55) res))
Expand All @@ -29,6 +35,7 @@

(deftest addition-multiple-operands)

(deftest operator-precedence)
(deftest operator-precedence
)

(deftest negative-numbers)

0 comments on commit 84f41ad

Please sign in to comment.