Skip to content

Commit

Permalink
Add div-by-zero tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-hull committed May 11, 2016
1 parent f0fecba commit 017bd04
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/infix/grammar.clj
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
(throw (IllegalStateException.
(str (name kw) " is not bound in environment")))))))))

(def mulop (binary-op "*" "/" "**" "%" ">>" ">>>" "<<"))
(def mulop (binary-op "*" "/" "÷" "**" "%" ">>" ">>>" "<<"))
(def addop (binary-op "+" "-" "|" "&"))

(defn- binary-reducer [op-parser arg-parser]
Expand Down
2 changes: 1 addition & 1 deletion src/infix/macros.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
([bindings env expr]
(cond
(not (vector? bindings))
(throw (IllegalArgumentException. (str "Binding variables is not a vector")))
(throw (IllegalArgumentException. "Binding variables is not a vector"))

:else
(let [b# (binding-vars bindings)]
Expand Down
2 changes: 2 additions & 0 deletions test/infix/macros_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
(is (= 380175 ((from-string [t] "(t*(t>>5|t>>8))>>(t>>16)") 3425)))
(is (= 0 ((from-string "(3-2)-1"))))
(is (= 0 ((from-string "3 - 2 - 1"))))
(is (= Double/POSITIVE_INFINITY ((from-string "divide(3, 0)"))))
(is (= Double/NEGATIVE_INFINITY ((from-string "-3 ÷ 0"))))
(is (= 5 ((from-string [t] "t - 2") 7)))
(is (= 5 ((from-string [t] "t-2") 7)))
(is (= 5 ((from-string [t] "t- 2") 7)))
Expand Down

0 comments on commit 017bd04

Please sign in to comment.