Created
April 16, 2016 21:02
-
-
Save lrechert/18f2e41000b3a2a20a44a3d83f8029dd to your computer and use it in GitHub Desktop.
Ruby Weekly Challenge - DNA Sequences
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 characters
| def check_dna(sequence1, sequence2) | |
| complementary?(normalize(sequence1), normalize(sequence2.reverse)) | |
| end | |
| def complementary?(seq1, seq2) | |
| return bonded?(seq1, seq2) || bonded?(seq2, seq1) | |
| end | |
| def bonded?(seq1, seq2) | |
| seq2.include?(seq1) | |
| end | |
| def normalize(seq) | |
| seq.gsub(/A|T/i, '0').gsub(/C|G/i, '1') | |
| end |
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 characters
| require_relative '../dna_sequence' | |
| describe "dna_sequence" do | |
| context "when there is a sequence mismatch" do | |
| it "returns false" do | |
| expect(check_dna('GTCTTAGTGTAGCTATGCATGC', 'GCATGCATAGCTACACTACGAC')).to be_falsey | |
| end | |
| end | |
| context "when one strand is completely bonded by the other" do | |
| it "returns true" do | |
| expect(check_dna('GCGCTGCTAGCTGATCGA', 'ACGTACGATCGATCAGCTAGCAGCGCTAC')).to be_truthy | |
| end | |
| end | |
| context "when both strands are only partially bonded" do | |
| it "returns false" do | |
| expect(check_dna('CGATACGAACCCATAATCG', 'CTACACCGGCCGATTATGG')).to be_falsey | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment