Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions hamming.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Hamming

def self.compute(seq1,seq2)
unless seq1.length == seq2.length
raise ArgumentError.new("The lengths of the strands must be equal.")
end

@array1 = seq1.split(//)
@array2 = seq2.split(//)
@count = 0
next_elements
count_differences(@element1,@element2)
end

def self.count_differences(element1,element2)
if @element1 == nil
return @count
end

if element1 != element2
@count += 1
next_elements
count_differences(@element1,@element2)
else
@count += 0
next_elements
count_differences(@element1,@element2)
end
end

def self.next_elements
@element1 = @array1.shift
@element2 = @array2.shift
end

end
14 changes: 0 additions & 14 deletions hamming_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,58 @@

class HammingTest < Minitest::Test
def test_identical_strands
skip
assert_equal 0, Hamming.compute('A', 'A')
end

def test_long_identical_strands
skip
assert_equal 0, Hamming.compute('GGACTGA', 'GGACTGA')
end

def test_complete_distance_in_single_nucleotide_strands
skip
assert_equal 1, Hamming.compute('A', 'G')
end

def test_complete_distance_in_small_strands
skip
assert_equal 2, Hamming.compute('AG', 'CT')
end

def test_small_distance_in_small_strands
skip
assert_equal 1, Hamming.compute('AT', 'CT')
end

def test_small_distance
skip
assert_equal 1, Hamming.compute('GGACG', 'GGTCG')
end

def test_small_distance_in_long_strands
skip
assert_equal 2, Hamming.compute('ACCAGGG', 'ACTATGG')
end

def test_non_unique_character_in_first_strand
skip
assert_equal 1, Hamming.compute('AGA', 'AGG')
end

def test_non_unique_character_in_second_strand
skip
assert_equal 1, Hamming.compute('AGG', 'AGA')
end

def test_large_distance
skip
assert_equal 4, Hamming.compute('GATACA', 'GCATAA')
end

def test_large_distance_in_off_by_one_strand
skip
assert_equal 9, Hamming.compute('GGACGGATTCTG', 'AGGACGGATTCT')
end

def test_empty_strands
skip
assert_equal 0, Hamming.compute('', '')
end

def test_disallow_first_strand_longer
skip
assert_raises(ArgumentError) { Hamming.compute('AATG', 'AAA') }
end

def test_disallow_second_strand_longer
skip
assert_raises(ArgumentError) { Hamming.compute('ATA', 'AGTG') }
end
end