forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exercise: nucleotide count (JuliaLang#31)
* Add exercise: nucleotide count * Remove hard-coded tuple of valid symbols
- Loading branch information
1 parent
7ba73f2
commit b19b198
Showing
4 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function count_nucleotides(strand::AbstractString) | ||
counter = Dict('A' => 0, 'C' => 0, 'G' => 0, 'T' => 0) | ||
for sym in strand | ||
sym in keys(counter) || error("Invalid nucleotide in strand") | ||
counter[sym] += 1 | ||
end | ||
return counter | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function count_nucleotides(strand::AbstractString) | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Base.Test | ||
|
||
include("nucleotide-count.jl") | ||
|
||
@testset "empty strand" begin | ||
@test count_nucleotides("") == Dict('A' => 0, 'C' => 0, 'G' => 0, 'T' => 0) | ||
end | ||
|
||
@testset "strand with repeated nucleotide" begin | ||
@test count_nucleotides("GGGGGGG") == Dict('A' => 0, 'C' => 0, 'G' => 7, 'T' => 0) | ||
end | ||
|
||
@testset "strand with multiple nucleotides" begin | ||
@test count_nucleotides("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC") == Dict('A' => 20, 'C' => 12, 'G' => 17, 'T' => 21) | ||
end | ||
|
||
@testset "strand with invalid nucleotides" begin | ||
@test_throws ErrorException count_nucleotides("AGXXACT") | ||
end |