The Freak Parade

Strange noises from the mind of Nathan Stults…
  • rss
  • Home
  • About The Freak Parade

The incredible, fallible symmetric Unit Test, and the beauty of Open Source software.

February 24, 2009

We’re doing some GIS development with the incredible NHibernate.Spatial library, which, like all of NHibernate has very good test coverage, from what I can tell. Even so, we ran into a puzzling bug where one of the standard spatial aggregations was returning an impossible result. So I downloaded the NHibernate Spatial source code and ran the unit tests, paying particular attention to the test centered around the spatial aggregation in question. All the tests passed with flying colors, but even so, it couldn’t have been correct, we had proof of that.

The problem? Symmetry. The dummy data used in the test produced identical results with incorrect behavior as it did with correct behavior. 

Here’s the data that was dummied up for the suite of tests:

"SRID=32719;POLYGON((0 0,1 0,1 1,0 1,0 0))"
"SRID=32719;POLYGON((0 1,1 1,1 2,0 2,0 1))"
"SRID=32719;POLYGON((1 1,2 1,2 2,1 2,1 1))"
"SRID=32719;POLYGON((1 0,2 0,2 1,1 1,1 0))"
"SRID=32719;POLYGON((0 0,1 0,1 1,0 1,0 0))"
"SRID=32719;POLYGON((0 1,1 1,1 2,0 2,0 1))"
"SRID=32719;POLYGON((1 1,2 1,2 2,1 2,1 1))"
"SRID=32719;POLYGON((1 0,2 0,2 1,1 1,1 0))"
"SRID=32719;POLYGON((0 0,1 0,1 1,0 1,0 0))"
"SRID=32719;POLYGON((0 1,1 1,1 2,0 2,0 1))"
"SRID=32719;POLYGON((1 1,2 1,2 2,1 2,1 1))"
"SRID=32719;POLYGON((1 0,2 0,2 1,1 1,1 0))"
"SRID=32719;POLYGON((0 0,1 0,1 1,0 1,0 0))"
"SRID=32719;POLYGON((0 1,1 1,1 2,0 2,0 1))"
"SRID=32719;POLYGON((1 1,2 1,2 2,1 2,1 1))"
"SRID=32719;POLYGON((1 0,2 0,2 1,1 1,1 0))"
"SRID=32719;POLYGON((0 0,1 0,1 1,0 1,0 0))"
"SRID=32719;POLYGON((0 1,1 1,1 2,0 2,0 1))"
"SRID=32719;POLYGON((1 1,2 1,2 2,1 2,1 1))"
"SRID=32719;POLYGON((1 0,2 0,2 1,1 1,1 0))"

It isn’t hard to imagine this limited set of three numbers combined in many different ways and coming up with identical results. While it makes for easy test writing, it makes for deceptively ambiguous testing.

In case you run into the same problem, the SpatialProjections.Envelope aggregate function for the PostGIS dialect will produce an envelope where the fourth coordinate contains two Y values, a simple transposition in a string format. A less regular distribution of sample data would have caught this straightaway.

The wonderful thing about this experience, however, was that this bug, which was crippling to the feature we were trying to implement, was easy to find, easy to fix, and within an hour we were back on track. When the patch is applied to the trunk, we can sync back up with the project, and in the mean time we won’t be implementing some awkward work around likely to break in future releases, waiting for some team somewhere to find it as important as we do. Of course, this is one of the hallmarks of Open Source, nothing new – but it is rather pleasant to experience it for yourself.

Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • DZone
  • Digg
  • Google Bookmarks
  • Ma.gnolia
  • Technorati
hello
Categories
General
Comments rss
Comments rss
Trackback
Trackback

« You Can’t Fill an Imaginary Hole Simple ASP.NET MVC Ajax Proxy »

blog comments powered by Disqus

Subscribe

Calendar

February 2009
M T W T F S S
« Nov   Oct »
 1
2345678
9101112131415
16171819202122
232425262728  

Recent Posts

  • So you want to learn IronRuby? – Chapter 1 – “The Back Story”
  • Lucy in the Sky with Ruby
  • Simple ASP.NET MVC Ajax Proxy
  • The incredible, fallible symmetric Unit Test, and the beauty of Open Source software.
  • You Can’t Fill an Imaginary Hole

Recent Comments

  • irfankhadrani on Content Management Systems (CMS) for the .NET Platform
  • adsl viettel on Simple ASP.NET MVC Ajax Proxy
  • nstults on Content Management Systems (CMS) for the .NET Platform
  • hayamayu on Content Management Systems (CMS) for the .NET Platform
  • ADSL Viettel on Evaluating Expressions at Runtime in .NET (C#)

Tags

TDD Testing

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox