+#!/usr/bin/env ruby
+
+# Copyright (C) 2011 Martin A. Hansen.
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+# http://www.gnu.org/copyleft/gpl.html
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+# This software is part of the Biopieces framework (www.biopieces.org).
+
+# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+require 'test/unit'
+require 'maasha/cigar'
+require 'pp'
+
+class CigarTest < Test::Unit::TestCase
+ def test_Cigar_new_with_bad_cigar_raises
+ assert_raise(CigarError) { Cigar.new("@") }
+ assert_raise(CigarError) { Cigar.new("1M1H1M") }
+ assert_raise(CigarError) { Cigar.new("1M1S1M") }
+ end
+
+ def test_Cigar_new_with_ok_cigar_dont_raise
+ assert_nothing_raised { Cigar.new("1M") }
+ assert_nothing_raised { Cigar.new("1H1M1H") }
+ assert_nothing_raised { Cigar.new("1S1M1S") }
+ assert_nothing_raised { Cigar.new("1H1S1M1S1H") }
+ end
+
+ def test_Cigar_each_returns_correctly
+ cigar = Cigar.new("10M")
+
+ cigar.each { |len, op|
+ assert_equal(10, len)
+ assert_equal("M", op)
+ }
+ end
+
+ def test_Cigar_length_returns_correctly
+ assert_equal(6, Cigar.new("1M2S3H").length)
+ end
+
+ def test_Cigar_matches_returns_correctly
+ assert_equal(1, Cigar.new("1M2S3H").matches)
+ end
+
+ def test_Cigar_insertions_returns_correctly
+ assert_equal(1, Cigar.new("10M1I").insertions)
+ end
+
+ def test_Cigar_deletions_returns_correctly
+ assert_equal(2, Cigar.new("10M2D").deletions)
+ end
+
+ def test_Cigar_clip_hard_returns_correctly
+ assert_equal(3, Cigar.new("10M3H").clip_hard)
+ end
+
+ def test_Cigar_clip_soft_returns_correctly
+ assert_equal(4, Cigar.new("10M4S").clip_soft)
+ end
+end