2014-05-28 15:03:54 +03:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
class TestWhileFragment < MiniTest::Test
|
|
|
|
include Fragments
|
|
|
|
|
2015-11-06 14:24:57 +02:00
|
|
|
def fibo num
|
2014-05-28 15:03:54 +03:00
|
|
|
@string_input = <<HERE
|
2015-10-06 00:27:13 +03:00
|
|
|
class Object
|
|
|
|
int fibonaccit(int n)
|
2015-10-27 11:00:48 +02:00
|
|
|
int a = 0
|
|
|
|
int b = 1
|
2015-11-14 00:22:00 +02:00
|
|
|
while_plus( n - 2)
|
|
|
|
n = n - 1
|
2015-10-27 11:00:48 +02:00
|
|
|
int tmp = a
|
|
|
|
a = b
|
|
|
|
b = tmp + b
|
|
|
|
end
|
|
|
|
b.putint()
|
|
|
|
return b
|
2015-10-06 00:27:13 +03:00
|
|
|
end
|
2014-06-07 23:22:32 +03:00
|
|
|
|
2015-10-06 00:27:13 +03:00
|
|
|
int main()
|
2015-11-06 14:24:57 +02:00
|
|
|
return fibonaccit( 100 )
|
2015-10-06 00:27:13 +03:00
|
|
|
end
|
|
|
|
end
|
2014-05-28 15:03:54 +03:00
|
|
|
HERE
|
2015-11-06 14:24:57 +02:00
|
|
|
@string_input.sub!( "100" , num.to_s )
|
|
|
|
end
|
|
|
|
|
2015-11-13 20:44:18 +02:00
|
|
|
def test_while_fibo48
|
|
|
|
fibo 48
|
2015-11-14 00:22:00 +02:00
|
|
|
@length = 1241
|
2015-11-08 15:15:55 +02:00
|
|
|
# this is not the correct fibo, just what comes from wrapping (smaller than below)
|
2015-11-18 13:04:57 +02:00
|
|
|
check 512559680
|
2015-11-06 14:24:57 +02:00
|
|
|
end
|
|
|
|
|
2015-11-13 20:44:18 +02:00
|
|
|
# highest 32 bit fibo
|
|
|
|
def test_while_fibo47
|
|
|
|
fibo 47
|
2015-11-14 00:22:00 +02:00
|
|
|
@length = 1216
|
2015-11-18 13:04:57 +02:00
|
|
|
check 2971215073
|
2014-05-28 15:03:54 +03:00
|
|
|
end
|
2014-06-05 16:27:25 +03:00
|
|
|
|
2014-05-28 15:03:54 +03:00
|
|
|
end
|