O Plameras wrote:
Matthew Palmer wrote:
Unit testing, yeah yeah!
As discussed tonight, I've got all of the test suites below you'll
need to
do some serious testing of your methods.
Before you start doing any of this, you'll need to move your
bodgy_rounding() method to a file called nrs_payroll.rb, and then
save each
of these test suites to separate files in the same directory as your
nrs_payroll.rb file. To run a test suite, just point Ruby at it and it
should print useful output like what you saw in my test runs
tonight. For
example, to run the first test suite, just run "ruby
./simple_br_test.rb".
So, test suite one -- the first test method is simply a conversion of
our
home-grown assert_equal testing to the Test::Unit system. Your
bodgy_rounding() method should satisfy these requirements easily. The
second method is the extra negative assertions we worked out, and your
bodgy_rounding method will have to be enhanced with some extra logic to
handle this case. Remember to re-run your tests regularly to ensure
that
you haven't broken something.
---[BEGIN simple_br_test.rb]---
require 'test/unit'
require 'nrs_payroll'
class SimpleBodgyRoundingTest < Test::Unit::TestCase
def test_bodgy_rounding
assert_equal(10, bodgy_rounding(12))
assert_equal(15, bodgy_rounding(13))
assert_equal(0, bodgy_rounding(1))
assert_equal(0, bodgy_rounding(0))
assert_equal(5, bodgy_rounding(7))
assert_equal(10, bodgy_rounding(7.01))
end
The above tests appear to be consistent and correct. You are consistently
rounding to nearest UNIT.
I correct this. Instead of 'nearest UNIT', it should be 'nearest UNIT
of FIVEs'.
Sorry.
O Plameras
_______________________________________________
coders mailing list
[email protected]
http://lists.slug.org.au/listinfo/coders