]> git.donarmstrong.com Git - biopieces.git/blob - code_ruby/test/maasha/test_cigar.rb
rewrite of FASTQ internals
[biopieces.git] / code_ruby / test / maasha / test_cigar.rb
1 #!/usr/bin/env ruby
2 $:.unshift File.join(File.dirname(__FILE__), '..', '..')
3
4 # Copyright (C) 2011 Martin A. Hansen.
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 # http://www.gnu.org/copyleft/gpl.html
21
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
23
24 # This software is part of the Biopieces framework (www.biopieces.org).
25
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
27
28 require 'test/unit'
29 require 'test/helper'
30 require 'maasha/cigar'
31
32 class CigarTest < Test::Unit::TestCase
33   test "Cigar.new with bad cigar raises" do
34     assert_raise(CigarError) { Cigar.new("@") }
35     assert_raise(CigarError) { Cigar.new("1M1H1M") }
36     assert_raise(CigarError) { Cigar.new("1M1S1M") }
37   end
38
39   test "Cigar.new with ok cigar dont raise" do
40     assert_nothing_raised { Cigar.new("1M") }
41     assert_nothing_raised { Cigar.new("1H1M1H") }
42     assert_nothing_raised { Cigar.new("1S1M1S") }
43     assert_nothing_raised { Cigar.new("1H1S1M1S1H") }
44   end
45
46   test "#to_s returns correctly" do
47     assert_equal("1M", Cigar.new("1M").to_s)
48   end
49
50   test "#each returns correctly" do
51     cigar = Cigar.new("10M")
52
53     cigar.each { |len, op|
54       assert_equal(10, len)
55       assert_equal("M", op)
56     }
57   end
58
59   test "#length returns correctly" do
60     assert_equal(6, Cigar.new("1M2S3H").length)
61   end
62
63   test "#matches returns correctly" do
64     assert_equal(1, Cigar.new("1M2S3H").matches)
65   end
66
67   test "#insertions returns correctly" do
68     assert_equal(1, Cigar.new("10M1I").insertions)
69   end
70
71   test "#deletions returns correctly" do
72     assert_equal(2, Cigar.new("10M2D").deletions)
73   end
74
75   test "#clip_hard returns correctly" do
76     assert_equal(3, Cigar.new("10M3H").clip_hard)
77   end
78
79   test "#clip_soft returns correctly" do
80     assert_equal(4, Cigar.new("10M4S").clip_soft)
81   end
82 end