Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78798
| References | <h2j33adothf9uctcdp5psqk2cclr01961r@4ax.com> <mailman.14621.1412552876.18130.python-list@python.org> <pnn33a1cqtpbagua005b0cfhb587sfla9t@4ax.com> <5433a8f7$0$2916$c3e8da3$76491128@news.astraweb.com> |
|---|---|
| Date | 2014-10-07 05:43 -0700 |
| Subject | Re: Practice question |
| From | C Smith <illusiontechniques@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14658.1412685815.18130.python-list@python.org> (permalink) |
Steven D'Aprano wrote: >>With two numbers, 15 and 30, all you really need is five test cases: My solution assumed integers also, but after I posted it, I thought: "What about floating points?" On Tue, Oct 7, 2014 at 1:48 AM, Steven D'Aprano <steve@pearwood.info> wrote: > On Sun, 05 Oct 2014 20:18:13 -0400, Seymore4Head wrote: > >> I think I get it now. You are using a sample of answers. So you could >> actually just run through them all. (I haven't tried this yet) >> >> for x in range(lo,hi) >> print((15 <= x < 30) == (15<= x and x <30)) > > Yes, except using print is probably not the best idea, since you might > have dozens of True True True True ... printed, one per line, and if you > blink the odd False might have scrolled off screen before you notice. > > With two numbers, 15 and 30, all you really need is five test cases: > > - a number lower than the smaller of the two numbers (say, 7); > - a number equal to the smaller of the two numbers (that is, 15); > - a number between the two numbers (say, 21); > - a number equal to the larger of the two numbers (that is, 30); > - a number higher than the larger of the two numbers (say, 999); > > > The exact numbers don't matter, so long as you test all five cases. And > rather than printing True True True... let's use assert instead: > > > for x in (7, 15, 21, 30, 999): > assert (15 <= x < 30) == (15<= x and x <30) > > > If the two cases are equal, assert will do nothing. But if they are > unequal, assert will raise an exception and stop, and you know that the > two cases are not equivalent and can go on to the next possibility. > > > -- > Steven > -- > https://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Practice question Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-05 19:02 -0400
Re: Practice question Roy Smith <roy@panix.com> - 2014-10-05 19:06 -0400
Re: Practice question Ned Batchelder <ned@nedbatchelder.com> - 2014-10-05 19:14 -0400
Re: Practice question Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-05 20:07 -0400
Re: Practice question Ned Batchelder <ned@nedbatchelder.com> - 2014-10-05 21:25 -0400
Re: Practice question Steven D'Aprano <steve@pearwood.info> - 2014-10-07 08:41 +0000
Re: Practice question Skip Montanaro <skip.montanaro@gmail.com> - 2014-10-05 18:33 -0500
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-05 19:47 -0700
Re: Practice question Skip Montanaro <skip.montanaro@gmail.com> - 2014-10-06 08:04 -0500
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-06 09:23 -0700
Re: Practice question Chris Angelico <rosuav@gmail.com> - 2014-10-07 03:52 +1100
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-06 10:05 -0700
Re: Practice question Chris Angelico <rosuav@gmail.com> - 2014-10-07 04:13 +1100
Re: Practice question Steven D'Aprano <steve@pearwood.info> - 2014-10-06 20:49 +0000
Re: Practice question "Redge @ Versalytics.com" <versalytics@gmail.com> - 2014-10-06 20:54 -0400
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-08 09:14 -0700
Re: Practice question Chris Angelico <rosuav@gmail.com> - 2014-10-09 03:23 +1100
Re: Practice question Skip Montanaro <skip.montanaro@gmail.com> - 2014-10-08 11:27 -0500
Re: Practice question Rustom Mody <rustompmody@gmail.com> - 2014-10-08 09:41 -0700
Re: Practice question Terry Reedy <tjreedy@udel.edu> - 2014-10-05 19:47 -0400
Re: Practice question Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-05 20:18 -0400
Re: Practice question Steven D'Aprano <steve@pearwood.info> - 2014-10-07 08:48 +0000
Re: Practice question C Smith <illusiontechniques@gmail.com> - 2014-10-07 05:43 -0700
Re: Practice question C Smith <illusiontechniques@gmail.com> - 2014-10-05 16:24 -0700
Re: Practice question Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-07 01:46 +0000
Re: Practice question Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-06 22:06 -0400
Re: Practice question alister <alister.nospam.ware@ntlworld.com> - 2014-10-09 15:28 +0000
csiph-web