From: Eric Hodel Date: 2004-06-01T10:54:49-07:00 Subject: Re: Test::Unit: assert_follows_spec() (or something like that) --5vNYLRcllDrimb99 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable David Garamond (lists@zara.6.isreserved.com) wrote: > For deterministic functions/methods, the same set of inputs should=20 > always produces the same output. What about adding something like: >=20 > assert_follows_spec(method_or_class_name, spec) >=20 > Where spec is an array of input and output pairs (and optionally an=20 > exception, if the input should not be accepted): >=20 > [{input =3D> [1, 1, 1], output =3D> 1}, > {input =3D> [8, 1, 2], output =3D> 4}, > {input =3D> [8, 3, 4], output =3D> 6}, > {input =3D> [4, 3, 2], output =3D> 6}, > {input =3D> [1, 2, nil], exception =3D> ArgumentError}, > {input =3D> [1, 2, 0], exception =3D> ZeroDivisionError}] > > This can make unit tests shorter and more readable. We can transform the= =20 > spec into an HTML table, include it into the API documentation, etc. >=20 > The assert_follows_spec() could even perform several iterations of tests= =20 > if wanted, to test deterministic-ness. If you've got a spec like this, why not write a method to autogenerate test methods? --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --5vNYLRcllDrimb99 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQFAvMLpMypVHHlsnwQRAiMMAKCa7UqFf5HbftP7fcSI21iBzbHF8wCgwo5I fN3jkjU06itjkycx1IQysCs= =lO+n -----END PGP SIGNATURE----- --5vNYLRcllDrimb99--