From 48a49d354e34687f5edcb56fdf618eb97e9842bc Mon Sep 17 00:00:00 2001 From: Tirthankar Bhattacharjee Date: Thu, 20 Nov 2014 14:26:54 -0500 Subject: [PATCH 1/4] add solution --- spec/refresher_spec.rb | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/spec/refresher_spec.rb b/spec/refresher_spec.rb index 1f2c4ce..8b3bfe5 100644 --- a/spec/refresher_spec.rb +++ b/spec/refresher_spec.rb @@ -5,70 +5,71 @@ context "guess the collection" do it "Yes, it is a Object, but which class" do - expect([].is_a? _fill_in_object_).to be true - expect(Array.new.instance_of? _FILL_ME_IN_).to be true + expect([].is_a? Object).to be true + expect(Array.new.instance_of? Array).to be true end it "Yes, it is a Object, but which class" do - expect({}.is_a? _fill_in_object_).to be true - expect(Hash.new.instance_of? _FILL_ME_IN_).to be true + expect({}.is_a? Object).to be true + expect(Hash.new.instance_of? Hash).to be true end end context "guess the type" do it "Yes, it is a Object, but which" do - expect(:class.is_a? _fill_in_object_).to be true + expect(:class.is_a? Symbol).to be true end it "Yes, it is a Object, but which" do - expect("module".is_a? _fill_in_object_).to be true + expect("module".is_a? String).to be true end it "Yes, it is a Object, but which" do - expect(1.is_a? _fill_in_object_).to be true + expect(1.is_a? Integer).to be true end it "Yes, it is a Object, but which" do - expect(1.5.is_a? _fill_in_object_).to be true + expect(1.5.is_a? Float).to be true end end context "the following are Array methods" do it "adds a thing to the end of the method" do - expect([]._fill_in_method_here_(1)).to eq [1] + expect([].push(1)).to eq [1] end it "removes an item from the end of an array" do - expect([1]._fill_in_method_here_).to eq 1 + expect([1].pop).to eq 1 end it "adds an item to the front of an array" do - expect([1]._fill_in_method_here_("banana")).to eq ["banana", 1] + expect([1].unshift("banana")).to eq ["banana", 1] end it "removes an item from the front of an array" do - expect([1, "banana"]._fill_in_method_here_).to eq ["banana"] + expect([1, "banana"].drop(1)).to eq ["banana"] end end context "the following are Hash methods" do it "adds a key and value to a Hash" do a_hash = {} - fail "remove this entire line, implement your solution here" + # fail "remove this entire line, implement your solution here" + a_hash[:foo] = "bar" expect(a_hash.empty?).to be false end it "returns a value from the hash for the given key" do a_hash = {magic: :johnson, shirley: :temple, "babe" => "ruth"} - expect(a_hash.fetch(:magic)).to eq _fill_in_sym_or_str - expect(a_hash[:shirley]).to eq _fill_in_sym_or_str - expect(a_hash["babe"]).to eq _fill_in_sym_or_str + expect(a_hash.fetch(:magic)).to eq :johnson + expect(a_hash[:shirley]).to eq :temple + expect(a_hash["babe"]).to eq "ruth" end it "removes a key value pair from a hash" do a_hash = { frank: :sinatra } - a_hash._fill_in_method_here_(:frank) + a_hash.delete(:frank) expect(a_hash.empty?).to be true end end @@ -76,7 +77,7 @@ context "on loops, yeah!!!" do it "should loop over the array and return a new array" do loopy = [1,2,3] - expect(loopy._fill_in_method_here_ { |n| n + 1 }).to eq [2,3,4] + expect(loopy.map { |n| n + 1 }).to eq [2,3,4] end end From 782e0c52e9fb2adb20cca42fa57e826aa1a1514a Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 22 May 2020 11:18:43 -0400 Subject: [PATCH 2/4] Add solutions for all but last problem --- spec/refresher_spec.rb | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/spec/refresher_spec.rb b/spec/refresher_spec.rb index 3766252..61434b7 100644 --- a/spec/refresher_spec.rb +++ b/spec/refresher_spec.rb @@ -5,70 +5,70 @@ context "guess the collection" do it "Yes, it is a Object, but which class" do - expect([].is_a? _fill_in_object_).to be true - expect(Array.new.instance_of? _FILL_ME_IN_).to be true + expect([].is_a? Array).to be true + expect(Array.new.instance_of? Array).to be true end it "Yes, it is a Object, but which class" do - expect({}.is_a? _fill_in_object_).to be true - expect(Hash.new.instance_of? _FILL_ME_IN_).to be true + expect({}.is_a? Hash).to be true + expect(Hash.new.instance_of? Hash).to be true end end context "guess the type" do it "Yes, it is a Object, but which" do - expect(:class.is_a? _fill_in_object_).to be true + expect(:class.is_a? Symbol).to be true end it "Yes, it is a Object, but which" do - expect("module".is_a? _fill_in_object_).to be true + expect("module".is_a? String).to be true end it "Yes, it is a Object, but which" do - expect(1.is_a? _fill_in_object_).to be true + expect(1.is_a? Integer).to be true end it "Yes, it is a Object, but which" do - expect(1.5.is_a? _fill_in_object_).to be true + expect(1.5.is_a? Float).to be true end end context "the following are Array methods" do it "adds a thing to the end of the method" do - expect([]._fill_in_method_here_(1)).to eq [1] + expect([].append(1)).to eq [1] end it "removes an item from the end of an array" do - expect([1]._fill_in_method_here_).to eq 1 + expect([1].pop).to eq 1 end it "adds an item to the front of an array" do - expect([1]._fill_in_method_here_("banana")).to eq ["banana", 1] + expect([1].unshift("banana")).to eq ["banana", 1] end it "removes an item from the front of an array" do - expect([1, "banana"]._fill_in_method_here_).to eq 1 + expect([1, "banana"].shift).to eq 1 end end context "the following are Hash methods" do it "adds a key and value to a Hash" do a_hash = {} - fail "remove this entire line, implement your solution here" + a_hash[:jeff] = "Is cool" expect(a_hash.empty?).to be false end it "returns a value from the hash for the given key" do a_hash = {magic: :johnson, shirley: :temple, "babe" => "ruth"} - expect(a_hash.fetch(:magic)).to eq _fill_in_sym_or_str - expect(a_hash[:shirley]).to eq _fill_in_sym_or_str - expect(a_hash["babe"]).to eq _fill_in_sym_or_str + expect(a_hash.fetch(:magic)).to eq :johnson + expect(a_hash[:shirley]).to eq :temple + expect(a_hash["babe"]).to eq "ruth" end it "removes a key value pair from a hash" do a_hash = { frank: :sinatra } - a_hash._fill_in_method_here_(:frank) + a_hash.delete(:frank) expect(a_hash.empty?).to be true end end @@ -76,7 +76,7 @@ context "on loops, yeah!!!" do it "should loop over the array and return a new array" do loopy = [1,2,3] - expect(loopy._fill_in_method_here_ { |n| n + 1 }).to eq [2,3,4] + expect(loopy.each { |n| n + 1 }).to eq [2,3,4] end end From 50123aeecfb0f60cf193bd976521478ad902895b Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 22 May 2020 11:29:53 -0400 Subject: [PATCH 3/4] Actually fix the merge conflict by saving the file before I commit --- spec/refresher_spec.rb | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/spec/refresher_spec.rb b/spec/refresher_spec.rb index 614b82a..61434b7 100644 --- a/spec/refresher_spec.rb +++ b/spec/refresher_spec.rb @@ -5,20 +5,12 @@ context "guess the collection" do it "Yes, it is a Object, but which class" do -<<<<<<< HEAD expect([].is_a? Array).to be true -======= - expect([].is_a? Object).to be true ->>>>>>> 48a49d354e34687f5edcb56fdf618eb97e9842bc expect(Array.new.instance_of? Array).to be true end it "Yes, it is a Object, but which class" do -<<<<<<< HEAD expect({}.is_a? Hash).to be true -======= - expect({}.is_a? Object).to be true ->>>>>>> 48a49d354e34687f5edcb56fdf618eb97e9842bc expect(Hash.new.instance_of? Hash).to be true end end @@ -43,11 +35,7 @@ context "the following are Array methods" do it "adds a thing to the end of the method" do -<<<<<<< HEAD expect([].append(1)).to eq [1] -======= - expect([].push(1)).to eq [1] ->>>>>>> 48a49d354e34687f5edcb56fdf618eb97e9842bc end it "removes an item from the end of an array" do @@ -59,34 +47,21 @@ end it "removes an item from the front of an array" do -<<<<<<< HEAD expect([1, "banana"].shift).to eq 1 -======= - expect([1, "banana"].drop(1)).to eq ["banana"] ->>>>>>> 48a49d354e34687f5edcb56fdf618eb97e9842bc end end context "the following are Hash methods" do it "adds a key and value to a Hash" do a_hash = {} -<<<<<<< HEAD a_hash[:jeff] = "Is cool" -======= - # fail "remove this entire line, implement your solution here" - a_hash[:foo] = "bar" ->>>>>>> 48a49d354e34687f5edcb56fdf618eb97e9842bc expect(a_hash.empty?).to be false end it "returns a value from the hash for the given key" do a_hash = {magic: :johnson, shirley: :temple, "babe" => "ruth"} -<<<<<<< HEAD expect(a_hash.fetch(:magic)).to eq :johnson -======= - expect(a_hash.fetch(:magic)).to eq :johnson ->>>>>>> 48a49d354e34687f5edcb56fdf618eb97e9842bc expect(a_hash[:shirley]).to eq :temple expect(a_hash["babe"]).to eq "ruth" end @@ -101,11 +76,7 @@ context "on loops, yeah!!!" do it "should loop over the array and return a new array" do loopy = [1,2,3] -<<<<<<< HEAD expect(loopy.each { |n| n + 1 }).to eq [2,3,4] -======= - expect(loopy.map { |n| n + 1 }).to eq [2,3,4] ->>>>>>> 48a49d354e34687f5edcb56fdf618eb97e9842bc end end From ca7d8df44b58a907e9a643b7c0380c93752b27cc Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 22 May 2020 11:52:39 -0400 Subject: [PATCH 4/4] Fix last test by using map instead of each --- spec/refresher_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/refresher_spec.rb b/spec/refresher_spec.rb index 61434b7..6b95c5c 100644 --- a/spec/refresher_spec.rb +++ b/spec/refresher_spec.rb @@ -76,7 +76,7 @@ context "on loops, yeah!!!" do it "should loop over the array and return a new array" do loopy = [1,2,3] - expect(loopy.each { |n| n + 1 }).to eq [2,3,4] + expect(loopy.map { |n| n + 1 }).to eq [2,3,4] end end