Created
September 22, 2010 12:47
-
-
Save marioaquino/591599 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | |
| describe "Calculator" do | |
| it "should blow up if a non-string expression is supplied" do | |
| lambda { Calculator::calculate(2) }.should raise_error(ArgumentError) | |
| end | |
| it "should blow up if an invalid expression is supplied" do | |
| lambda { Calculator::calculate("a + b") }.should raise_error(ArgumentError) | |
| end | |
| it "should handle simple addition" do | |
| Calculator::calculate("2 + 3").should == "5" | |
| end | |
| it "should handle simple subtraction" do | |
| Calculator::calculate("3 - 1").should == "2" | |
| end | |
| it "should handle addition and subtraction combined" do | |
| Calculator::calculate("3 - 1 + 24 + 5 - 6").should == "25" | |
| end | |
| it "should handle simple multiplication" do | |
| Calculator::calculate("3 * 2").should == "6" | |
| end | |
| it "should handle simple division" do | |
| Calculator::calculate("6 / 3").should == "2" | |
| end | |
| it "should honor left-right operator order precedence" do | |
| Calculator::calculate("1 + 6 * 11 - 8 / 3").should == "23" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment