Merge pull request #1435 from Bovi-Li/test-fix-order

[mrbtest] assert_equal(expect, actual) order fix
This commit is contained in:
Yukihiro "Matz" Matsumoto
2013-08-04 17:40:18 -07:00
11 changed files with 82 additions and 86 deletions
+10 -11
View File
@@ -4,41 +4,40 @@
assert("Enumerable#drop") do
a = [1, 2, 3, 4, 5, 0]
assert_equal a.drop(3), [4, 5, 0]
assert_equal a.drop(6), []
assert_equal [4, 5, 0], a.drop(3)
assert_equal [], a.drop(6)
end
assert("Enumerable#drop_while") do
a = [1, 2, 3, 4, 5, 0]
assert_equal a.drop_while {|i| i < 3 }, [3, 4, 5, 0]
assert_equal [3, 4, 5, 0], a.drop_while {|i| i < 3 }
end
assert("Enumerable#take") do
a = [1, 2, 3, 4, 5, 0]
assert_equal a.take(3), [1, 2, 3]
assert_equal [1, 2, 3], a.take(3)
end
assert("Enumerable#take_while") do
a = [1, 2, 3, 4, 5, 0]
assert_equal a.take_while {|i| i < 3 }, [1, 2]
assert_equal [1, 2], a.take_while {|i| i < 3}
end
assert("Enumerable#each_cons") do
a = []
(1..5).each_cons(3){|e| a << e}
assert_equal a, [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
assert_equal [[1, 2, 3], [2, 3, 4], [3, 4, 5]], a
end
assert("Enumerable#each_slice") do
a = []
(1..10).each_slice(3){|e| a << e}
assert_equal a, [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
assert_equal [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]], a
end
assert("Enumerable#group_by") do
r = (1..6).group_by {|i| i % 3 }
assert_equal r[0], [3, 6]
assert_equal r[1], [1, 4]
assert_equal r[2], [2, 5]
assert_equal [3, 6], r[0]
assert_equal [1, 4], r[1]
assert_equal [2, 5], r[2]
end
+5 -7
View File
@@ -12,15 +12,13 @@ assert('Hash#merge!') do
original
end
result_1 == {'abc_key' => 'abc_value', 'cba_key' => 'XXX',
'xyz_key' => 'xyz_value' } and
result_2 == {'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
'xyz_key' => 'xyz_value' }
assert_equal({'abc_key' => 'abc_value', 'cba_key' => 'XXX',
'xyz_key' => 'xyz_value' }, result_1)
assert_equal({'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
'xyz_key' => 'xyz_value' }, result_2)
end
assert('Hash#values_at') do
h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
result = h.values_at("cow", "cat")
result == ["bovine", "feline"]
assert_equal ["bovine", "feline"], h.values_at("cow", "cat")
end
+2 -2
View File
@@ -2,8 +2,8 @@
# Numeric(Ext) Test
assert('Integer#chr') do
assert_equal(65.chr, "A")
assert_equal(0x42.chr, "B")
assert_equal("A", 65.chr)
assert_equal("B", 0x42.chr)
# multibyte encoding (not support yet)
assert_raise(RangeError) { 12345.chr }
+3 -3
View File
@@ -1,11 +1,11 @@
assert('NilClass#to_a') do
assert_equal nil.to_a, []
assert_equal [], nil.to_a
end
assert('NilClass#to_f') do
assert_equal nil.to_f, 0.0
assert_equal 0.0, nil.to_f
end
assert('NilClass#to_i') do
assert_equal nil.to_i, 0
assert_equal 0, nil.to_i
end
+1 -1
View File
@@ -5,5 +5,5 @@ assert('Object#instance_exec') do
end
end
k = KlassWithSecret.new
assert_equal k.instance_exec(5) {|x| @secret+x }, 104
assert_equal 104, k.instance_exec(5) {|x| @secret+x }
end
+29 -30
View File
@@ -1,38 +1,37 @@
assert('ObjectSpace.count_objects') do
h = {}
ObjectSpace.count_objects(h)
assert_kind_of(Hash, h)
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
assert_true(h.values.all? {|x| x.is_a?(Integer) })
h = {}
ObjectSpace.count_objects(h)
assert_kind_of(Hash, h)
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
assert_true(h.values.all? {|x| x.is_a?(Integer) })
assert_true(h.has_key?(:TOTAL))
assert_true(h.has_key?(:FREE))
assert_true(h.has_key?(:TOTAL))
assert_true(h.has_key?(:FREE))
h = ObjectSpace.count_objects
assert_kind_of(Hash, h)
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
assert_true(h.values.all? {|x| x.is_a?(Integer) })
h = ObjectSpace.count_objects
assert_kind_of(Hash, h)
assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
assert_true(h.values.all? {|x| x.is_a?(Integer) })
assert_raise(TypeError) { ObjectSpace.count_objects(1) }
assert_raise(TypeError) { ObjectSpace.count_objects(1) }
h0 = {:MRB_TT_FOO=>1000}
h = ObjectSpace.count_objects(h0)
assert_false(h0.has_key?(:MRB_TT_FOO))
h0 = {:MRB_TT_FOO=>1000}
h = ObjectSpace.count_objects(h0)
assert_false(h0.has_key?(:MRB_TT_FOO))
GC.start
h_after = {}
h_before = ObjectSpace.count_objects
GC.start
h_after = {}
h_before = ObjectSpace.count_objects
objs = []
1000.times do
objs << {}
end
objs = nil
ObjectSpace.count_objects(h)
GC.start
ObjectSpace.count_objects(h_after)
objs = []
1000.times do
objs << {}
end
objs = nil
ObjectSpace.count_objects(h)
GC.start
ObjectSpace.count_objects(h_after)
assert_equal(h_before[:MRB_TT_HASH] + 1000, h[:MRB_TT_HASH])
assert_equal(h_before[:MRB_TT_HASH], h_after[:MRB_TT_HASH])
end
assert_equal(h[:MRB_TT_HASH], h_before[:MRB_TT_HASH] + 1000)
assert_equal(h_after[:MRB_TT_HASH], h_before[:MRB_TT_HASH])
end
+8 -8
View File
@@ -8,24 +8,24 @@ end
assert('Proc#===') do
proc = Proc.new {|a| a * 2}
assert_equal (proc === 10), 20
assert_equal 20, (proc === 10)
end
assert('Proc#yield') do
proc = Proc.new {|a| a * 2}
assert_equal proc.yield(10), 20
assert_equal 20, proc.yield(10)
end
assert('Proc#curry') do
b = proc {|x, y, z| (x||0) + (y||0) + (z||0) }
assert_equal b.curry[1][2][3], 6
assert_equal b.curry[1, 2][3, 4], 6
assert_equal b.curry(5)[1][2][3][4][5], 6
assert_equal b.curry(5)[1, 2][3, 4][5], 6
assert_equal b.curry(1)[1], 1
assert_equal 6, b.curry[1][2][3]
assert_equal 6, b.curry[1, 2][3, 4]
assert_equal 6, b.curry(5)[1][2][3][4][5]
assert_equal 6, b.curry(5)[1, 2][3, 4][5]
assert_equal 1, b.curry(1)[1]
b = lambda {|x, y, z| (x||0) + (y||0) + (z||0) }
assert_equal b.curry[1][2][3], 6
assert_equal 6, b.curry[1][2][3]
assert_raise(ArgumentError) { b.curry[1, 2][3, 4] }
assert_raise(ArgumentError) { b.curry(5) }
assert_raise(ArgumentError) { b.curry(1) }
+6 -6
View File
@@ -8,13 +8,13 @@ assert('Range#cover?') do
end
assert('Range#first') do
assert_equal (10..20).first, 10
assert_equal (10..20).first(3), [10, 11, 12]
assert_equal 10, (10..20).first
assert_equal [10, 11, 12], (10..20).first(3)
end
assert('Range#last') do
assert_equal (10..20).last, 20
assert_equal (10...20).last, 20
assert_equal (10..20).last(3), [18, 19, 20]
assert_equal (10...20).last(3), [17, 18, 19]
assert_equal 20, (10..20).last
assert_equal 20, (10...20).last
assert_equal [18, 19, 20], (10..20).last(3)
assert_equal [17, 18, 19], (10...20).last(3)
end
+6 -6
View File
@@ -74,8 +74,8 @@ assert('String#rstrip!') do
end
assert('String#swapcase') do
assert_equal "Hello".swapcase, "hELLO"
assert_equal "cYbEr_PuNk11".swapcase, "CyBeR_pUnK11"
assert_equal "hELLO", "Hello".swapcase
assert_equal "CyBeR_pUnK11", "cYbEr_PuNk11".swapcase
end
assert('String#swapcase!') do
@@ -95,10 +95,10 @@ assert('String#concat') do
end
assert('String#casecmp') do
assert_equal "abcdef".casecmp("abcde"), 1
assert_equal "aBcDeF".casecmp("abcdef"), 0
assert_equal "abcdef".casecmp("abcdefg"),-1
assert_equal "abcdef".casecmp("ABCDEF"), 0
assert_equal 1, "abcdef".casecmp("abcde")
assert_equal 0, "aBcDeF".casecmp("abcdef")
assert_equal(-1, "abcdef".casecmp("abcdefg"))
assert_equal 0, "abcdef".casecmp("ABCDEF")
end
assert('String#start_with?') do
+2 -2
View File
@@ -2,11 +2,11 @@
# Symbol(Ext) Test
assert('Symbol#to_proc') do
assert_equal :abs.to_proc[-5], 5
assert_equal 5, :abs.to_proc[-5]
end
assert('Symbol.all_symbols') do
foo = [:__symbol_test_1, :__symbol_test_2, :__symbol_test_3].sort
symbols = Symbol.all_symbols.select{|sym|sym.to_s.include? '__symbol_test'}.sort
assert_equal symbols, foo
assert_equal foo, symbols
end
+10 -10
View File
@@ -1,19 +1,19 @@
##
# Toplevel Self(Ext) Test
module ToplevelTestModule1
def method_foo
:foo
assert('Toplevel#include') do
module ToplevelTestModule1
def method_foo
:foo
end
CONST_BAR = :bar
end
CONST_BAR = :bar
end
module ToplevelTestModule2
CONST_BAR = :bar2
end
module ToplevelTestModule2
CONST_BAR = :bar2
end
assert('Toplevel#include') do
self.include ToplevelTestModule2, ToplevelTestModule1
assert_true self.class.included_modules.include?( ToplevelTestModule1 )