<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: How do you specify an exponentiation function with a test?</title>
	<atom:link href="http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/</link>
	<description>Longer than a blog; shorter than a book</description>
	<pubDate>Fri, 21 Nov 2008 20:40:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: David Matuszek</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5452</link>
		<dc:creator>David Matuszek</dc:creator>
		<pubDate>Sat, 15 Jul 2006 15:31:51 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5452</guid>
		<description>Responding to:
  If tests are specs, then how do you specify the tests?
  Do you write tests to test the tests, or do you write a spec?

Forgive the platitudes, but I didn't see any other response to this point.

You test the tests by running them. If a test fails, you determine whether the error is in the code being tested, or in the test itself.

As Dijkstra said, "Testing can demonstrate the presence of bugs, but not their absence." Testing is a (learnable) skill, and some programmers are better at it than others.

Testing, like proofs in mathematics, only serve to increase confidence that something is correct; tests, like proofs, may contain unnoticed flaws. Nothing you can do will ever completely guarantee correctness.

Finally, no programmatic tests can ever to written to test whether the program does what the customer wanted. That's why customer-readable specs are needed; and flaws in those specs are the reason customer acceptance testing is also needed.

Any accusations of lack of originality in the above will be cheerfully admitted.  :)</description>
		<content:encoded><![CDATA[<p>Responding to:<br />
  If tests are specs, then how do you specify the tests?<br />
  Do you write tests to test the tests, or do you write a spec?</p>
<p>Forgive the platitudes, but I didn&#8217;t see any other response to this point.</p>
<p>You test the tests by running them. If a test fails, you determine whether the error is in the code being tested, or in the test itself.</p>
<p>As Dijkstra said, &#8220;Testing can demonstrate the presence of bugs, but not their absence.&#8221; Testing is a (learnable) skill, and some programmers are better at it than others.</p>
<p>Testing, like proofs in mathematics, only serve to increase confidence that something is correct; tests, like proofs, may contain unnoticed flaws. Nothing you can do will ever completely guarantee correctness.</p>
<p>Finally, no programmatic tests can ever to written to test whether the program does what the customer wanted. That&#8217;s why customer-readable specs are needed; and flaws in those specs are the reason customer acceptance testing is also needed.</p>
<p>Any accusations of lack of originality in the above will be cheerfully admitted.  <img src='http://cafe.elharo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5359</link>
		<dc:creator>Matthew</dc:creator>
		<pubDate>Thu, 13 Jul 2006 18:19:09 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5359</guid>
		<description>I think the point is that test cases are an expression of the functionality of the system.  In many cases, this expression may be sufficient to fully document the business, application and/or system requirements for simple systems, but may not.

However, the test cases that are all or part of the 'spec' do for a concrete and binary decision as to when the development is contractually and functionally complete. They also should be a good representation of the Use-Cases associated with the development, including exceptions and alternate paths.

In any case, at test case based spec shapely delimits the scope of the project and tends to limit tangential code development to implement functionality which may be nice (or even a great idea) but not (currently) in scope.

As a consultant, the ability to crisply define and managed scope and scope change is the only way to ensure profitability.

Additionally, this also manages client expectations as they are signing of specific and detailed action-response scenarios that define the system.</description>
		<content:encoded><![CDATA[<p>I think the point is that test cases are an expression of the functionality of the system.  In many cases, this expression may be sufficient to fully document the business, application and/or system requirements for simple systems, but may not.</p>
<p>However, the test cases that are all or part of the &#8217;spec&#8217; do for a concrete and binary decision as to when the development is contractually and functionally complete. They also should be a good representation of the Use-Cases associated with the development, including exceptions and alternate paths.</p>
<p>In any case, at test case based spec shapely delimits the scope of the project and tends to limit tangential code development to implement functionality which may be nice (or even a great idea) but not (currently) in scope.</p>
<p>As a consultant, the ability to crisply define and managed scope and scope change is the only way to ensure profitability.</p>
<p>Additionally, this also manages client expectations as they are signing of specific and detailed action-response scenarios that define the system.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cedric</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5274</link>
		<dc:creator>Cedric</dc:creator>
		<pubDate>Mon, 10 Jul 2006 22:00:49 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5274</guid>
		<description>Ditto, Elliote, I read over the last paragraph too fast, sorry about that.

Here is one way to do this with TestNG.  I hardcoded the numbers in this example to illustrate how @DataProvider works, but you should generate these numbers randomly so that the coverage of your function increases over time:

    @DataProvider(name = "random")
    public Object[][] generateRandomExps() {
      // This array should be generated with random numbers
      return new Object[][] {
        new Object[] { 0.0, Math.exp(0) },
        new Object[] { 1.0, Math.exp(1) },
        new Object[] { 2.0, Math.exp(2) },
      };
    }

    @Test(dataProvider = "random")
    public void testExponent(double exponent, double expected) {
      assertEquals(myExpFunction(exponent), expected);
    }</description>
		<content:encoded><![CDATA[<p>Ditto, Elliote, I read over the last paragraph too fast, sorry about that.</p>
<p>Here is one way to do this with TestNG.  I hardcoded the numbers in this example to illustrate how @DataProvider works, but you should generate these numbers randomly so that the coverage of your function increases over time:</p>
<p>    @DataProvider(name = &#8220;random&#8221;)<br />
    public Object[][] generateRandomExps() {<br />
      // This array should be generated with random numbers<br />
      return new Object[][] {<br />
        new Object[] { 0.0, Math.exp(0) },<br />
        new Object[] { 1.0, Math.exp(1) },<br />
        new Object[] { 2.0, Math.exp(2) },<br />
      };<br />
    }</p>
<p>    @Test(dataProvider = &#8220;random&#8221;)<br />
    public void testExponent(double exponent, double expected) {<br />
      assertEquals(myExpFunction(exponent), expected);<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravi Venkataraman</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5266</link>
		<dc:creator>Ravi Venkataraman</dc:creator>
		<pubDate>Mon, 10 Jul 2006 13:10:43 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5266</guid>
		<description>I apologize. You are right, Elliote. The last paragraph does mention it.

Ravi</description>
		<content:encoded><![CDATA[<p>I apologize. You are right, Elliote. The last paragraph does mention it.</p>
<p>Ravi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliotte Rusty Harold</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5264</link>
		<dc:creator>Elliotte Rusty Harold</dc:creator>
		<pubDate>Mon, 10 Jul 2006 11:09:20 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5264</guid>
		<description>Cedric and Ravi,

Did either of you bother to read to the end of the article or did you just scan the code? Sometimes you have to present an illustrative example in a different form than one would actually write code (or a test suite) to avoid obscuring the points in question. Additional levels of indirection are often useful in programming (and test suites) but they merely serve to obscure explanations.</description>
		<content:encoded><![CDATA[<p>Cedric and Ravi,</p>
<p>Did either of you bother to read to the end of the article or did you just scan the code? Sometimes you have to present an illustrative example in a different form than one would actually write code (or a test suite) to avoid obscuring the points in question. Additional levels of indirection are often useful in programming (and test suites) but they merely serve to obscure explanations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cedric</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5241</link>
		<dc:creator>Cedric</dc:creator>
		<pubDate>Mon, 10 Jul 2006 02:25:27 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5241</guid>
		<description>Elliotte,

As Randall pointed out, the simple fact that it takes so many methods to approximate what exp() does makes my point. 

exp() is actually a very good example of a function that should be tested with data-driven testing, by the way, and not the way you approached it (see TestNG's @DataProvider for more details).</description>
		<content:encoded><![CDATA[<p>Elliotte,</p>
<p>As Randall pointed out, the simple fact that it takes so many methods to approximate what exp() does makes my point. </p>
<p>exp() is actually a very good example of a function that should be tested with data-driven testing, by the way, and not the way you approached it (see TestNG&#8217;s @DataProvider for more details).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ravi Venkataraman</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5237</link>
		<dc:creator>Ravi Venkataraman</dc:creator>
		<pubDate>Sun, 09 Jul 2006 22:40:54 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5237</guid>
		<description>Interesting that one has to write so many different methods for such a simple test. Isn't that code duplication?

All we need is a method that takes three arguments: the base number, the power to which it is to be raised and the expected result.

Write such a method, put this set of three values into a file or a database and validate as many tests as possible. In pseudo code:

for each set of values: // read from a file or database
   assert that Exponent.calculate(base,power) = expectedValue 

Why go for the duplicate code shown above?

This lack of pattern recognition is something I see all the time, even from so-called experts and well known authors. Basically it tells me that they are not thinking at all, they are merely following the herd; and mindlessly reproducing the same stupid code as exemplars of great sagacity.</description>
		<content:encoded><![CDATA[<p>Interesting that one has to write so many different methods for such a simple test. Isn&#8217;t that code duplication?</p>
<p>All we need is a method that takes three arguments: the base number, the power to which it is to be raised and the expected result.</p>
<p>Write such a method, put this set of three values into a file or a database and validate as many tests as possible. In pseudo code:</p>
<p>for each set of values: // read from a file or database<br />
   assert that Exponent.calculate(base,power) = expectedValue </p>
<p>Why go for the duplicate code shown above?</p>
<p>This lack of pattern recognition is something I see all the time, even from so-called experts and well known authors. Basically it tells me that they are not thinking at all, they are merely following the herd; and mindlessly reproducing the same stupid code as exemplars of great sagacity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: N*M</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5232</link>
		<dc:creator>N*M</dc:creator>
		<pubDate>Sun, 09 Jul 2006 20:22:57 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5232</guid>
		<description>It's more like 2^128 tests, not 2^64, because you have to pair every operand with every other operand.</description>
		<content:encoded><![CDATA[<p>It&#8217;s more like 2^128 tests, not 2^64, because you have to pair every operand with every other operand.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Randall</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5231</link>
		<dc:creator>Randall</dc:creator>
		<pubDate>Sun, 09 Jul 2006 19:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5231</guid>
		<description>Re: tests as specs.

If tests are specs, then how do you specify the tests?

Do you write tests to test the tests, or do you write a spec?

At what point does the "tests as specs" recursion bottom out and turn into gibberish or something that's so incredibly self-evident that it doesn't need specification?

And if it's self-evident, then how do you formalize it in a way you can use it to build your first level of tests as specs?

These may seem like mere rhetorical trickery, but as someone who's written both specs and tests for a lot of software, they are very real questions.  They all boil down to the same basic question: Where do you draw the line?

It reminds me of my early days when other engineers would estimate 14 man-hours to code something that hadn't even been designed yet.  As an inexperienced developer, I wondered where such precision could come from in the face of such uncertainty.  Later, I learned that some of it came from experience, but mostly it came from thin air: it was a hopeful fiction.  Until this is ALL acknowledged as little more than hopeful fiction, how can it be taken seriously?</description>
		<content:encoded><![CDATA[<p>Re: tests as specs.</p>
<p>If tests are specs, then how do you specify the tests?</p>
<p>Do you write tests to test the tests, or do you write a spec?</p>
<p>At what point does the &#8220;tests as specs&#8221; recursion bottom out and turn into gibberish or something that&#8217;s so incredibly self-evident that it doesn&#8217;t need specification?</p>
<p>And if it&#8217;s self-evident, then how do you formalize it in a way you can use it to build your first level of tests as specs?</p>
<p>These may seem like mere rhetorical trickery, but as someone who&#8217;s written both specs and tests for a lot of software, they are very real questions.  They all boil down to the same basic question: Where do you draw the line?</p>
<p>It reminds me of my early days when other engineers would estimate 14 man-hours to code something that hadn&#8217;t even been designed yet.  As an inexperienced developer, I wondered where such precision could come from in the face of such uncertainty.  Later, I learned that some of it came from experience, but mostly it came from thin air: it was a hopeful fiction.  Until this is ALL acknowledged as little more than hopeful fiction, how can it be taken seriously?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Cowan</title>
		<link>http://cafe.elharo.com/blogroll/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5230</link>
		<dc:creator>John Cowan</dc:creator>
		<pubDate>Sun, 09 Jul 2006 17:58:31 +0000</pubDate>
		<guid isPermaLink="false">http://cafe.elharo.com/java/how-do-you-specify-an-exponentiation-function-with-a-test/#comment-5230</guid>
		<description>I think you'd both agree, then, that tests are not complete specs.  I'd hate to try to reverse engineer an XMLâ€Šparser solely from its (obfuscated) test suite if I'd never heard of XML, though.</description>
		<content:encoded><![CDATA[<p>I think you&#8217;d both agree, then, that tests are not complete specs.  I&#8217;d hate to try to reverse engineer an XMLâ€Šparser solely from its (obfuscated) test suite if I&#8217;d never heard of XML, though.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
