diff --git a/03-hamming/hamming.rb b/03-hamming/hamming.rb index e69de29..9acda49 100644 --- a/03-hamming/hamming.rb +++ b/03-hamming/hamming.rb @@ -0,0 +1,17 @@ +class Hamming + def self.compute(a,b) + i = 1 + counter = 0 + + if (a.length-b.length) != 0 + raise ArgumentError.new("First strand cannot be longer than second") + end + until (i > a.length || i > b.length) + if a[i-1] != b[i-1] + counter += 1 + end + i += 1 + end + return counter + end +end diff --git a/03-hamming/hamming_spec.rb b/03-hamming/hamming_spec.rb index 4af958b..8a1a924 100644 --- a/03-hamming/hamming_spec.rb +++ b/03-hamming/hamming_spec.rb @@ -12,62 +12,50 @@ end it "Check complete distance in single nucleotide strands" do - skip expect(Hamming.compute('A', 'G')).must_equal 1 end it "Check complete distance in small strands" do - skip expect(Hamming.compute('AG', 'CT')).must_equal 2 end it "Check small distance in small strands" do - skip expect(Hamming.compute('AT', 'CT')).must_equal 1 end it "Check small distance" do - skip expect(Hamming.compute('GGACG', 'GGTCG')).must_equal 1 end it "Check small distance in long strands" do - skip expect(Hamming.compute('ACCAGGG', 'ACTATGG')).must_equal 2 end it "Check non_unique character in first strand" do - skip expect(Hamming.compute('AGA', 'AGG')).must_equal 1 end it "Check non unique character in second strand" do - skip expect(Hamming.compute('AGG', 'AGA')).must_equal 1 end it "Check large_distance" do - skip expect(Hamming.compute('GATACA', 'GCATAA')).must_equal 4 end it "Check large distance in off by one strand" do - skip expect(Hamming.compute('GGACGGATTCTG', 'AGGACGGATTCT')).must_equal 9 end it "Check Empty Strands" do - skip expect(Hamming.compute('', '')).must_equal 0 end it "Check disallow first strand longer" do - skip expect ( proc { Hamming.compute('AATG', 'AAA') }).must_raise ArgumentError end it "Check disallow second strand longer" do - skip expect( proc { Hamming.compute('ATA', 'AGTG') }).must_raise ArgumentError end end