The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Of Tests, Tautology, and Alignment

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Of Tests, Tautology, and Alignment Posted: May 31, 2007 2:23 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Of Tests, Tautology, and Alignment
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

One of my favorite XP early day stories was some time I spent talking with Ward Cunningham at the original XP workshop in '99. Ward was describing a testing experience where he was writing a little game of life thing, and he was doing tests. He was writing a fixed size game, so his tests were for a fixed size grid. At one point, someone (Beck maybe?) convinced him to make the tests be for a generalized size, and this apparently had a positive effect on the process. Abstractiions became apparent that made the game and tests easier to write, and run faster.

One of the things that worries me about this story, is that I might have myth-ized it as the years have moved on. I apologize up front for any misrepresentations.

Somehwere in there, I came to call one aspect of this the Test Tautology problem. "Test Tautology" is basically when your test code says the same thing, has the exact same algorithm, as the code it's testing. If there's an error in the algorithm, you tend to duplicate it. I've come to the conclusion that you really want find a different way to express the same thing if you can. If you can't, it's possible you're testing at the wrong point, or that your testing meaningless stuff and wasting time that would be better spent on productive coding.

One example I thought of in this regard recently was how one would write tests for and then code for a widget that center's text. One might start with a test that tested left alignment. And then add a test for right alignment. And then the code. And then another test for centering, and of course then the code. Likely, the way this would go down is with some sort of symbol or other flag, and code that "branches" for each type of alignment.

If we back up a bit though, we can look at the "alignment" algorithm in abstract. It's really nothing more than

(containerWidth - textLineWidth) * someFraction
You can factor it the other way, but it works either way. Left is 0.0. Center is 0.5. Right is 1.0. Those just become helpers though. Your test is for an arbitrary fraction or two. And in the end, you've got something that can do the standard 3, but can do zany things like 0.4 too. Is that valuable? I don't know. The point is that this kind of test and code end up being less branchy and easier to trust in my experience. A "less is more" sort of thing. And a different way to express the center/left/right API.

Read: Of Tests, Tautology, and Alignment

Topic: New BottomFeeder Dev Build up Previous Topic   Next Topic Topic: Updated Tutorial

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use