<?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: Automated Unit Testing your Java using ScalaCheck</title>
	<atom:link href="http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Thu, 28 Aug 2008 12:28:05 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Rickard Nilsson</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2275</link>
		<dc:creator>Rickard Nilsson</dc:creator>
		<pubDate>Wed, 04 Jun 2008 12:01:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2275</guid>
		<description>Sorry...


val genSizeAndRange = for {
  size __ Gen.choose(1,1000)
  range __ Gen.choose(size+1, size+5000)
} yield (size, range)</description>
		<content:encoded><![CDATA[<p>Sorry&#8230;</p>
<p>val genSizeAndRange = for {<br />
  size __ Gen.choose(1,1000)<br />
  range __ Gen.choose(size+1, size+5000)<br />
} yield (size, range)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rickard Nilsson</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2274</link>
		<dc:creator>Rickard Nilsson</dc:creator>
		<pubDate>Wed, 04 Jun 2008 11:57:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2274</guid>
		<description>OK, third attempt. WP doesn't seem to like for-comprehensions.

val genSizeAndRange = for {
  size</description>
		<content:encoded><![CDATA[<p>OK, third attempt. WP doesn&#8217;t seem to like for-comprehensions.</p>
<p>val genSizeAndRange = for {<br />
  size</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rickard Nilsson</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2273</link>
		<dc:creator>Rickard Nilsson</dc:creator>
		<pubDate>Wed, 04 Jun 2008 11:55:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2273</guid>
		<description>Hmm, WordPress seemed to strip all my pre-tags, and cut some of the code... Here's that first generator again:


val genSizeAndRange = for {
  size</description>
		<content:encoded><![CDATA[<p>Hmm, WordPress seemed to strip all my pre-tags, and cut some of the code&#8230; Here&#8217;s that first generator again:</p>
<p>val genSizeAndRange = for {<br />
  size</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rickard Nilsson</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2272</link>
		<dc:creator>Rickard Nilsson</dc:creator>
		<pubDate>Wed, 04 Jun 2008 11:51:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2272</guid>
		<description>Hi Jörn!

Since the chance that you implication condition is fulfilled when ScalaCheck generates sizes and ranges at random, you will easily get into the situation where to many tests are discarded. The simplest way to solve the problem is to implement a small generator that only generates sizes and ranges of your taste:


val genSizeAndRange = for {
  size

For simplicity, I hardcoded the upper limits of size and range here, but you could also have used the Gen.sized combinator to let ScalaCheck decide how large numbers to generate.

Now we can write the specification like this:


specify("generate", Prop.forAll(genSizeAndRange) {
  case (size,range) =&#38;gt; generate(size, range).size == size
})


As for Arbitrary[Generator], in this case there is no really need for it, since your generator class is so simple (all Generator instances look the same). Anyway, here is how you would do it:


implicit val arbGenerator = Arbitrary(Gen.value(new Generator))


Now you can write properties like this one:


specify("generate", (g: Generator) =&#38;gt; forAll(genSizeAndRange) {
  case (size,range) =&#38;gt; g.generate(size, range).size == size
})


Hope this helps to get you started!</description>
		<content:encoded><![CDATA[<p>Hi Jörn!</p>
<p>Since the chance that you implication condition is fulfilled when ScalaCheck generates sizes and ranges at random, you will easily get into the situation where to many tests are discarded. The simplest way to solve the problem is to implement a small generator that only generates sizes and ranges of your taste:</p>
<p>val genSizeAndRange = for {<br />
  size</p>
<p>For simplicity, I hardcoded the upper limits of size and range here, but you could also have used the Gen.sized combinator to let ScalaCheck decide how large numbers to generate.</p>
<p>Now we can write the specification like this:</p>
<p>specify(&#8221;generate&#8221;, Prop.forAll(genSizeAndRange) {<br />
  case (size,range) =&#38;gt; generate(size, range).size == size<br />
})</p>
<p>As for Arbitrary[Generator], in this case there is no really need for it, since your generator class is so simple (all Generator instances look the same). Anyway, here is how you would do it:</p>
<p>implicit val arbGenerator = Arbitrary(Gen.value(new Generator))</p>
<p>Now you can write properties like this one:</p>
<p>specify(&#8221;generate&#8221;, (g: Generator) =&#38;gt; forAll(genSizeAndRange) {<br />
  case (size,range) =&#38;gt; g.generate(size, range).size == size<br />
})</p>
<p>Hope this helps to get you started!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jörn Zaefferer</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2271</link>
		<dc:creator>Jörn Zaefferer</dc:creator>
		<pubDate>Tue, 03 Jun 2008 12:17:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2271</guid>
		<description>Hi Tony,

I'm currently trying to wrap my head around Scala and the ideas and concepts of ScalaCheck. Currently I'm trying to write properties for a simple generator class. The method I'm trying to test is this:

&lt;pre&gt;/**
	 * Generates a sorted list of numbers in the given range, without
	 * duplicates.
	 *
	 * @param size
	 *            How many numbers to generate
	 * @param range
	 *            The range of numbers to generate, from 1 to the given value,
	 *            both inclusive
	 * @return A random list of numbers for the given size and range, sorted
	 *         ascending
	 */
	public List generate(int size, int range) {
		List result = new ArrayList();
		for (int i = 0; i &#38;lt; size; i++) {
			int next;
			do {
				next = generateOneOutOf(range);
			} while (result.contains(next));
			result.add(next);
		}
		return result;
	}&lt;/pre&gt;

The properties I'd like to state: For any value of size, the resulting list must have that size. For any value of range, the resulting list must have values inside that range, not outside of it. The preconditions are size &#38;gt; 0 and range &#38;gt; size (not in the JavaDoc, got to fix that - ScalaCheck already helped to show that).

What I managed to get running so far is this:

&lt;pre&gt;def generate(size: Int, range: Int): java.util.List[Integer] = {
    new Generator().generate(size, range)
  }

  specify("generate", (size: Int, range: Int) =&#38;gt; (size &#38;gt; 0 &#38;#38;&#38;#38; range &#38;gt; size) ==&#38;gt; (generate(size, range).size == size) )&lt;/pre&gt;

This doesn't quite work out as too many tests get discarded, ala "gave up after only 59 passed tests. 500 tests were discarded.".

I couldn't figure out how to implement Arbitrary[Generator], nor how to use eg. Gen.choose to define the preconditions outside the property.

Some ideas to get started are very welcome!</description>
		<content:encoded><![CDATA[<p>Hi Tony,</p>
<p>I&#8217;m currently trying to wrap my head around Scala and the ideas and concepts of ScalaCheck. Currently I&#8217;m trying to write properties for a simple generator class. The method I&#8217;m trying to test is this:</p>
<pre>/**
	 * Generates a sorted list of numbers in the given range, without
	 * duplicates.
	 *
	 * @param size
	 *            How many numbers to generate
	 * @param range
	 *            The range of numbers to generate, from 1 to the given value,
	 *            both inclusive
	 * @return A random list of numbers for the given size and range, sorted
	 *         ascending
	 */
	public List generate(int size, int range) {
		List result = new ArrayList();
		for (int i = 0; i &#38;lt; size; i++) {
			int next;
			do {
				next = generateOneOutOf(range);
			} while (result.contains(next));
			result.add(next);
		}
		return result;
	}</pre>
<p>The properties I&#8217;d like to state: For any value of size, the resulting list must have that size. For any value of range, the resulting list must have values inside that range, not outside of it. The preconditions are size &#38;gt; 0 and range &#38;gt; size (not in the JavaDoc, got to fix that - ScalaCheck already helped to show that).</p>
<p>What I managed to get running so far is this:</p>
<pre>def generate(size: Int, range: Int): java.util.List[Integer] = {
    new Generator().generate(size, range)
  }

  specify("generate", (size: Int, range: Int) =&#38;gt; (size &#38;gt; 0 &#38;#38;&#38;#38; range &#38;gt; size) ==&#38;gt; (generate(size, range).size == size) )</pre>
<p>This doesn&#8217;t quite work out as too many tests get discarded, ala &#8220;gave up after only 59 passed tests. 500 tests were discarded.&#8221;.</p>
<p>I couldn&#8217;t figure out how to implement Arbitrary[Generator], nor how to use eg. Gen.choose to define the preconditions outside the property.</p>
<p>Some ideas to get started are very welcome!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rickard Nilsson</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2270</link>
		<dc:creator>Rickard Nilsson</dc:creator>
		<pubDate>Sun, 11 May 2008 17:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2270</guid>
		<description>ScalaCheck 1.3 is now available at http://www.scalacheck.org!</description>
		<content:encoded><![CDATA[<p>ScalaCheck 1.3 is now available at <a href="http://www.scalacheck.org" onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.scalacheck.org');" rel="nofollow">http://www.scalacheck.org</a>!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rickard Nilsson</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2269</link>
		<dc:creator>Rickard Nilsson</dc:creator>
		<pubDate>Sun, 11 May 2008 15:44:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2269</guid>
		<description>@Gábor: There is no support for that kind of testing in ScalaCheck currently. There exist a checking method that can execute several tests of a property in parallel by the use of Scala Actors. However, the data is then generated per test execution (and hence per thread). It should be possible though to let your properties access a shared object, and then you will get multi-threaded access if you use the right check method in ScalaCheck. I think it is difficult to write sensible properties about a global mutable object though, but maybe it could be used for some sort of sanity check that makes sure your class doesn't get into a deadlock or so. You should also look into the Commands trait in ScalaCheck, where it is possible to specify properties about command sequences and mutable systems. It doesn't support multi-threading though, but it would be an interesting extension. I'll give it some thought....</description>
		<content:encoded><![CDATA[<p>@Gábor: There is no support for that kind of testing in ScalaCheck currently. There exist a checking method that can execute several tests of a property in parallel by the use of Scala Actors. However, the data is then generated per test execution (and hence per thread). It should be possible though to let your properties access a shared object, and then you will get multi-threaded access if you use the right check method in ScalaCheck. I think it is difficult to write sensible properties about a global mutable object though, but maybe it could be used for some sort of sanity check that makes sure your class doesn&#8217;t get into a deadlock or so. You should also look into the Commands trait in ScalaCheck, where it is possible to specify properties about command sequences and mutable systems. It doesn&#8217;t support multi-threading though, but it would be an interesting extension. I&#8217;ll give it some thought&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rickard Nilsson</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2268</link>
		<dc:creator>Rickard Nilsson</dc:creator>
		<pubDate>Sun, 11 May 2008 08:56:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2268</guid>
		<description>@James: You can use the Properties trait in ScalaCheck to define several properties in a simple way. In the upcoming release (1.3) of ScalaCheck this trait has been improved to be even simpler to use, for example it now contains a main-method. Look at the section "Grouping Properties" in the ScalaCheck 1.3 user guide, http://code.google.com/p/scalacheck/wiki/UserGuide13 .  I plan to release ScalaCheck 1.3 later today.</description>
		<content:encoded><![CDATA[<p>@James: You can use the Properties trait in ScalaCheck to define several properties in a simple way. In the upcoming release (1.3) of ScalaCheck this trait has been improved to be even simpler to use, for example it now contains a main-method. Look at the section &#8220;Grouping Properties&#8221; in the ScalaCheck 1.3 user guide, <a href="http://code.google.com/p/scalacheck/wiki/UserGuide13" onclick="javascript:pageTracker._trackPageview('/outbound/comment/code.google.com');" rel="nofollow">http://code.google.com/p/scalacheck/wiki/UserGuide13</a> .  I plan to release ScalaCheck 1.3 later today.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gábor Bakos</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2267</link>
		<dc:creator>Gábor Bakos</dc:creator>
		<pubDate>Sat, 10 May 2008 19:57:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2267</guid>
		<description>Hi Tony,
Was the properties tested in a multithreaded context? (As I know java.util.LinkedList is not thread-safe.) Is it possible to test the properties with more than one thread and shared objects?</description>
		<content:encoded><![CDATA[<p>Hi Tony,<br />
Was the properties tested in a multithreaded context? (As I know java.util.LinkedList is not thread-safe.) Is it possible to test the properties with more than one thread and shared objects?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tony Morris</title>
		<link>http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2266</link>
		<dc:creator>Tony Morris</dc:creator>
		<pubDate>Sun, 04 May 2008 20:33:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/automated-unit-testing-your-java-using-scalacheck/#comment-2266</guid>
		<description>Hi James,
No it is not complicated, but such a feature is not implemented by ScalaCheck. However, keep an eye out here for an announcement of this ability and much more ;)</description>
		<content:encoded><![CDATA[<p>Hi James,<br />
No it is not complicated, but such a feature is not implemented by ScalaCheck. However, keep an eye out here for an announcement of this ability and much more <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
</channel>
</rss>
