« | » Main « | »

Flaws in coverage measurement

Tuesday 30 October 2007

Coverage testing is a great way to find out what parts of your code are not tested by your test suite. You turn on coverage.py, then run your tests. At the end, coverage can show you which lines were never executed, either by line number or visually in an annotated source file.

When your test coverage is less than 100%, coverage testing works well: it points you to the lines in your code that are never run, showing the way to new tests to write. The ultimate goal, of course, is to get your test coverage to 100%.

But then you have problems, because 100% test coverage doesn't really mean much. There are dozens of ways your code or your tests could still broken, but now you aren't getting any directions. The measurement coverage.py provides is more accurately called statement coverage, because it tells you which statements were executed. Statement coverage testing has taken you to the end of its road, and the bad news is, you aren't at your destination, but you've run out of road.

By way of illustration, here are a few examples of 100% statement coverage of buggy code.

» read more of: Flaws in coverage measurement... (19 paragraphs)

Halloween pumpkins

Monday 29 October 2007

2007's pumpkins were designed by Max and Ben, and I knew beforehand that they would involve their current anime obsessions. I'd link to some web pages about the anime, but I really don't know what they are! Good pumpkins, though:

Gurren lagann brigade logo pumpkin Naruto mist village symbol pumpkin

Matt Shlian

Sunday 28 October 2007

A random trip through Youtube deposited me at a video of a gorgeous flipbook called "cut out flipbook". It's so simple and beautifully done. The creator, Matt Shlian, is a paper engineer and artist, and his web page has the rest of his videos, which offer surprising and lovely paper creations. As usual, I want how-to instructions!

Plato and a platypus walk into a bar

Sunday 28 October 2007

Plato and a Platypus Walk Into a Bar is a delightful little book. It aims to explain the big topics in philosophy, and illustrate them with jokes. I learned a little and laughed a lot, so I'd say it succeeded.

Not all the jokes fit so well into the philosophic branch they're meant to illustrate, but this isn't meant to be a serious treatise. For example, here's a joke from the Philosophy of Language chapter:

A man goes into the confession booth and tells the priest, "Father, I'm seventy-five years old and last night I made love to two twenty-year-old girls—at the same time."

The priest says, "When did you last go to confession?"

The man says, "I've never been to confession, Father. I'm Jewish."

The priest says, "Then why are you telling me?"

The man says, "I'm telling everybody!"

I guess there's a point here about differing assumptions about the dialog, but it doesn't really matter: the joke is funny. The whole book is like that: you'll learn something about philosophy, and even if you don't, the jokes are funny.


Saturday 27 October 2007

Debatepedia is a great new addition to the ecosystem of Wikipedia spin-offs. It is a collection of debate topics run curated by the International Debate Education Association for the benefit of student debaters. The topics are carefully broken down into subquestions, with pros and cons logically presented, with links to evidence and advocacy groups.

They of course have pages devoted to current hot topics, like death penalty and same-sex marriage, as well as controversies I was unaware of, like goat-giving at Christmas.

This seems like a great resource for people interested in learning more about an issue, either to help understand all of the viewpoints, or to brush up on their opponents' likely counter-arguments.

I would love to see historical debating points. The topics on Debatepedia are all current controversies. What about issues which are well-resolved now but were controversial in the past? What would the Debatepedia of 1907 or 1807 or even 1507 look like? Should women be given the right to vote? Is slavery acceptable? Can witchcraft be detected and cured? I think it would be fascinating to see how reasonable people of those times argued these points.

Continuous line art

Wednesday 24 October 2007

I was fascinated to see the variety of different art that could be made with a single continuous line. An artificial constraint like that ends up forcing the artist's creativity to emerge in new ways. The video of the drawing on the wall makes me wonder though, how much planning and practice was necessary to create an image that good?

Why we curse

Friday 19 October 2007

Stephen Pinker has written a great piece on cursing: What the F***? Why We Curse. It's erudite and revelatory, covering the strange grammar of swears, why words are considered swears, the origin of their prohibition, and so on.

I liked this anecdote:

When Bess Truman was asked to get the president to say fertilizer instead of manure, she replied, "You have no idea how long it took me to get him to say manure."

Wikipedia quick search

Friday 19 October 2007

I love the Firefox custom keywords feature, and the way it's used to do quick searches. Firefox comes with one for Wikipedia, where "w" is a short-cut like this:


It works pretty well. The problem is that Wikipedia URLs are case-sensitive. So if I type "w jimmy durante", I get to a page which has helpfully capitalized Jimmy, but left durante alone, so that the page is not found, and I'm stuck at an oh-so-close Not Found page.

But I noticed that if I type "jimmy durante" into the search box, it takes me directly to the Jimmy Durante page. So I redefined my Wikipedia quick search:


Now if I have the title correct except for case, I get taken straight to the page I want, and if the page doesn't exist, I at least see close matches. Much better.

Http-https transitions and relative URLs

Wednesday 17 October 2007

When building a web site with HTTPS pages, one of the annoying tasks is to ensure that those pages make no references to HTTP resources. If they do, then Internet Explorer will pop up alarming messages about mixing secure and insecure content, and do you want to display the insecure content. This confuses users and generally discourages them from continuing to use your site.

To fix the problem, all URLs on the page must use HTTPS. Web sites these days are built from reusable components, some of which may be used on both HTTP and HTTPS pages. How to make the URLs correct for both?

Relative URLs are the answer. Typically, relative URLs omit the hostname, specifying the full path to the resource, or perhaps just a single path component:

<img src='/pix/smiley.jpg' />
<img src='smiley.jpg' />

Either of these images will display without warning on either HTTP or HTTPS pages. Since the host name is omitted, it uses the host name from the page being displayed. But these URLs also omit the protocol scheme, so the protocol is taken from the base URL also. On an HTTP page, the images will be requested using HTTP, on an HTPPS page, they will use HTTPS. That's why there's no warning, because there's no mixing of secure and insecure content.

But what if you need to pull resources from another site? For example, a CDN (content delivery network)? Here the problem seems to be thornier:

<img src='http://fast.cdn.net/pix/smiley.jpg' />

If this reference appears in an HTTPS page, the mixed content warning will appear. How to craft a reference that works for both? The answer is again relative URLs, but using a more obscure syntax:

<img src='//fast.cdn.net/pix/smiley.jpg' />

Here, we've left off the protocol scheme, but included a host name. In this case, the protocol scheme from the displayed page will be used, but against the host in the URL. The relative URL system is still in play here: omitted portions of the URL at the beginning are taken from the base page, and the relative URL takes over whereever it starts. On an HTTPS page, this will be an HTTPS request to the CDN, on an HTTP page, it will be an HTTP request.

You have to be careful to only use this syntax in pages destined for browsers. If you put it in an email, there will be no base page URL to use in resolving the relative URL. In Outlook at least, this URL will be interpreted as a Windows network file, not what you intended.

BTW: when trying to get rid of the mixed secure and insecure content warning, you really have to fix up every URL, even if it doesn't seem like it's being used for anything. Flash content? There's a macromedia.com URL in there in the codebase attribute:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
   width="600" height="400"> ... </object>

Making it scheme-relative as shown will also prevent warnings.

Modular pie-cosahedron

Sunday 14 October 2007

Looking for an unusual dessert to make for Thanksgiving this year? How about a pie in the shape of an icosahedron? This is what Instructables is all about: two geeks spending a ton of time making 20 specially-crafted pie tins so they can bake 20 triangular pecan pies, then attach them with super magnets to create a foot-high icosahedron of pie! And how often do baking instructions make reference to the hairy ball theorem?

The comments are also awesome, as math, baking, and physics geeks chime in to debate and joke:

A piecosahedron can be defined as a regular plenty-sided pie, or, in more mathematical detail, as a delicial approximation of a 2-sphere (which is the simplest space with nontrivial pie-2) constructed out of twenty regular pi-angles. It is inextricably interrelated with its dual, the doughdecahedron.


Friday 12 October 2007

Aptus is a side project I've been tinkering with the last few months. It's a Mandelbrot set explorer and renderer.

A portion of the Mandelbrot set

Aptus is written in Python with a wxPython user interface. It runs on Windows, Mac, and Linux. It has a computation engine in C for speed, with boundary tracing and cycle detection for more speed. There's also command-line renderer for making higher-quality renderings by supersampling pixels to get smoother contours and more detail.

There are other Mandelbrot explorers of course. Xaos is particularly good at interactivity, but is poor at controlling the look of the image. I wrote Aptus partly to improve the look of the final rendering, and partly to have fun on a side project.

This is one of those side projects with a number of different facets to hold my attention as my interests shift. In a visual mood, I can extend the graphic options, in a quantitative mood, I can dig out a little more speed from the engine, and so on.

Side projects have always been a good way for me to extend my skills. For example, this is the first time I have undertaken a C extension for Python. Writing Aptus has also forced me to examine and deepen my understanding of floating point numbers, and GUI programming is always a challenge.

Plus, I like looking at the pretty pictures...

Histogram as image

Monday 1 October 2007

David at Ironic Sans had a cool idea: hide an image in the histogram of another image. Not a generally useful technique, but a neat hack that demonstrates that a stream of data may be interpretable in unusual ways. Nick Fisher took it one step further and made an online tool for creating these.

A commenter points to images hidden in audio spectrographs, a similar idea.

All these techniques are forms of steganography, the art of hiding messages inside other messages. It's a form of secret communication complete distinct from cryptography, and has a long, rich and fascinating history.

Completely off-topic: Ironic Sans also has a witty line of pre-pixelated T-shirts for reality TV.

« | » Main « | »