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