Print Story Bread error
Diary
By tmoertel (Wed Sep 01, 2004 at 06:23:59 PM EST) (all tags)
Tonight, I used up the last slice of bread on a tomato sandwich. Being a modern renaissance man, I decided to bake a couple of replacement loaves rather than run to the store. Now it's 2:01 AM, I'm dead tired, and the bread is still rising. What was I thinking?

Perl + QuickCheck.



Over the last couple of days I've been hacking up a Perl version of Haskell's ultra-cool QuickCheck. Maybe I'll talk about it at the next Pittsburgh Perl Mongers gathering.

Writing the Generator library and combinators was fun. It was also fun writing up unit tests for them. The interesting thing is that many of the tests for the generators rely on statistical inferences. As a result, even if everything works, there is 1-in-250 chance that the suite won't pass. I guess I should mention that in the docs.

For your entertainment, the output of the test suite:

1..62
ok 1 - use QuickCheck::Generator;
ok 2 - Int constructor returns something
ok 3 - Int ctor returns a QuickCheck::Generator
ok 4 - Bool constructor returns something
ok 5 - Bool ctor returns a QuickCheck::Generator
ok 6 - Float constructor returns something
ok 7 - Float ctor returns a QuickCheck::Generator
ok 8 - Char constructor returns something
ok 9 - Char ctor returns a QuickCheck::Generator
ok 10 - String constructor returns something
ok 11 - String ctor returns a QuickCheck::Generator
ok 12 - List constructor returns something
ok 13 - List ctor returns a QuickCheck::Generator
ok 14 - Hash constructor returns something
ok 15 - Hash ctor returns a QuickCheck::Generator
ok 16 - Elements constructor returns something
ok 17 - Elements ctor returns a QuickCheck::Generator
ok 18 - Unit(1) constructor returns something
ok 19 - Unit(1) ctor returns a QuickCheck::Generator
ok 20 - Paste constructor returns something
ok 21 - Paste ctor returns a QuickCheck::Generator
ok 22 - OneOf(Unit(0)) constructor returns something
ok 23 - OneOf(Unit(0)) ctor returns a QuickCheck::Generator
ok 24 - Frequency([1,"a"]) constructor returns something
ok 25 - Frequency([1,"a"]) ctor returns a QuickCheck::Generator
ok 26 - Bool dist mean is 0.5 (z-score = -0.12)
ok 27 - Elements(0 1 2 3 4 5 6 7 8 9) is complete and uniformly distributed
ok 28 - Elements(a b c d e f g h i j) is complete and uniformly distributed
ok 29 - Frequency(all freqs = 1, 0 1 2 3 4 5 6 7 8 9) is complete and uniformly distributed
ok 30 - Frequency(all freqs = 1, a b c d e f g h i j) is complete and uniformly distributed
ok 31 - Frequency([[0,Unit("no")],[1,Unit("yes")]]) generates only 'yes'
ok 32 - Frequency([[1,Unit("yes")],[0,Unit("no")]]) generates only 'yes'
ok 33 - Unit("a")->generate eq "a"
ok 34 - Unit(1)->generate eq 1
ok 35 - Unit(0.334)->generate eq 0.334
ok 36 - Int(sized=>0,range=>[-3005,-2996]) is complete and uniformly distributed
ok 37 - Int(sized=>0,range=>[-2005,-1996]) is complete and uniformly distributed
ok 38 - Int(sized=>0,range=>[-1005,-996]) is complete and uniformly distributed
ok 39 - Int(sized=>0,range=>[-5,4]) is complete and uniformly distributed
ok 40 - Int(sized=>0,range=>[995,1004]) is complete and uniformly distributed
ok 41 - Int(sized=>0,range=>[1995,2004]) is complete and uniformly distributed
ok 42 - Int(sized=>0,range=>[2995,3004]) is complete and uniformly distributed
ok 43 - Int(sized=>0,range=>[-400,-200]) dist mean is -300 (z-score = 0.12)
ok 44 - Int(sized=>0,range=>[-300,-100]) dist mean is -200 (z-score = -0.19)
ok 45 - Int(sized=>0,range=>[-200,0]) dist mean is -100 (z-score = -0.52)
ok 46 - Int(sized=>0,range=>[-100,100]) dist mean is 0 (z-score = 1.12)
ok 47 - Int(sized=>0,range=>[0,200]) dist mean is 100 (z-score = -1.39)
ok 48 - Int(sized=>0,range=>[100,300]) dist mean is 200 (z-score = -1.30)
ok 49 - Int(sized=>0,range=>[200,400]) dist mean is 300 (z-score = -1.75)
ok 50 - Int(sized=>1,range=>[0,2000]) dist mean is 900 (z-score = -0.70)
ok 51 - Int(sized=>1,range=>[0,4000]) dist mean is 1600 (z-score = -0.05)
ok 52 - Int(sized=>1,range=>[0,6000]) dist mean is 2100 (z-score = -0.63)
ok 53 - Int(sized=>1,range=>[0,8000]) dist mean is 2400 (z-score = 0.60)
ok 54 - Int(sized=>1,range=>[0,10000]) dist mean is 2500 (z-score = 0.64)
ok 55 - Int(sized=>1,range=>[-1,1]) dist mean is 0 (z-score = 0.70)
ok 56 - Int(sized=>1,range=>[-2000,2000]) dist mean is 0 (z-score = 2.41)
ok 57 - Int(sized=>1,range=>[-4000,4000]) dist mean is 0 (z-score = 0.45)
ok 58 - Int(sized=>1,range=>[-6000,6000]) dist mean is 0 (z-score = -0.83)
ok 59 - Int(sized=>1,range=>[-8000,8000]) dist mean is 0 (z-score = -1.50)
ok 60 - Int(sized=>1,range=>[-10000,10000]) dist mean is 0 (z-score = -0.09)
ok 61 - Paste w/o glue as expected
ok 62 - Paste w/ glue as expected

Has the bread risen yet?

< Looks like a thin year ahead. | BBC White season: 'Rivers of Blood' >
Bread error | 10 comments (10 topical, 0 hidden) | Trackback
For your entertainment... by fritz the cat (5.00 / 1) #1 Wed Sep 01, 2004 at 08:55:50 PM EST
I think we have different ideas of what 'entertainment' means.

[Ed.: currently a dormant account - posting on behalf of extremely tedious HuSer]
Speak for yourself by Rogerborg (6.00 / 1) #2 Wed Sep 01, 2004 at 10:01:32 PM EST
Unit tests get me hot.

-
Metus amatores matrum compescit, non clementia.
[ Parent ]
I am not geek enough for a witty rebuttal [nt] by fritz the cat (3.00 / 0) #3 Wed Sep 01, 2004 at 10:11:37 PM EST
[nt] = no tekkie humour

[Ed.: currently a dormant account - posting on behalf of extremely tedious HuSer]
[ Parent ]
Naturally by tmoertel (3.00 / 0) #10 Thu Sep 02, 2004 at 03:12:45 AM EST
Unit tests get me hot.
It was with you in mind that at the end of my article I asked euphemistically, "Has the bread risen yet?"

--
Write Perl code? Check out LectroTest. Write markup-dense XML? Check out PXSL.

[ Parent ]
FWIW by komet (3.00 / 0) #6 Thu Sep 02, 2004 at 01:27:40 AM EST
there are much lamer ways to be a smelly perl hippie than this.

--
<ni> komet: You are functionally illiterate as regards trashy erotica.
[ Parent ]
O'Reilly just lost 45,000 points in my book [nt] by fritz the cat (3.00 / 0) #7 Thu Sep 02, 2004 at 01:31:37 AM EST
[nt] = no taste

[Ed.: currently a dormant account - posting on behalf of extremely tedious HuSer]
[ Parent ]
I used to write documentation in a strip club by fencepost (3.00 / 0) #8 Thu Sep 02, 2004 at 01:45:59 AM EST
Because the other options were writing documentation sitting in my hotel room, writing documentation in a cube area that was converted from factory floor in the 60's or driving 15 miles to get to a bookstore or coffeeshop. At least the scenery was nicer, and hey if you're going to be working off battery with a dimmed screen isn't it better to be in a dark room?

After I discovered the coffeeshop 3 blocks from the hotel (with free Internet access no less) I never went back.

I'm still glad that I didn't take the offer to move to Ohio.


[ Parent ]
Thoughts by Vulch (6.00 / 1) #4 Wed Sep 01, 2004 at 10:13:09 PM EST

You were thinking "Why don't I get a bread machine with timer function so I could have loaded it up three hours ago and gone to bed, then there'd be nice fresh bread ready and waiting when I got up" of course.

Oh, but I do have a bread machine by tmoertel (3.00 / 0) #9 Thu Sep 02, 2004 at 03:01:52 AM EST
It's just that I find the crust of bread-machine bread to be unsatisfactory. I much prefer bread baked on a large oven stone.

Still, in this particular case, you might be right about the more practical of the two approaches.

--
Write Perl code? Check out LectroTest. Write markup-dense XML? Check out PXSL.

[ Parent ]
The Breakmaker's Lament by tps12 (6.00 / 1) #5 Thu Sep 02, 2004 at 01:08:48 AM EST
I feel your pain.

Bread error | 10 comments (10 topical, 0 hidden) | Trackback