Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rna-transcription: Update tests to expect ArgumentError if invalid input is supplied #848

Merged
merged 2 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
require 'generator/exercise_case'

class RnaTranscriptionCase < Generator::ExerciseCase

def workload
if expects_error?
assert_raises(ArgumentError) { test_case }
else
assert_equal { test_case }
end
end

private

def test_case
"assert_equal '#{expected}', Complement.of_dna('#{dna}')"
end

def expects_error?
expected.is_a? Hash
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Complement
def self.of_dna(strand)
strand =~ /[^CGTA]/ ? '' : strand.tr('CGTA', 'GCAU')
raise ArgumentError if strand =~ /[^CGTA]/
strand.tr('CGTA', 'GCAU')
end
end
6 changes: 3 additions & 3 deletions exercises/rna-transcription/rna_transcription_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def test_rna_complement

def test_correctly_handles_invalid_input_rna_instead_of_dna
skip
assert_equal '', Complement.of_dna('U')
assert_raises(ArgumentError) { Complement.of_dna('U') }
end

def test_correctly_handles_completely_invalid_dna_input
skip
assert_equal '', Complement.of_dna('XXX')
assert_raises(ArgumentError) { Complement.of_dna('XXX') }
end

def test_correctly_handles_partially_invalid_dna_input
skip
assert_equal '', Complement.of_dna('ACGTXXXCTTAA')
assert_raises(ArgumentError) { Complement.of_dna('ACGTXXXCTTAA') }
end
end