+ # qual score detection
+
+ test "#qual_base33? returns correctly" do
+ # self.qual.match(/[!-:]/)
+ @entry.qual = '!"#$%&\'()*+,-./0123456789:'
+ assert_equal(true, @entry.qual_base33? )
+ @entry.qual = 32.chr
+ assert_equal(false, @entry.qual_base33? )
+ @entry.qual = 59.chr
+ assert_equal(false, @entry.qual_base33? )
+ end
+
+ test "#qual_base64? returns correctly" do
+ # self.qual.match(/[K-h]/)
+ @entry.qual = 'KLMNOPQRSTUVWXYZ[\]^_`abcdefgh'
+ assert_equal(true, @entry.qual_base64? )
+ @entry.qual = 74.chr
+ assert_equal(false, @entry.qual_base64? )
+ @entry.qual = 105.chr
+ assert_equal(false, @entry.qual_base64? )
+ end
+
+ test "#qual_valid? with nil qual raises" do
+ assert_raise(SeqError) { @entry.qual_valid?(:base_33) }
+ assert_raise(SeqError) { @entry.qual_valid?(:base_64) }
+ end
+
+ test "#qual_valid? with bad encoding raises" do
+ @entry.qual = "abc"
+ assert_raise(SeqError) { @entry.qual_valid?("foobar") }
+ end
+
+ test "#qual_valid? with OK range returns correctly" do
+ @entry.qual = ((Seq::SCORE_MIN + 33).chr .. (Seq::SCORE_MAX + 33).chr).to_a.join
+ assert_equal(true, @entry.qual_valid?(:base_33))
+ @entry.qual = ((Seq::SCORE_MIN + 64).chr .. (Seq::SCORE_MAX + 64).chr).to_a.join
+ assert_equal(true, @entry.qual_valid?(:base_64))
+ end
+
+ test "#qual_valid? with bad range returns correctly" do
+ @entry.qual = ((Seq::SCORE_MIN + 33 - 1).chr .. (Seq::SCORE_MAX + 33).chr).to_a.join
+ assert_equal(false, @entry.qual_valid?(:base_33))
+ @entry.qual = ((Seq::SCORE_MIN + 33).chr .. (Seq::SCORE_MAX + 33 + 1).chr).to_a.join
+ assert_equal(false, @entry.qual_valid?(:base_33))
+
+ @entry.qual = ((Seq::SCORE_MIN + 64 - 1).chr .. (Seq::SCORE_MAX + 64).chr).to_a.join
+ assert_equal(false, @entry.qual_valid?(:base_64))
+ @entry.qual = ((Seq::SCORE_MIN + 64).chr .. (Seq::SCORE_MAX + 64 + 1).chr).to_a.join
+ assert_equal(false, @entry.qual_valid?(:base_64))
+ end
+
+ # convert sanger to ...
+
+ test "#qual_convert! from base33 to base33 returns OK" do
+ @entry.qual = 'BCDEFGHI'
+ assert_equal('BCDEFGHI', @entry.qual_convert!(:base_33, :base_33).qual)
+ end
+
+ test "#qual_convert! from base33 to base64 returns OK" do
+ @entry.qual = 'BCDEFGHI'
+ assert_equal('abcdefgh', @entry.qual_convert!(:base_33, :base_64).qual)
+ end
+
+ test "#qual_convert! from base64 to base64 returns OK" do
+ @entry.qual = 'BCDEFGHI'
+ assert_equal('BCDEFGHI', @entry.qual_convert!(:base_64, :base_64).qual)
+ end
+
+ test "#qual_convert! from base64 to base33 returns OK" do
+ @entry.qual = 'abcdefgh'
+ assert_equal('BCDEFGHI', @entry.qual_convert!(:base_64, :base_33).qual)
+ end
+
+ test "#qual_coerce! returns correctly" do
+ @entry.qual = ('!' .. '~').to_a.join
+ assert_equal("!\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII", @entry.qual_coerce!(:base_33).qual)
+ @entry.qual = ('!' .. '~').to_a.join
+ assert_equal("!\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZh\\h^_`abcdefghhhhhhhhhhhhhhhhhhhhhhh", @entry.qual_coerce!(:base_64).qual)
+ end
+
+ test "#scores_mean without qual raises" do
+ @entry.qual = nil
+ assert_raise(SeqError) { @entry.scores_mean }
+ end
+
+ test "#scores_mean returns correctly" do
+ @entry.qual = '!!II'
+ assert_equal(20.0, @entry.scores_mean)
+ end
+end