Class: TestPrograms
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TestPrograms
- Defined in:
- lib/tester/test_unit.rb
Instance Method Summary collapse
Instance Method Details
#test_fibonacci ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/tester/test_unit.rb', line 244 def test_fibonacci program = " a = 1 b = 1 #{$def} fib(x) #{$if} 2 < x temp = a + b a = b b = temp fib(x - 1) #{$else} b #{$end} #{$end} fib(11) " assert_equal(89, LangParser.new.calc_test(program)) end |
#test_func_with_while ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/tester/test_unit.rb', line 267 def test_func_with_while program = " x = 1 #{$def} foo(bar) #{$while} bar < 20 #{$print} bar bar = bar + 1 #{$end} #{$end} foo(x) " assert_equal(WhileLoopNode, LangParser.new.calc_test(program)) end |
#test_func_with_while_return_value ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/tester/test_unit.rb', line 283 def test_func_with_while_return_value program = " x = 1 #{$def} foo(bar) y = 0 #{$while} bar < 20 #{$print} bar bar = bar + 1 y = bar #{$end} #{$print} y y #{$end} foo(x) " assert_equal(20, LangParser.new.calc_test(program)) end |