ruby fibs versions and tests for them

This commit is contained in:
Torsten Ruger 2015-11-20 19:12:58 +02:00
parent 9bcead4c1a
commit da4003c30a
2 changed files with 60 additions and 1 deletions

View File

@ -117,4 +117,32 @@ class Integer < Value
int mod4()
return self & 3
end
int fibr( )
if_plus( self - 2 )
int tmp
tmp = self - 1
int a = tmp.fibr( )
tmp = self - 2
int b = tmp.fibr( )
return a + b
else
return self
end
end
int fibw( )
int result = 1
int a = 0
int b = 1
int i = 2
while_plus( self - i )
result = a + b
a = b
b = result
i = i + 1
end
return result
end
end

View File

@ -157,7 +157,7 @@ five.putstring()"
@stdout = " 1234567"
check 1234567
end
def test_puti_seven_digit_length
@main = "int i = 301 * 4096
Word str = i.to_s()
@ -172,4 +172,35 @@ five.putstring()"
@stdout = " 12345678"
check 12345678
end
def test_fibr8
@main = "int fib = 8.fibr( )
return fib.puti()"
@stdout = " 21"
check 21
end
def test_fibw8
@main = "int fib = 8.fibw( )
return fib.puti()"
@stdout = " 21"
check 21
end
def test_fibw20
@main = "int fib = 20.fibw( )
return fib.puti()"
@stdout = " 6765"
check 6765
end
def test_fib40_1000000
@main = "int count = 999424
count = count + 576
while_plus( count - 1)
40.fibw( )
count = count - 1
end
return count"
check 0
end
end