Skip to content

Instantly share code, notes, and snippets.

@alekst
Last active December 22, 2015 11:09
Show Gist options
  • Save alekst/6463424 to your computer and use it in GitHub Desktop.
Save alekst/6463424 to your computer and use it in GitHub Desktop.
class DNATest < MiniTest::Unit::TestCase
class DNA
def initialize(string)
@string = string
@counts = {"A"=> 0, "T" => 0, "C"=> 0, "G"=> 0}
dna_validation
end
def count(element)
@element = element
element_validation
@array = @string.chars.sort
@array.count(element)
end
def nucleotide_counts
nucleotides = @string.chars.sort
nucleotides.each do |nucleotide|
@counts[nucleotide] += 1
end
@counts
end
def dna_validation
return 0 if @string.empty?
raise ArgumentError, "DNA is not RNA" if @string.include?('U')
raise ArgumentError, "This is not a DNA" unless @string.match(/[ACGT]/)
end
def element_validation
raise ArgumentError, "There are no such nucleotides" unless @element.match(/[ACGTU]/)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment