2 $:.unshift File.join(File.dirname(__FILE__), '..', '..')
4 # Copyright (C) 2011 Martin A. Hansen.
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.
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.
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.
20 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
24 # This software is part of the Biopieces framework (www.biopieces.org).
26 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
30 require 'maasha/cigar'
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") }
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") }
46 test "#to_s returns correctly" do
47 assert_equal("1M", Cigar.new("1M").to_s)
50 test "#each returns correctly" do
51 cigar = Cigar.new("10M")
53 cigar.each { |len, op|
59 test "#length returns correctly" do
60 assert_equal(6, Cigar.new("1M2S3H").length)
63 test "#matches returns correctly" do
64 assert_equal(1, Cigar.new("1M2S3H").matches)
67 test "#insertions returns correctly" do
68 assert_equal(1, Cigar.new("10M1I").insertions)
71 test "#deletions returns correctly" do
72 assert_equal(2, Cigar.new("10M2D").deletions)
75 test "#clip_hard returns correctly" do
76 assert_equal(3, Cigar.new("10M3H").clip_hard)
79 test "#clip_soft returns correctly" do
80 assert_equal(4, Cigar.new("10M4S").clip_soft)