"Thomas R.Corbin" <tc / clark.net> writes:
> I love XP, so seeing it and Ruby together is neat.
I'm having a whale of a time using Ruby as a test bed to do unit
testing on a complex C program. I write Ruby wrappers for the major C
functions (which is a trivial exercise) and then I can use RubyUnit to
do XP-style unit testing. It's remarkably flexible: once the interface
is written I can even use irb to do interactive testing. A typical
test looks something like:
def test_simple_chunks
id1 = IntervalDataSet.new(5) {|i| i}
id2 = IntervalDataSet.new(4) {|i| i+5}
id3 = IntervalDataSet.new(1) {|i| 9}
cursor = Ceres::IDAPI::read_raw_data(CHAN,
START_BASE,
END_BASE,
nil)
assert(cursor.more_data?)
assert_equal(START_BASE, cursor.startDTM)
assert_equal(INTLEN, cursor.intervalLength)
ids = cursor.read(5)
assert(cursor.more_data?, "Data available after first")
assert_equal(5, ids.size)
assert_equal(id1, ids)
ids = cursor.read(4)
assert(cursor.more_data?, "Data available after second")
assert_equal(4, ids.size)
assert_equal(id2, ids)
ids = cursor.read(99)
assert(!cursor.more_data?, "No data after third")
assert_equal(1, ids.size)
assert_equal(id3, ids)
end
Just the simple initialization of a test data set using a constructor
with an associated block would take a fair ammount of C, code that I'd
rather not have to write for unit tests.
Anyway, back to the wrapping.
Dave