S
Simon Strandgaard
I am testing the 'stream' module..
http://raa.ruby-lang.org/list.rhtml?name=stream
Q1: I have to overload the implicitstream.at_beginning_proc
with a offbyone value.. Why ?
Q2: Is this me which is thinking wrong, or is it a design flaw
in the 'stream' library?
I have made two methods which should return virtually the
same stream; [1, 2, 3, 4, 5, 6]
server> expand -t2 test_misc.rb
require 'test/unit'
require 'stream'
class TestMisc < Test::Unit::TestCase
def mk_str16
(1..6).create_stream
end
def mk_str16x
Stream::ImplicitStream.new{|s|
x = 1
s.at_end_proc = proc {x == 6}
s.forward_proc = proc {x += 1}
s.at_beginning_proc = proc {x == 0} # todo: why is'nt it {x == 1}
s.backward_proc = proc {x -= 1}
}
end
def setup
@data = mk_str16.filtered{|x| x % 2 == 0}
@data += mk_str16x.filtered{|x| x % 2 != 0}
end
def test_toa
assert_equal([2, 4, 6, 1, 3, 5], @data.to_a)
end
def test_revtoa
assert_equal([5, 3, 1, 6, 4, 2], @data.reverse.to_a)
end
end
if $0 == __FILE__
require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TestMisc)
end
server> ruby test_misc.rb
Loaded suite TestMisc
Started
...
Finished in 0.008114 seconds.
2 tests, 2 assertions, 0 failures, 0 errors
server>
If I change the 'at_beginning_proc' to stop at '1' which I believe
is where it should stop, then I get this error:
server> ruby test_misc.rb
Loaded suite TestMisc
Started
FF
Finished in 0.009856 seconds.
1) Failure!!!
test_revtoa(TestMisc) [test_misc.rb:25]:
<[5, 3, 1, 6, 4, 2]> expected but was
<[5, 3, 6, 4, 2]>
2) Failure!!!
test_toa(TestMisc) [test_misc.rb:22]:
<[2, 4, 6, 1, 3, 5]> expected but was
<[2, 4, 6, 3, 5]>
2 tests, 2 assertions, 2 failures, 0 errors
server>
http://raa.ruby-lang.org/list.rhtml?name=stream
Q1: I have to overload the implicitstream.at_beginning_proc
with a offbyone value.. Why ?
Q2: Is this me which is thinking wrong, or is it a design flaw
in the 'stream' library?
I have made two methods which should return virtually the
same stream; [1, 2, 3, 4, 5, 6]
server> expand -t2 test_misc.rb
require 'test/unit'
require 'stream'
class TestMisc < Test::Unit::TestCase
def mk_str16
(1..6).create_stream
end
def mk_str16x
Stream::ImplicitStream.new{|s|
x = 1
s.at_end_proc = proc {x == 6}
s.forward_proc = proc {x += 1}
s.at_beginning_proc = proc {x == 0} # todo: why is'nt it {x == 1}
s.backward_proc = proc {x -= 1}
}
end
def setup
@data = mk_str16.filtered{|x| x % 2 == 0}
@data += mk_str16x.filtered{|x| x % 2 != 0}
end
def test_toa
assert_equal([2, 4, 6, 1, 3, 5], @data.to_a)
end
def test_revtoa
assert_equal([5, 3, 1, 6, 4, 2], @data.reverse.to_a)
end
end
if $0 == __FILE__
require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TestMisc)
end
server> ruby test_misc.rb
Loaded suite TestMisc
Started
...
Finished in 0.008114 seconds.
2 tests, 2 assertions, 0 failures, 0 errors
server>
If I change the 'at_beginning_proc' to stop at '1' which I believe
is where it should stop, then I get this error:
server> ruby test_misc.rb
Loaded suite TestMisc
Started
FF
Finished in 0.009856 seconds.
1) Failure!!!
test_revtoa(TestMisc) [test_misc.rb:25]:
<[5, 3, 1, 6, 4, 2]> expected but was
<[5, 3, 6, 4, 2]>
2) Failure!!!
test_toa(TestMisc) [test_misc.rb:22]:
<[2, 4, 6, 1, 3, 5]> expected but was
<[2, 4, 6, 3, 5]>
2 tests, 2 assertions, 2 failures, 0 errors
server>