Sha256: d2a969a7bc3ec7a6189d3d7c9ed50978249fe90c8aa07fc2cdfae90b08013f71

Contents?: true

Size: 1.2 KB

Versions: 20

Compression:

Stored size: 1.2 KB

Contents

require "#{File.dirname(__FILE__)}/../../test_helper"

class HashTest < Test::Unit::TestCase
  context "Hash" do
    setup do
      @hsh = {:a => "a", :b => "b", :c => "c"}
    end
    
    should "have choose to select hashes" do      
      assert_equal @hsh.choose {|k,v| k == :a}, {:a => "a"}
      assert_equal @hsh.choose {|k,v| k == :z}, {}
      assert_equal @hsh.choose {|k,v|[:b,:a].include?(k)}.keys.sort{|a,b|"#{a}"<=>"#{b}"}, [:a,:b]
    end
            
    should "be able to call methods on the hash of their keys" do
      assert_equal @hsh.a, "a"
      assert_equal @hsh.b, "b"
      assert_equal @hsh.c, "c"
    end
    
    should "compute the differences in the hashes" do
      assert_equal ({:a => "a"}).diff({:a => "a"}), {}
      assert_equal ({:a => "a"}).diff({:a => "b"}), {:a => "b"}
      assert_equal ({:a => "a", :b => "b"}).diff({:a => "b"}, :a), {:a => "b"}
      assert_equal ({:a => "a", :b => "b"}).diff({:b => "b"}, :b), {}
      assert_equal ({:a => "a", :b => "b"}).diff({:b => "c"}, :b), {:b => "c"}
      assert_equal ({:a => "a", :b => "b"}).diff({:b => "c"}), {:b => "c", :a => nil}
      assert_equal ({:a => "a", :b => "b"}).diff({:b => "c"}, :a), {:a => nil}
    end
    
  end
  
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
poolparty-1.6.9 test/lib/core/hash_test.rb
poolparty-1.6.8 test/lib/core/hash_test.rb
poolparty-1.6.7 test/lib/core/hash_test.rb
poolparty-1.6.6 test/lib/core/hash_test.rb
poolparty-1.6.5 test/lib/core/hash_test.rb
poolparty-1.6.4 test/lib/core/hash_test.rb
poolparty-1.6.3 test/lib/core/hash_test.rb
poolparty-1.6.2 test/lib/core/hash_test.rb
poolparty-1.6.1 test/lib/core/hash_test.rb
poolparty-1.6.0 test/lib/core/hash_test.rb
poolparty-1.5.0 test/lib/core/hash_test.rb
poolparty-1.4.8 test/lib/core/hash_test.rb
poolparty-1.4.7 test/lib/core/hash_test.rb
poolparty-1.4.6 test/lib/core/hash_test.rb
poolparty-1.4.5 test/lib/core/hash_test.rb
poolparty-1.4.4 test/lib/core/hash_test.rb
poolparty-1.4.3 test/lib/core/hash_test.rb
poolparty-1.4.2 test/lib/core/hash_test.rb
poolparty-1.4.1 test/lib/core/hash_test.rb
poolparty-1.4.0 test/lib/core/hash_test.rb