| 1 |
# frozen_string_literal: false |
| 2 |
require 'test/unit' |
| 3 |
|
| 4 |
class Test_ArithSeq < Test::Unit::TestCase |
| 5 |
def test_extract_with_arith_seq |
| 6 |
assert_separately([], <<-"end;") #do |
| 7 |
require '-test-/arith_seq/extract' |
| 8 |
|
| 9 |
b, e, s, f, r = Enumerator::ArithmeticSequence.__extract__(1.step(10, 2)) |
| 10 |
assert_equal([1, 10, 2, 0, 1], [b, e, s, f, r]) |
| 11 |
|
| 12 |
b, e, s, f, r = Enumerator::ArithmeticSequence.__extract__((1..10) % 2) |
| 13 |
assert_equal([1, 10, 2, 0, 1], [b, e, s, f, r]) |
| 14 |
|
| 15 |
b, e, s, f, r = Enumerator::ArithmeticSequence.__extract__((1...10) % 2) |
| 16 |
assert_equal([1, 10, 2, 1, 1], [b, e, s, f, r]) |
| 17 |
end; |
| 18 |
end |
| 19 |
|
| 20 |
def test_extract_with_range |
| 21 |
assert_separately([], <<-"end;") #do |
| 22 |
require '-test-/arith_seq/extract' |
| 23 |
|
| 24 |
b, e, s, f, r = Enumerator::ArithmeticSequence.__extract__(1..10) |
| 25 |
assert_equal([1, 10, 1, 0, 1], [b, e, s, f, r]) |
| 26 |
|
| 27 |
b, e, s, f, r = Enumerator::ArithmeticSequence.__extract__(1...10) |
| 28 |
assert_equal([1, 10, 1, 1, 1], [b, e, s, f, r]) |
| 29 |
end; |
| 30 |
end |
| 31 |
|
| 32 |
def test_extract_with_others |
| 33 |
assert_separately([], <<-"end;") #do |
| 34 |
require '-test-/arith_seq/extract' |
| 35 |
|
| 36 |
b, e, s, f, r = Enumerator::ArithmeticSequence.__extract__(nil) |
| 37 |
assert_equal([nil, nil, nil, nil, 0], [b, e, s, f, r]) |
| 38 |
end; |
| 39 |
end |
| 40 |
end |