Created
December 11, 2008 07:18
-
-
Save takedasoft/34630 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* ftdrop3Spec.scala | |
* | |
* specs for ftdop3.scala | |
* http://gist.github.com/30441 | |
* | |
* require: specs-<version>.jar | |
* http://code.google.com/p/specs/ | |
*/ | |
package ftdop3 | |
import org.specs._ | |
import org.specs.matcher._ | |
import ftdop3.{main => FTDOP} | |
object ftdop3Spec extends Specification("specification of ftdop3"){ | |
val EVAL_ERROR = -1 | |
"ftdop3" should { | |
"parse successfully." >> { | |
"unsigned number" >> { | |
FTDOP.parse("1") must_== 1 | |
FTDOP.parse("100") must_== 100 | |
} | |
"negative numbers" >> { | |
FTDOP.parse("-5") must_== -5 // must fail | |
//FTDOP.parse("-5") must_== ("-",5) | |
} | |
"1+1" >> { | |
FTDOP.parse("1+1") must_==(1,"+",1) | |
} | |
"1*1" >> { | |
FTDOP.parse("1*1") must_==(1,"*",1) | |
} | |
"1+1+1" >> { | |
FTDOP.parse("1+1+1") must_==((1,"+",1),"+",1) | |
} | |
"1+1*1" >> { | |
FTDOP.parse("1+1*1") must_==(1,"+",(1,"*",1)) | |
} | |
"if( true ) 1 else 2" >> { | |
FTDOP.parse("if( 1==1 ) 1 else 9") | |
.must_== ("if",("",(1,"==",1),""),(1,"else",9)) | |
} | |
"a=fun(c)c+1 a(2)" >> { | |
FTDOP.parse("a=fun(c)c+1 a(2)") | |
.must_== (("a","=",("fun",("","c",""),("c","+",1))),"@",("a",("",2,""))) | |
} | |
} | |
"evaluate successfully." >> { | |
"unsigned numbers" >> { | |
FTDOP.eval("1") must_== 1 | |
FTDOP.eval("100") must_== 100 | |
} | |
"negative numbers" >> { | |
FTDOP.eval("-1") must_== -1 | |
FTDOP.eval("-100") must_== -100 | |
} | |
"1+1" >> { | |
FTDOP.eval("1+1") must_== 2 | |
} | |
"1*1" >> { | |
FTDOP.eval("1*1") must_== 1 | |
} | |
"1+1+1" >> { | |
FTDOP.eval("1+1+1") must_== 3 | |
} | |
"1+1*1" >> { | |
FTDOP.eval("1+1*1") must_== 2 | |
} | |
"2*(1+1)" >> { | |
FTDOP.eval("2*(1+1)") must_== 4 | |
} | |
"if( true ) 1 else 2" >> { | |
FTDOP.eval("if( 1==1 ) 1 else 9") must_== 1 | |
} | |
"a=fun(c)c+1 a(2)" >> { | |
FTDOP.eval("a=fun(c)c+1 a(2)") must_== 3 | |
} | |
} | |
"not evaluate." >> { | |
"too big number" >> { | |
val n = "100000000000" | |
try{ | |
FTDOP.eval(n) must_== EVAL_ERROR | |
}catch{ | |
case e => | |
e must beLike{ case ex:NumberFormatException => true } | |
} | |
} | |
"--5" >> { | |
FTDOP.eval("--5") must_== EVAL_ERROR | |
} | |
"1+1*" >> { | |
FTDOP.eval("1+1*") must_== EVAL_ERROR | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment