Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #29631
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: in1To10, a simple test plan |
| Date | Sun, 10 Aug 2014 12:01:00 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 60 |
| Message-ID | <ls84vs$eqb$1@dont-email.me> (permalink) |
| References | <0c8de66a-429a-4697-b575-35f37a7b6882@googlegroups.com> <0rqdnVpuJ9ayDnrOnZ2dnUVZ8sKdnZ2d@bt.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Sun, 10 Aug 2014 16:01:00 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="15179"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/rIorKDTGTmt6vqLN6KYV0" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 |
| In-Reply-To | <0rqdnVpuJ9ayDnrOnZ2dnUVZ8sKdnZ2d@bt.com> |
| Cancel-Lock | sha1:7ahLLc1hqwwEzMn0gVB6jywL/sk= |
| Xref | csiph.com comp.lang.java.programmer:29631 |
Show key headers only | View raw
On 8/10/2014 11:43 AM, lipska the kat wrote:
> [...]
> public class In1To10 {
>
> static boolean in1To10(int n, boolean outsideMode){
> if(n == 1 || n == 10){
> return true;
> }
> else{
> return (n > 1 && n < 10) ^ outsideMode;
> }
> }
>
> public static void main(String[] args){
> boolean outsideMode = true;
> //Expected: Actual:
> System.out.println(in1To10(1, outsideMode)); //true true
> System.out.println(in1To10(1, !outsideMode)); //true true
> System.out.println(in1To10(10, outsideMode)); //true true
> System.out.println(in1To10(10, !outsideMode)); //true true
> System.out.println(in1To10(0, outsideMode)); //true true
> System.out.println(in1To10(0, !outsideMode)); //false false
> System.out .println(in1To10(-1, outsideMode)); //true true
> System.out.println(in1To10(-1, !outsideMode)); //false false
> System.out.println(in1To10(2, outsideMode)); //false false
> System.out.println(in1To10(2, !outsideMode)); //true true
> System.out.println(in1To10(5, outsideMode)); //false false
> System.out.println(in1To10(5, !outsideMode)); //true true
> System.out.println(in1To10(9, outsideMode)); //false false
> System.out.println(in1To10(9, !outsideMode)); //true true
> System.out.println(in1To10(11, outsideMode)); //true true
> System.out.println(in1To10(11, !outsideMode)); //false false
> //etc
> }
> }
While the notion of having a test plan is an excellent one, relying
on human eyeballs to verify the expected output is tedious and may be
error-prone. I'd suggest writing a helper method, something like
static void test(int number, boolean mode, boolean expected) {
boolean actual = in1To10(number, mode);
if (actual != expected) {
throw new AssertionError(String.format(
"in1To10(%d, %b) gave %b, expected %b",
number, mode, actual, expected);
}
}
... and then write the test cases as
test(1, true, true);
test(1, false, true);
...
test(11, true, true);
test(11, false, false);
//etc
--
esosman@comcast-dot-net.invalid
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
in1To10 cdalten@gmail.com - 2014-08-09 12:12 -0700
Re: in1To10 Jeff Higgins <jeff@invalid.invalid> - 2014-08-09 15:58 -0400
Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-09 16:13 -0400
Re: in1To10 Marcel Mueller <news.5.maazl@spamgourmet.org> - 2014-08-09 22:56 +0200
Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-09 17:02 -0400
Re: in1To10 Marcel Mueller <news.5.maazl@spamgourmet.org> - 2014-08-09 23:43 +0200
Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-09 19:49 -0400
Re: in1To10 Torsten Kirschner <torsten@kirschner.no> - 2014-08-10 16:59 +0200
Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-10 11:33 -0400
Re: in1To10 Torsten Kirschner <torsten@kirschner.no> - 2014-08-11 22:23 +0200
Re: in1To10 Gene Wirchenko <genew@telus.net> - 2014-08-12 11:10 -0700
Re: in1To10 Arne Vajhøj <arne@vajhoej.dk> - 2014-08-19 16:54 -0400
Re: in1To10 Gene Wirchenko <genew@telus.net> - 2014-08-20 10:36 -0700
Re: in1To10 Arne Vajhøj <arne@vajhoej.dk> - 2014-08-19 16:53 -0400
Re: in1To10 cdalten@gmail.com - 2014-08-09 18:35 -0700
Re: in1To10 Jeff Higgins <jeff@invalid.invalid> - 2014-08-09 22:13 -0400
Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-09 22:23 -0400
Re: in1To10 Jeff Higgins <jeff@invalid.invalid> - 2014-08-10 12:07 -0400
Re: in1To10 Mike Amling <mamling@chaff.us> - 2014-08-10 00:29 -0500
Re: in1To10 "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-10 13:53 +0100
Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-10 09:48 -0400
Re: in1To10 "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-10 15:01 +0100
Re: in1To10 Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-10 10:32 -0400
Re: in1To10 "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-08-10 15:53 +0100
Re: in1To10 lipska the kat <lipskathekat@example.com> - 2014-08-10 14:07 +0100
Re: in1To10, a simple test plan lipska the kat <lipskathekat@example.com> - 2014-08-10 16:43 +0100
Re: in1To10, a simple test plan Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-10 12:01 -0400
Re: in1To10, a simple test plan lipska the kat <lipskathekat@example.com> - 2014-08-10 17:41 +0100
Re: in1To10, a simple test plan Arne Vajhøj <arne@vajhoej.dk> - 2014-08-19 16:57 -0400
Re: in1To10 Roedy Green <see_website@mindprod.com.invalid> - 2014-08-12 02:59 -0700
csiph-web