Last active
December 22, 2015 11:09
-
-
Save alekst/6463424 to your computer and use it in GitHub Desktop.
This file contains 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
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