Add tests for _is_valid(::Haplotype)

This commit is contained in:
Thomas A. Christensen II 2023-01-21 18:10:04 -06:00
parent 57ebe391bf
commit 7bd39b1d54

View file

@ -45,6 +45,9 @@ seq2 = ungap!(dna"TGATGCGTGT-AGCAACACTTATAGCG")
seq3 = ungap!(dna"-GATGCGTGT-AGCAACACTTATCGC-") seq3 = ungap!(dna"-GATGCGTGT-AGCAACACTTATCGC-")
var = Haplotype(align(seq1, seq2)) var = Haplotype(align(seq1, seq2))
const SEQ = typeof(seq1)
const BSE = eltype(seq1)
@testset "EditSorting" begin @testset "EditSorting" begin
S = typeof(seq1) S = typeof(seq1)
T = eltype(seq1) T = eltype(seq1)
@ -55,6 +58,11 @@ var = Haplotype(align(seq1, seq2))
end end
@testset "HaplotypeValidation" begin @testset "HaplotypeValidation" begin
# Test that we can't use an empty reference
@test_throws ErrorException Haplotype(
dna"", [SequenceVariation.Edit{SEQ,BSE}(Insertion{SEQ}(dna"A"), 0)]
)
# Test that substitutions cannot share the same position # Test that substitutions cannot share the same position
@test_throws ErrorException Haplotype( @test_throws ErrorException Haplotype(
seq2, [Variation(seq2, "T2A"), Variation(seq2, "T2C")] seq2, [Variation(seq2, "T2A"), Variation(seq2, "T2C")]
@ -87,6 +95,21 @@ end
@test_throws ErrorException Haplotype( @test_throws ErrorException Haplotype(
seq2, [Variation(seq2, "Δ2-6"), Variation(seq2, "Δ3-5")] seq2, [Variation(seq2, "Δ2-6"), Variation(seq2, "Δ3-5")]
) )
# Test that a complicated (but valid) Haplotype still checks out
@test first(
SequenceVariation._is_valid(
Haplotype(
seq2,
[
Variation(seq2, "0AAA"),
Variation(seq2, "T2A"),
Variation(seq2, "Δ5-8"),
Variation(seq2, "G26A"),
],
),
),
)
end end
@testset "HaplotypeRoundtrip" begin @testset "HaplotypeRoundtrip" begin