644
651
assert_equal([], expected - vals)
654
def test_security_check
656
assert_raise(SecurityError) do
664
def test_intialize_wrong_arguments
665
assert_raise(ArgumentError) do
671
assert_equal({1=>2, 3=>4}, Hash[[[1,2],[3,4]]])
672
assert_raise(ArgumentError) { Hash[0, 1, 2] }
673
assert_equal({1=>2, 3=>4}, Hash[1,2,3,4])
678
assert_equal(h.dup, h.rehash)
679
assert_raise(RuntimeError) { h.each { h.rehash } }
680
assert_equal({}, {}.rehash)
684
assert_equal(:bar, @h.fetch(0, :foo) { :bar })
687
def test_default_proc
688
h = Hash.new {|h, k| h + k + "baz" }
689
assert_equal("foobarbaz", h.default_proc.call("foo", "bar"))
691
assert_nil(h.default_proc)
695
h = Hash.new {|h, k| :foo }
697
assert_equal([1, 2], h.shift)
698
assert_equal(:foo, h.shift)
699
assert_equal(:foo, h.shift)
703
assert_equal([1, 2], h.shift)
704
assert_equal(:foo, h.shift)
705
assert_equal(:foo, h.shift)
708
h.each { assert_equal([1, 2], h.shift) }
711
def test_reject_bang2
712
assert_equal({1=>2}, {1=>2,3=>4}.reject! {|k, v| k + v == 7 })
713
assert_nil({1=>2,3=>4}.reject! {|k, v| k == 5 })
714
assert_nil({}.reject! { })
718
assert_equal({3=>4,5=>6}, {1=>2,3=>4,5=>6}.select {|k, v| k + v >= 7 })
722
assert_equal({}, {1=>2,3=>4,5=>6}.clear)
729
h1 = Hash.new { :foo }
732
assert_equal(:foo, h2[0])
736
assert_equal(0, {}.size)
742
def o.to_hash; {}; end
743
def o.==(x); true; end
745
def o.==(x); false; end
748
h1 = {1=>2}; h2 = {3=>4}
750
h1 = {1=>2}; h2 = {1=>4}
753
h1 = {}; h1[h1] = h1; h1.rehash
754
h2 = {}; h2[h2] = h2; h2.rehash
759
assert(!({}.eql?(0)))
761
def o.to_hash; {}; end
762
def o.eql?(x); true; end
764
def o.eql?(x); false; end
765
assert(!({}.eql?(o)))
769
assert_kind_of(Integer, {}.hash)
775
h1.update(h2) {|k, v1, v2| k + v1 + v2 }
776
assert_equal({1=>6, 3=>4, 5=>7}, h1)
782
assert_equal({1=>3, 3=>4, 5=>7}, h1.merge(h2))
783
assert_equal({1=>6, 3=>4, 5=>7}, h1.merge(h2) {|k, v1, v2| k + v1 + v2 })
787
assert_equal([3,4], {1=>2, 3=>4, 5=>6}.assoc(3))
788
assert_nil({1=>2, 3=>4, 5=>6}.assoc(4))
792
assert_equal([3,4], {1=>2, 3=>4, 5=>6}.rassoc(4))
793
assert_nil({1=>2, 3=>4, 5=>6}.rassoc(3))
797
assert_equal([[1], [2]], {[1] => [2]}.flatten)
804
h.each { callcc {|c2| c = c2 } }
809
assert_raise(RuntimeError) { h.each { h.rehash } }
813
assert_raise(RuntimeError) do
814
h.each { callcc {|c2| c = c2 } }
820
def test_compare_by_identity
822
assert(!{}.compare_by_identity?)
824
assert(!h.compare_by_identity?)
825
h.compare_by_identity
826
assert(h.compare_by_identity?)
827
#assert_equal("bar", h[a])