mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Complete Integer Tests for ISO
This commit is contained in:
@@ -56,3 +56,116 @@ assert('Integer#==', '15.2.8.3.7') do
|
||||
a == false and b == true
|
||||
end
|
||||
|
||||
assert('Integer#~', '15.2.8.3.8') do
|
||||
# Complement
|
||||
~0 == -1 and ~2 == -3
|
||||
end
|
||||
|
||||
assert('Integer#&', '15.2.8.3.9') do
|
||||
# Bitwise AND
|
||||
# 0101 (5)
|
||||
# & 0011 (3)
|
||||
# = 0001 (1)
|
||||
5 & 3 == 1
|
||||
end
|
||||
|
||||
assert('Integer#|', '15.2.8.3.10') do
|
||||
# Bitwise OR
|
||||
# 0101 (5)
|
||||
# | 0011 (3)
|
||||
# = 0111 (7)
|
||||
5 | 3 == 7
|
||||
end
|
||||
|
||||
assert('Integer#^', '15.2.8.3.11') do
|
||||
# Bitwise XOR
|
||||
# 0101 (5)
|
||||
# ^ 0011 (3)
|
||||
# = 0110 (6)
|
||||
5 ^ 3 == 6
|
||||
end
|
||||
|
||||
assert('Integer#<<', '15.2.8.3.12') do
|
||||
# Left Shift by one
|
||||
# 00010111 (23)
|
||||
# = 00101110 (46)
|
||||
23 << 1 == 46
|
||||
end
|
||||
|
||||
assert('Integer#>>', '15.2.8.3.13') do
|
||||
# Right Shift by one
|
||||
# 00101110 (46)
|
||||
# = 00010111 (23)
|
||||
46 >> 1 == 23
|
||||
end
|
||||
|
||||
assert('Integer#ceil', '15.2.8.3.14') do
|
||||
10.ceil == 10
|
||||
end
|
||||
|
||||
assert('Integer#downto', '15.2.8.3.15') do
|
||||
a = 0
|
||||
3.downto(1) do |i|
|
||||
a += i
|
||||
end
|
||||
a == 6
|
||||
end
|
||||
|
||||
assert('Integer#eql?', '15.2.8.3.16') do
|
||||
a = 1.eql?(1)
|
||||
b = 1.eql?(2)
|
||||
c = 1.eql?(nil)
|
||||
|
||||
a == true and b == false and c == false
|
||||
end
|
||||
|
||||
assert('Integer#floor', '15.2.8.3.17') do
|
||||
a = 1.floor
|
||||
|
||||
a == 1
|
||||
end
|
||||
|
||||
assert('Integer#next', '15.2.8.3.19') do
|
||||
1.next == 2
|
||||
end
|
||||
|
||||
assert('Integer#round', '15.2.8.3.20') do
|
||||
1.round == 1
|
||||
end
|
||||
|
||||
assert('Integer#succ', '15.2.8.3.21') do
|
||||
1.succ == 2
|
||||
end
|
||||
|
||||
assert('Integer#times', '15.2.8.3.22') do
|
||||
a = 0
|
||||
3.times do
|
||||
a += 1
|
||||
end
|
||||
a == 3
|
||||
end
|
||||
|
||||
assert('Integer#to_f', '15.2.8.3.23') do
|
||||
1.to_f == 1.0
|
||||
end
|
||||
|
||||
assert('Integer#to_i', '15.2.8.3.24') do
|
||||
1.to_i == 1
|
||||
end
|
||||
|
||||
assert('Integer#to_s', '15.2.8.3.25') do
|
||||
1.to_s == '1' and -1.to_s == "-1"
|
||||
end
|
||||
|
||||
assert('Integer#truncate', '15.2.8.3.26') do
|
||||
1.truncate == 1
|
||||
end
|
||||
|
||||
assert('Integer#upto', '15.2.8.3.27') do
|
||||
a = 0
|
||||
1.upto(3) do |i|
|
||||
a += i
|
||||
end
|
||||
a == 6
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user