Last active
December 28, 2015 07:09
-
-
Save adamloo85/7462522 to your computer and use it in GitHub Desktop.
Revisions
-
adamloo85 renamed this gist
Nov 14, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
adamloo85 renamed this gist
Nov 14, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
adamloo85 created this gist
Nov 14, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ require 'rubygems' require 'shoulda-context' class HashFake def initialize(size=0) @body = Array.new(size) end def body @body end def insert(key, value) key = make_key(key) pair = [key, value] check_key(key) ? change_key(key, value) : @body << pair end def find_value(key) check_key(key) ? @body[index(key)][1] : nil end def delete_pair(key) check_key(key) ? @body.delete_at(index(key)) : nil end private def make_key(key) key = key.to_sym unless key.instance_of? Symbol end def check_key(key) @body.each { |k, v| return true if k == key } return false end def change_key(key, value) @body[index(key)][1] = value end def index(key) index = @body.find_index {|k, v| k == key} end end class HashTest < Test::Unit::TestCase context "hash" do setup do @hash = HashFake.new end should "have the correct class" do assert_equal HashFake, @hash.class end context "adding, deleting, fetching" do should "" end end end