Finished
11def hamming_distance(dna_strand_1, dna_strand_2):
2 pass
2 # Edge Case: Handle None inputs
3 if dna_strand_1 is None or dna_strand_2 is None:
4 raise ValueError("DNA strands cannot be None")
5
6 # Edge Case: Handle empty strings
7 if len(dna_strand_1) == 0 and len(dna_strand_2) == 0:
8 return 0
9
10 # Edge Case: Handle invalid characters
11 valid_bases = set('ACGT')
12 if not all(base in valid_bases for base in dna_strand_1) or not all(base in valid_bases for base in dna_strand_2):
13 raise ValueError("DNA strands must contain only valid nucleotide bases (A, C, G, T)")
14
15 # Calculate Hamming distance (compare up to the length of the shorter strand)
16 distance = 0
17 min_length = min(len(dna_strand_1), len(dna_strand_2))
18 for i in range(min_length):
19 if dna_strand_1[i] != dna_strand_2[i]:
20 distance += 1
21
22 return distance
23# Handled Edge Cases: None inputs, empty strings, unequal lengths, invalid characters
Test NameStatus
test_complete_hamming_distance_in_small_strand
Pass
test_hamming_distance_in_off_by_one_strand
Pass
test_ignores_extra_length_on_original_strand_when_longer
Pass
test_ignores_extra_length_on_other_strand_when_longer
Pass
test_larger_distance
Pass
test_no_difference_between_empty_strands
Pass
test_no_difference_between_identical_strands
Pass
test_small_hamming_distance_in_middle_somewhere
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.