From: Matthew Moss Date: 2007-04-28T04:31:37+09:00 Subject: Re: [QUIZ] Checking Credit Cards (#122) So I took this as an opportunity to try doing a little TDD, something which is appealing but I've never really tried. It _is_ fun to see failure first and then fix. =) There are probably other tests I could have included, but here is a start, in case people want to check a few numbers or add more tests: Obviously, you may need to change this to match your solution... require "test/unit" require "ccard" class CreditCardCheckTest < Test::Unit::TestCase def test_valid_numbers assert CreditCard.new("4408041234567893").valid? assert CreditCard.new("6011111111111117").valid? end def test_invalid_nubers assert !CreditCard.new("4417123456789112").valid? end def test_valid_numbers_with_spaces assert CreditCard.new("4408 0412 3456 7893").valid? assert CreditCard.new("6011 1111 1111 1117").valid? end def test_invalid_nubers_with_spaces assert !CreditCard.new("4417 1234 5678 9112").valid? end def test_valid_types assert_equal CreditCard.new("4408041234567893").type, :visa assert_equal CreditCard.new("4408 0412 3456 7893").type, :visa assert_equal CreditCard.new("6011 1111 1111 1117").type, :discover assert_equal CreditCard.new("123456789").type, :unknown end def test_invalid_types assert_nil CreditCard.new("4408 0412 3456 789").type end end