2015-11-10 18:09:17 +01:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
class TestPutiRT < MiniTest::Test
|
2015-11-18 12:04:57 +01:00
|
|
|
include ParfaitTests
|
2015-11-10 18:09:17 +01:00
|
|
|
|
2015-11-18 10:29:37 +01:00
|
|
|
def test_mod4_2
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 2.mod4()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 2 % 4
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_mod4_3
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 3.mod4()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 3 % 4
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_mod4_4
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 4.mod4()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 4 % 4
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_mod4_5
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 5.mod4()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 5 % 4
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_mod4_12
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 12.mod4()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 12 % 4
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_mod4_10
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 10.mod4()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 10 % 4
|
2015-11-11 19:36:40 +01:00
|
|
|
end
|
2015-11-13 19:46:27 +01:00
|
|
|
|
|
|
|
# if you multiply i by "by" the return is the high 32 bits
|
|
|
|
def high_times( i , by_high , by_low)
|
|
|
|
by = by_high * 65536 + by_low
|
|
|
|
by *= i
|
|
|
|
by /= 65536
|
|
|
|
by /= 65536
|
|
|
|
return by
|
|
|
|
end
|
|
|
|
|
|
|
|
# if you multiply i by "by" the return is the low 32 bits
|
|
|
|
def low_times( i , by_high , by_low)
|
|
|
|
by = by_high * 65536 + by_low
|
|
|
|
by *= i
|
|
|
|
return (by & 0xffffffff)
|
|
|
|
end
|
|
|
|
|
2015-11-18 10:29:37 +01:00
|
|
|
def test_hightimes2
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 2.high_times(12 , 333)"
|
2015-11-20 12:26:35 +01:00
|
|
|
check high_times(2,12,333)
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_hightimes3456
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 3456.high_times(12 , 333)"
|
2015-11-20 12:26:35 +01:00
|
|
|
check high_times(3456,12,333)
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_hightimes234567
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 234567.high_times(12 , 333)"
|
2015-11-20 12:26:35 +01:00
|
|
|
check high_times(234567,12,333)
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
2015-11-13 19:46:27 +01:00
|
|
|
def test_hightimes
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 234567.high_times(12 , 333)"
|
2015-11-20 12:26:35 +01:00
|
|
|
check high_times(234567,12,333)
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_lowtimes2
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 2.low_times(14 , 33)"
|
2015-11-20 12:26:35 +01:00
|
|
|
check low_times(2,14,33)
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_lowtimes3456
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 3456.low_times(14 , 33)"
|
2015-11-20 12:26:35 +01:00
|
|
|
check low_times(3456,14,33)
|
2015-11-13 19:46:27 +01:00
|
|
|
end
|
2015-11-18 10:29:37 +01:00
|
|
|
def test_lowtimes234567
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 234567.low_times(14 , 33)"
|
2015-11-20 12:26:35 +01:00
|
|
|
check low_times(234567,14,33)
|
2015-11-11 19:36:40 +01:00
|
|
|
end
|
2015-11-12 19:02:14 +01:00
|
|
|
|
2015-11-13 19:46:27 +01:00
|
|
|
# finally settled on the long version in http://www.sciencezero.org/index.php?title=ARM:_Division_by_10
|
|
|
|
# also the last looked good, but some bug is admittedly in all the ones i tried
|
|
|
|
# (off course the bug is not included in the test, but easy to achieve with random numbers )
|
|
|
|
# for high numbers with ending 0 they are all 1 low. Possibly Interpreter bug ?
|
2015-11-18 10:29:37 +01:00
|
|
|
def test_div10_2
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 2.div10()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 2 / 10
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_div10_10
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 10.div10()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 10 / 10
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_div10_12345
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 12345.div10()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 12345 / 10
|
2015-11-18 10:29:37 +01:00
|
|
|
end
|
|
|
|
def test_div10_234567
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 234567.div10()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 234567 / 10
|
2015-11-11 19:36:40 +01:00
|
|
|
end
|
2015-11-13 19:46:27 +01:00
|
|
|
|
2015-11-10 18:09:17 +01:00
|
|
|
def test_as_char1
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 5.as_char()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 53
|
2015-11-10 18:09:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_as_char2
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 10.as_char()"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 32
|
2015-11-10 18:09:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_tos_one_digit
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "Word five = 5.to_s()
|
2015-11-11 19:36:40 +01:00
|
|
|
five.putstring()"
|
2015-11-10 18:09:17 +01:00
|
|
|
@stdout = " 5"
|
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-11-20 12:26:35 +01:00
|
|
|
def test_tos_one_digit_length
|
|
|
|
@main = "Word five = 5.to_s()
|
|
|
|
return five.char_length"
|
|
|
|
check 2
|
|
|
|
end
|
|
|
|
|
2015-11-10 18:09:17 +01:00
|
|
|
def test_tos_zero
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "Word five = 0.to_s()
|
2015-11-20 12:26:35 +01:00
|
|
|
five.putstring()"
|
2015-11-10 18:09:17 +01:00
|
|
|
@stdout = " 0"
|
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tos_two_digit
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "Word five = 15.to_s()
|
2015-11-11 19:36:40 +01:00
|
|
|
five.putstring()"
|
2015-11-10 18:09:17 +01:00
|
|
|
@stdout = " 15"
|
|
|
|
check
|
|
|
|
end
|
|
|
|
|
2015-11-20 12:26:35 +01:00
|
|
|
def test_tos_two_digit_length
|
|
|
|
@main = "Word five = 15.to_s()
|
|
|
|
return five.char_length"
|
|
|
|
check 3
|
|
|
|
end
|
|
|
|
|
2015-11-10 18:09:17 +01:00
|
|
|
def test_tos_three_digit
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "Word five = 150.to_s()
|
2015-11-11 19:36:40 +01:00
|
|
|
five.putstring()"
|
2015-11-10 18:09:17 +01:00
|
|
|
@stdout = " 150"
|
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_puti_four_digit
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "return 1234.puti()"
|
2015-11-10 18:09:17 +01:00
|
|
|
@stdout = " 1234"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 1234
|
2015-11-10 18:09:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_puti_seven_digit
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "int i = 301 * 4096
|
2015-11-14 12:05:49 +01:00
|
|
|
i = i + 1671
|
|
|
|
return i.puti()"
|
2015-11-10 18:09:17 +01:00
|
|
|
@stdout = " 1234567"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 1234567
|
2015-11-10 18:09:17 +01:00
|
|
|
end
|
2015-11-20 18:12:58 +01:00
|
|
|
|
2015-11-20 12:26:35 +01:00
|
|
|
def test_puti_seven_digit_length
|
|
|
|
@main = "int i = 301 * 4096
|
|
|
|
Word str = i.to_s()
|
|
|
|
return str.char_length"
|
|
|
|
check 8
|
|
|
|
end
|
|
|
|
|
2015-11-14 12:05:49 +01:00
|
|
|
def test_puti_eight_digit
|
2015-11-18 12:04:57 +01:00
|
|
|
@main = "int i = 3014 * 4096
|
2015-11-14 12:05:49 +01:00
|
|
|
i = i + 334
|
|
|
|
return i.puti()"
|
|
|
|
@stdout = " 12345678"
|
2015-11-20 12:26:35 +01:00
|
|
|
check 12345678
|
2015-11-10 18:09:17 +01:00
|
|
|
end
|
2015-11-20 18:12:58 +01:00
|
|
|
|
|
|
|
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
|
2015-11-10 18:09:17 +01:00
|
|
|
end
|