Skip to content

Commit

Permalink
Add some basic error testing, don't use logging macro for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jangevaare committed Sep 13, 2019
1 parent 49b1961 commit 16e6cde
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end

function rand(::Type{T}, w::W, n::Int64; checkinput::Bool=true) where {T <: GeneticSeq, W<: Weights}
if checkinput && length(w) != 4
@error "Invalid sampling weights for $T generation"
throw(ErrorException("Invalid sampling weights for $T generation"))
end
x = BitArray(fill(0, (4, n)))
@simd for i = 1:n
Expand Down Expand Up @@ -42,7 +42,7 @@ function setindex!(x::T, a::BitArray{1}, i::Int64) where {T <: GeneticSeq}
if length(a) == 4 && sum(a) == 1
return x.data[:, i] = a
else
@error "Invalid input"
throw(ErrorException("Invalid input"))
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/DNA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct DNASeq <: GeneticSeq
if _checkinput(x)
return new(x)
else
@error "Invalid input"
throw(ErrorException("Invalid input"))
end
else
return new(x)
Expand All @@ -25,7 +25,7 @@ function onehot(::Type{DNASeq}, x::Char)
elseif x == 'T'
return BitArray{1}([0, 0, 0, 1])
else
@error "Invalid `Char`"
throw(ErrorException("Invalid `Char`"))
end
end

Expand All @@ -47,7 +47,7 @@ function DNASeq(seq::Vector{Char})
elseif seq[i] == 'T'
x[4, i] = 1
else
@error "Invalid `Char` at index $i"
throw(ErrorException("Invalid `Char` at index $i"))
end
end
return DNASeq(x, checkinput=false)
Expand Down
6 changes: 3 additions & 3 deletions src/RNA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct RNASeq <: GeneticSeq
if _checkinput(x)
return new(x)
else
@error "Invalid input"
throw(ErrorException("Invalid input"))
end
else
return new(x)
Expand All @@ -25,7 +25,7 @@ function onehot(::Type{RNASeq}, x::Char)
elseif x == 'U'
return BitArray{1}([0, 0, 0, 1])
else
@error "Invalid `Char`"
throw(ErrorException("Invalid `Char`"))
end
end

Expand All @@ -47,7 +47,7 @@ function RNASeq(seq::Vector{Char})
elseif seq[i] == 'U'
x[4, i] = 1
else
@error "Invalid `Char` at index $i"
throw(ErrorException("Invalid `Char` at index $i"))
end
end
return RNASeq(x, checkinput=false)
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ end
b[1] = 'U'
@test b[1] == RNASeq("U")
end

@testset "Errors" begin
@test_throws ErrorException DNASeq("AAAU")
@test_throws ErrorException RNASeq("AAAT")
@test_throws ErrorException rand(RNASeq, Weights(fill(0.25, 3)), 1000)
end

4 comments on commit 16e6cde

@jangevaare
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/3519

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 16e6cde02d847a4a230e2f91ce0c1a48973c21e8
git push origin v0.2.0

Also, note the warning: This looks like a new registration that registers version 0.2.0.
Ideally, you should register an initial release with 0.0.1, 0.1.0 or 1.0.0 version numbers
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

@jangevaare
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/3519

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.0 -m "<description of version>" 16e6cde02d847a4a230e2f91ce0c1a48973c21e8
git push origin v0.2.0

Please sign in to comment.