bunch of usefull tests

This commit is contained in:
Ward Wouts 2005-03-09 15:02:52 +00:00
parent 00a0638ee4
commit 02bea100c0

View file

@ -0,0 +1,86 @@
#!/usr/local/bin/ruby
# $Id$
# $Source$
require 'test/unit'
require '../intspan'
class TestSetIntspan < Test::Unit::TestCase
# def setup
# end
# def teardown
# end
def test_empty_set
set = Set::IntSpan.new()
assert(set.empty?)
assert_equal("", set.to_s)
set.set_neg_inf(true)
assert_equal(false, set.empty?)
set = Set::IntSpan.new()
set.set_pos_inf(true)
assert_equal(false, set.empty?)
set = Set::IntSpan.new("1")
assert_equal(false, set.empty?)
end
def test_neg_inf
set = Set::IntSpan.new()
set.set_neg_inf(true)
assert(set.neg_inf?)
set = Set::IntSpan.new("(-1,3,5")
assert_equal(true, set.neg_inf?)
set = Set::IntSpan.new("1-3,5-)")
assert_equal(false, set.neg_inf?)
set = Set::IntSpan.new("(-1,3,5-)")
assert_equal(true, set.neg_inf?)
end
def test_pos_inf
set = Set::IntSpan.new()
set.set_pos_inf(true)
assert(set.pos_inf?)
end
def test_to_s
assert_equal("", Set::IntSpan.new().to_s)
assert_equal("1", Set::IntSpan.new("1").to_s)
assert_equal("1-3", Set::IntSpan.new("1-3").to_s)
assert_equal("1-3,5", Set::IntSpan.new("1-3,5").to_s)
assert_equal("(-1,3,5", Set::IntSpan.new("(-1,3,5").to_s)
assert_equal("1-3,5-)", Set::IntSpan.new("1-3,5-)").to_s)
assert_equal("(-1,3,5-)", Set::IntSpan.new("(-1,3,5-)").to_s)
end
def test_array_init
assert_equal("", Set::IntSpan.new([]).to_s)
assert_equal("1", Set::IntSpan.new([1]).to_s)
assert_equal("1-3", Set::IntSpan.new([1,2,3]).to_s)
assert_equal("1-3,5", Set::IntSpan.new([1,2,3,5]).to_s)
end
def test_set_init
set = Set::IntSpan.new("1-3,5")
set2 = Set::IntSpan.new(set)
assert_equal("1-3,5", set2.to_s)
set = Set::IntSpan.new("(-1,3,5-)")
set2 = Set::IntSpan.new(set)
assert_equal("(-1,3,5-)", set2.to_s)
end
def test_insert
set = Set::IntSpan.new()
assert_equal("", set.to_s)
set.insert(4)
assert_equal("4", set.to_s)
set.insert(5)
assert_equal("4-5", set.to_s)
set.insert(7)
assert_equal("4-5,7", set.to_s)
set.insert(6)
assert_equal("4-7", set.to_s)
set.set_neg_inf(true)
end
end