Class: NatSetTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- NatSetTest
- Defined in:
- lib/natset.rb
Instance Method Summary collapse
- #test_complement ⇒ Object
- #test_each_range ⇒ Object
- #test_empty ⇒ Object
- #test_intersect ⇒ Object
- #test_max ⇒ Object
- #test_min ⇒ Object
- #test_new ⇒ Object
- #test_open ⇒ Object
- #test_singleton ⇒ Object
- #test_split ⇒ Object
- #test_subtract ⇒ Object
- #test_union ⇒ Object
- #test_universal ⇒ Object
Instance Method Details
#test_complement ⇒ Object
314 315 316 317 318 319 |
# File 'lib/natset.rb', line 314 def test_complement assert_equal(NatSet.empty, ~NatSet.universal) assert_equal(NatSet.universal, ~NatSet.empty) assert_equal(NatSet._new(1, 2), ~NatSet._new(0, 1, 2)) assert_equal(NatSet._new(0, 1, 2), ~NatSet._new(1, 2)) end |
#test_each_range ⇒ Object
402 403 404 405 406 407 408 409 |
# File 'lib/natset.rb', line 402 def test_each_range rs = []; NatSet.new() .each_range {|r| rs << r}; assert_equal([], rs) rs = []; NatSet.new(0).each_range {|r| rs << r}; assert_equal([0..0], rs) rs = []; NatSet.new(1).each_range {|r| rs << r}; assert_equal([1..1], rs) rs = []; NatSet.new(1..3).each_range {|r| rs << r}; assert_equal([1..3], rs) rs = []; NatSet.new(1...3).each_range {|r| rs << r}; assert_equal([1..2], rs) rs = []; NatSet.new(1..-1).each_range {|r| rs << r}; assert_equal([1..-1], rs) end |
#test_empty ⇒ Object
296 297 298 |
# File 'lib/natset.rb', line 296 def test_empty assert(NatSet.empty.empty?) end |
#test_intersect ⇒ Object
329 330 331 332 333 334 335 |
# File 'lib/natset.rb', line 329 def test_intersect assert_equal(NatSet.empty, NatSet.empty & NatSet.empty) assert_equal(NatSet.empty, NatSet.empty & NatSet.universal) assert_equal(NatSet.empty, NatSet.universal & NatSet.empty) assert_equal(NatSet.universal, NatSet.universal & NatSet.universal) assert_equal(NatSet.new(0), NatSet.new(0, 2) & NatSet.new(0, 1)) end |
#test_max ⇒ Object
396 397 398 399 400 |
# File 'lib/natset.rb', line 396 def test_max assert_equal(nil, NatSet.new().max) assert_equal(10, NatSet.new(1..10).max) assert_equal(nil, NatSet.new(1..-1).max) end |
#test_min ⇒ Object
391 392 393 394 |
# File 'lib/natset.rb', line 391 def test_min assert_equal(nil, NatSet.new().min) assert_equal(1, NatSet.new(1..10).min) end |
#test_new ⇒ Object
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/natset.rb', line 345 def test_new assert_equal([1, 2], NatSet.new(1).es) assert_equal([1, 3], NatSet.new(1, 2).es) assert_equal([1, 4], NatSet.new(1, 2, 3).es) assert_equal([1, 4], NatSet.new(1, 3, 2).es) assert_equal([10, 21], NatSet.new(10..20).es) assert_equal([10, 20], NatSet.new(10...20).es) assert_equal([1, 2, 3, 4, 5, 6], NatSet.new(1, 3, 5).es) assert_equal([1, 16], NatSet.new(5..15, 1..10).es) assert_equal([1, 16], NatSet.new(11..15, 1..10).es) assert_raises(ArgumentError) {NatSet.new("a")} assert_raises(ArgumentError) {NatSet.new("a".."b")} assert_raises(ArgumentError) {NatSet.new(-1)} assert_raises(ArgumentError) {NatSet.new(-1..3)} end |
#test_open ⇒ Object
304 305 306 307 |
# File 'lib/natset.rb', line 304 def test_open assert(!NatSet.empty.open?) assert(NatSet.universal.open?) end |
#test_singleton ⇒ Object
309 310 311 312 |
# File 'lib/natset.rb', line 309 def test_singleton assert_equal(1, NatSet._new(1, 2).singleton?) assert_equal(nil, NatSet._new(1, 3).singleton?) end |
#test_split ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/natset.rb', line 361 def test_split u = NatSet.universal assert_equal([[NatSet.universal]], u.split()) assert_equal([[NatSet.universal]], u.split(NatSet.empty)) assert_equal([[NatSet.universal, u]], u.split(u)) n = NatSet.new(10..20) assert_equal([[NatSet.new(0..9, 21..-1)], [NatSet.new(10..20), n]], u.split(n)) ns = [NatSet.new(10..20), NatSet.new(10..20)] assert_equal([[NatSet.new(0..9, 21..-1)], [NatSet.new(10..20), *ns]], u.split(*ns)) ns = [NatSet.new(1..30), NatSet.new(5..40)] assert_equal([[NatSet.new(0, 41..-1)], [NatSet.new(1..4), ns[0]], [NatSet.new(31..40), ns[1]], [NatSet.new(5..30), *ns]], u.split(*ns)) ns = [NatSet.new(1..30), NatSet.new(5..20)] assert_equal([[NatSet.new(0, 31..-1)], [NatSet.new(1..4, 21..30), ns[0]], [NatSet.new(5..20), *ns]], u.split(*ns)) end |
#test_subtract ⇒ Object
337 338 339 340 341 342 343 |
# File 'lib/natset.rb', line 337 def test_subtract assert_equal(NatSet.empty, NatSet.empty - NatSet.empty) assert_equal(NatSet.empty, NatSet.empty - NatSet.universal) assert_equal(NatSet.universal, NatSet.universal - NatSet.empty) assert_equal(NatSet.empty, NatSet.universal - NatSet.universal) assert_equal(NatSet.new(2), NatSet.new(0, 2) - NatSet.new(0, 1)) end |
#test_union ⇒ Object
321 322 323 324 325 326 327 |
# File 'lib/natset.rb', line 321 def test_union assert_equal(NatSet.empty, NatSet.empty + NatSet.empty) assert_equal(NatSet.universal, NatSet.empty + NatSet.universal) assert_equal(NatSet.universal, NatSet.universal + NatSet.empty) assert_equal(NatSet.universal, NatSet.universal + NatSet.universal) assert_equal(NatSet.new(0..2), NatSet.new(0, 2) + NatSet.new(0, 1)) end |