Commit e129a4c8 authored by Masaki Muranaka's avatar Masaki Muranaka

Add test cases.

parent 6bd49a3d
......@@ -272,7 +272,7 @@ assert('Array#unshift', '15.2.12.5.30') do
a == [1,2,3] and b == [1,2,3] and c == [0,1,2,3] and d == [0,1,2,3]
end
assert('Array#to_s', '15.2.12.5.31') do
assert('Array#to_s', '15.2.12.5.31 / 15.2.12.5.32') do
a = [2, 3, 4, 5]
r1 = a.to_s
r2 = a.inspect
......@@ -288,6 +288,20 @@ assert('Array#==', '15.2.12.5.33') do
r1 == false and r2 == true and r3 == false
end
assert('Array#eql?', '15.2.12.5.34') do
a1 = [ 1, 2, 3 ]
a2 = [ 1, 2, 3 ]
a3 = [ 1.0, 2.0, 3.0 ]
(a1.eql? a2) and (not a1.eql? a3)
end
assert('Array#hash', '15.2.12.5.35') do
a = [ 1, 2, 3 ]
a.hash.is_a? Integer
end
assert('Array#<=>', '15.2.12.5.36') do
r1 = [ "a", "a", "c" ] <=> [ "a", "b", "c" ] #=> -1
r2 = [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1
......
......@@ -9,6 +9,26 @@ assert('Class superclass', '15.2.3.2') do
Class.superclass == Module
end
# Class#initialize '15.2.3.3.1' is tested in Class#new
assert('Class#initialize_copy', '15.2.3.3.2') do
class TestClass
attr_accessor :n
def initialize(n)
@n = n
end
def initialize_copy(obj)
@n = n
end
end
c1 = TestClass.new('Foo')
c2 = c1.dup
c3 = TestClass.new('Bar')
c1.n == c2.n and c1.n != c3.n
end
assert('Class#new', '15.2.3.3.3') do
# at the moment no exception on singleton class
#e1 = nil
......
......@@ -138,7 +138,18 @@ assert('Hash#include?', '15.2.13.4.15') do
a.include?('abc_key') and not b.include?('cba')
end
assert('Hash#initialize copy', '15.2.13.4.17') do
assert('Hash#initialize', '15.2.13.4.16') do
# Testing initialize by new.
h = Hash.new
h2 = Hash.new(:not_found)
h.is_a? Hash and
h == { } and
h["hello"] == nil and
h2["hello"] == :not_found
end
assert('Hash#initialize_copy', '15.2.13.4.17') do
a = { 'abc_key' => 'abc_value' }
b = Hash.new.initialize_copy(a)
......
......@@ -129,6 +129,21 @@ assert('Module#const_get', '15.2.2.4.23') do
Test4ConstSet.const_get(:Const4Test4ConstSet) == 23
end
assert('Module.constants', '15.2.2.4.24') do
$n = []
module TestA
Const = 1
end
class TestB
include TestA
Const2 = 1
$n = constants.sort
end
TestA.constants == [ :Const ] and
$n == [ :Const, :Const2 ]
end
assert('Module#include', '15.2.2.4.27') do
module Test4Include
Const4Include = 42
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment