package prop
Scalatest support for Property-based testing.
Introduction to Property-based Testing
In traditional unit testing, you write tests that describe precisely what the test will do: create these objects, wire them together, call these functions, assert on the results, and so on. It is clear and deterministic, but also limited, because it only covers the exact situations you think to test. In most cases, it is not feasible to test all of the possible combinations of data that might arise in real-world use.
Property-based testing works the other way around. You describe properties -- rules that you expect your classes to live by -- and describe how to test those properties. The test system then generates relatively large amounts of synthetic data (with an emphasis on edge cases that tend to make things break), so that you can see if the properties hold true in these situations.
As a result, property-based testing is scientific in the purest sense: you are stating a hypothesis about how things should work (the property), and the system is trying to falsify that hypothesis. If the tests pass, that doesn't prove the property holds, but it at least gives you some confidence that you are probably correct.
Property-based testing is deliberately a bit random: while the edge cases get tried upfront, the system also usually generates a number of random values to try out. This makes things a bit non-deterministic -- each run will be tried with somewhat different data. To make it easier to debug, and to build regression tests, the system provides tools to re-run a failed test with precisely the same data.
Background
TODO: Bill should insert a brief section on QuickCheck, ScalaCheck, etc, and how this system is similar and different.
Using Property Checks
In order to use the tools described here, you should import this package:
import org.scalatest._ import org.scalatest.prop._
This library is designed to work well with the types defined in Scalactic, and some functions take types such as PosZInt as parameters. So it can also be helpful to import those with:
import org.scalactic.anyvals._
In order to call forAll
, the function that actually
performs property checks, you will need to either extend or import GeneratorDrivenPropertyChecks,
like this:
class DocExamples extends FlatSpec with Matchers with GeneratorDrivenPropertyChecks {
There's nothing special about FlatSpec, though -- you may use any of ScalaTest's styles with property checks. GeneratorDrivenPropertyChecks extends CommonGenerators, so it also provides access to the many utilities found there.
What Does a Property Look Like?
Let's check a simple property of Strings -- that if you concatenate a String to itself, its length will be doubled:
"Strings" should "have the correct length when doubled" in { forAll { (s: String) => val s2 = s * 2 s2.length should equal (s.length * 2) } }
(Note that the examples here are all using the FlatSpec style, but will work the same way with any of ScalaTest's styles.)
As the name of the tests suggests, the property we are testing is the length of a String that has been doubled.
The test begins with forAll
. This is usually the way you'll want to begin property checks, and
that line can be read as, "For all Strings, the following should be true".
The test harness will generate a number of Strings, with various contents and lengths. For each one,
we compute s * 2
. (*
is a function on String, which appends the String to itself as many times
as you specify.) And then we
check that the length of the doubled String is twice the length of the original one.
Using Specific Generators
Let's try a more general version of this test, multiplying arbitrary Strings by arbitrary multipliers:
"Strings" should "have the correct length when multiplied" in { forAll { (s: String, n: PosZInt) => val s2 = s * n.value s2.length should equal (s.length * n.value) } }
Again, you can read the first line of the test as "For all Strings, and all non-negative Integers, the following should be true". (PosZInt is a type defined in Scalactic, which can be any positive integer, including zero. It is appropriate to use here, since multiplying a String by a negative number doesn't make sense.)
This intuitively makes sense, but when we try to run it, we get a JVM Out of Memory error! Why? Because the test system tries to test with the "edge cases" first, and one of the more important edge cases is Int.MaxValue. It is trying to multiply a String by that, which is far larger than the memory of even a big computer, and crashing.
So we want to constrain our test to sane values of n
, so that it doesn't crash. We can do this by
using more specific Generators.
When we write a forAll
test like the above, ScalaTest has to generate the values to be tested -- the
semi-random Strings, Ints and other types that you are testing. It does this by calling on an implicit
Generator for the desired type. The Generator generates values to test, starting with the edge cases
and then moving on to randomly-selected values.
ScalaTest has built-in Generators for many major types, including String and PosZInt, but these Generators are generic: they will try any value, including values that can break your test, as shown above. But it also provides tools to let you be more specific.
Here is the fixed version of the above test:
"Strings" should "have the correct length when multiplied" in { forAll(strings, posZIntsBetween(0, 1000)) { (s: String, n: PosZInt) => val s2 = s * n.value s2.length should equal (s.length * n.value) } }
This is using a variant of forAll, which lets you specify the Generators to use instead of just picking the implicit one. CommonGenerators.strings is the built-in Generator for Strings, the same one you were getting implicitly. (The other built-ins can be found in CommonGenerators. They are mixed into GeneratorDrivenPropertyChecks, so they are readily available.)
But CommonGenerators.posZIntsBetween is a function that creates a Generator that selects from the given values. In this case, it will create a Generator that only creates numbers from 0 to 1000 -- small enough to not blow up our computer's memory. If you try this test, this runs correctly.
The moral of the story is that, while using the built-in Generators is very convenient, and works most of the time, you should think about the data you are trying to test, and pick or create a more-specific Generator when the test calls for it.
CommonGenerators contains many functions that are helpful in common cases. In particular:
xxsBetween
(wherexxs
might be Int, Long, Float or most other significant numeric types) gives you a value of the desired type in the given range, as in theposZIntsBetween()
example above.- CommonGenerators.specificValue and CommonGenerators.specificValues create Generators that produce either one specific value every time, or one of several values randomly. This is useful for enumerations and types that behave like enumerations.
- CommonGenerators.evenly and CommonGenerators.frequency create higher-level Generators that call other Generators, either more or less equally or with a distribution you define.
Testing Your Own Types
Testing the built-in types isn't very interesting, though. Usually, you have your own types that you want to check the properties of. So let's build up an example piece by piece.
Say you have this simple type:
sealed trait Shape { def area: Double } case class Rectangle(width: Int, height: Int) extends Shape { require(width > 0) require(height > 0) def area: Double = width * height }
Let's confirm a nice straightforward property that is surely true: that the area is greater than zero:
"Rectangles" should "have a positive area" in { forAll { (w: PosInt, h: PosInt) => val rect = Rectangle(w, h) rect.area should be > 0.0 } }
Note that, even though our class takes ordinary Ints as parameters (and checks the values at runtime), it is actually easier to generate the legal values using Scalactic's PosInt type.
This should work, right? Actually, it doesn't -- if we run it a few times, we quickly hit an error!
[info] Rectangles [info] - should have a positive area *** FAILED *** [info] GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation. [info] (DocExamples.scala:42) [info] Falsified after 2 successful property evaluations. [info] Location: (DocExamples.scala:42) [info] Occurred when passed generated values ( [info] None = PosInt(399455539), [info] None = PosInt(703518968) [info] ) [info] Init Seed: 1568878346200
TODO: fix the above error to reflect the better errors we should get when we merge in the code being forward-ported from 3.0.5.
Looking at it, we can see that the numbers being used are pretty large. What happens when we multiply them together?
scala> 399455539 * 703518968 res0: Int = -2046258840
We're hitting an Int overflow problem here: the numbers are too big to multiply together and
still get an Int. So we have to fix our area
function:
case class Rectangle(width: Int, height: Int) extends Shape { require(width > 0) require(height > 0) def area: Double = width.toLong * height.toLong }
Now, when we run our property check, it consistently passes. Excellent -- we've caught a bug, because ScalaTest tried sufficiently large numbers.
Composing Your Own Generators
Doing things as shown above works, but having to generate the parameters and construct a
Rectangle
every time is a nuisance. What we really want is to create our own Generator
that just hands us Rectangles, the same way we can do for PosInt
. Fortunately, this
is easy.
Generators can be composed in for
comprehensions. So we can create our own Generator
for Rectangle like this:
implicit val rectGenerator = for { w <- posInts h <- posInts } yield Rectangle(w, h)
Taking that line by line:
w <- posInts
CommonGenerators.posInts is the built-in Generator for positive Ints. So this line puts
a randomly-generated positive Int in w
, and
h <- posInts
this line puts another one in h
. Finally, this line:
yield Rectangle(w, h)
combines w
and h
to make a Rectangle
.
That's pretty much all you need in order to build any normal case class
-- just build it
out of the Generators for the type of each field. (And if the fields are complex data
structures themselves, build Generators for them the same way, until you are just using
primitives.)
Now, our property check becomes simpler:
"Generated Rectangles" should "have a positive area" in { forAll { (rect: Rectangle) => rect.area should be > 0.0 } }
That's about as close to plain English as we can reasonably hope for!
Filtering Values with whenever()
Sometimes, not all of your generated values make sense for the property you want to check -- you know (via external information) that some of these values will never come up. In cases like this, you can create a custom Generator that only creates the values you do want, but it's often easier to just use Whenever.whenever. (Whenever is mixed into GeneratorDrivenPropertyChecks, so this is available when you need it.)
The Whenever.whenever function can be used inside of GeneratorDrivenPropertyChecks.forAll. It says that only the filtered values should be used, and anything else should be discarded. For example, look at this property:
"Fractions" should "get smaller when squared" in { forAll { (n: Float) => whenever(n > 0 && n < 1) { (n * n) should be < n } } }
We are testing a property of numbers less than 1, so we filter away everything that is not the numbers we want. This property check succeeds, because we've screened out the values that would make it fail.
Discard Limits
You shouldn't push Whenever.whenever too far, though. This system is all about trying random data, but if too much of the random data simply isn't usable, you can't get valid answers, and the system tracks that.
For example, consider this apparently-reasonable test:
"Space Chars" should "not also be letters" in { forAll { (c: Char) => whenever (c.isSpaceChar) { assert(!c.isLetter) } } }
Although the property is true, this test will fail with an error like this:
[info] Lowercase Chars [info] - should upper-case correctly *** FAILED *** [info] Gave up after 0 successful property evaluations. 49 evaluations were discarded. [info] Init Seed: 1568855247784
Because the vast majority of Chars are not spaces, nearly all of the generated values are being discarded. As a result, the system gives up after a while. In cases like this, you usually should write a custom Generator instead.
The proportion of how many discards to permit, relative to the number of successful checks, is configuration-controllable. See GeneratorDrivenPropertyChecks for more details.
Randomization
The point of Generator is to create pseudo-random values for checking properties. But it turns out to be very inconvenient if those values are actually random -- that would mean that, when a property check fails occasionally, you have no good way to invoke that specific set of circumstances again for debugging. We want "randomness", but we also want it to be deterministic, and reproducible when you need it.
To support this, all "randomness" in ScalaTest's property checking system uses the Randomizer class. You start by creating a Randomizer using an initial seed value, and call that to get your "random" value. Each call to a Randomizer function returns a new Randomizer, which you should use to fetch the next value.
GeneratorDrivenPropertyChecks.forAll uses Randomizer under the hood: each time
you run a forAll
-based test, it will automatically create a new Randomizer,
which by default is seeded based on the current system time. You can override this,
as discussed below.
Since Randomizer is actually deterministic (the "random" values are unobvious, but will always be the same given the same initial seed), this means that re-running a test with the same seed will produce the same values.
If you need random data for your own Generators and property checks, you should use Randomizer in the same way; that way, your tests will also be re-runnable, when needed for debugging.
Debugging, and Re-running a Failed Property Check
In Testing Your Own Types above, we found to our surprise that the property check failed with this error:
[info] Rectangles [info] - should have a positive area *** FAILED *** [info] GeneratorDrivenPropertyCheckFailedException was thrown during property evaluation. [info] (DocExamples.scala:42) [info] Falsified after 2 successful property evaluations. [info] Location: (DocExamples.scala:42) [info] Occurred when passed generated values ( [info] None = PosInt(399455539), [info] None = PosInt(703518968) [info] ) [info] Init Seed: 1568878346200
There must be a bug here -- but once we've fixed it, how can we make sure that we are re-testing exactly the same case that failed?
This is where the pseudo-random nature of Randomizer comes in, and why it is so important to use it consistently. So long as all of our "random" data comes from that, then all we need to do is re-run with the same seed.
That's why the Init Seed
shown in the message above is crucial. We can re-use that
seed -- and therefore get exactly the same "random" data -- by using the -S
flag to
ScalaTest.
So you can run this command in sbt to re-run exactly the same property check:
testOnly *DocExamples -- -z "have a positive area" -S 1568878346200
Taking that apart:
testOnly *DocExamples
says that we only want to run suites whose paths end withDocExamples
-z "have a positive area"
says to only run tests whose names include that string.-S 1568878346200
says to run all tests with a "random" seed of1568878346200
By combining these flags, you can re-run exactly the property check you need, with the right random seed to make sure you are re-creating the failed test. You should get exactly the same failure over and over until you fix the bug, and then you can confirm your fix with confidence.
Configuration
In general, forAll()
works well out of the box. But you can tune several configuration parameters
when needed. See GeneratorDrivenPropertyChecks for info on how to set
configuration parameters for your test.
Table-Driven Properties
Sometimes, you want something in between traditional hard-coded unit tests and Generator-driven, randomized tests. Instead, you sometimes want to check your properties against a specific set of inputs.
(This is particularly useful for regression tests, when you have found certain inputs that have caused problems in the past, and want to make sure that they get consistently re-tested.)
ScalaTest supports these, by mixing in TableDrivenPropertyChecks. See the documentation for that class for the full details.
- Source
- package.scala
- Grouped
- Alphabetic
- By Inheritance
- prop
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- trait Chooser[T] extends AnyRef
A simple one-method trait to allow you to pick values within a range.
A simple one-method trait to allow you to pick values within a range.
Quite often in test code, you need to pick a specific value for a given type within a range. This typeclass represents that notion. You can think of it as the generalization of functions in Randomizer such as
chooseChar
,chooseFloat
orchoosePosInt
. It is appropriate to use this typeclass when you are writing a function that needs this notion of "choosing", and works for multiple types.In principle, this typeclass makes sense for any ordered type with a finite number of values. However, it is a bit different from scala.math.Ordering in that it is specifically built around ScalaTest's Randomizer. This is not attempting to choose truly random values; it is choosing pseudo-random values via Randomizer, so that the results can be replayed for debugging if necessary. This is very important: all "randomness" in making the choice should come from the provided Randomizer.
This typeclass is used as the basis for CommonGenerators.between, so that you can use that function with your own types by creating an implicit instance of Chooser. (Note that such types will also requires instances of Generator and Ordering.)
- T
A type to choose a value of.
- case class Classification(totalGenerated: PosInt, totals: Map[String, PosZInt]) extends Product with Serializable
The results of a call to CommonGenerators.classify.
The results of a call to CommonGenerators.classify.
The
classify
function takes a PartialFunction and a Generator, and organizes the values created by the Generator based on the PartialFunction. It returns this data structure, which describes how many of the values went into each bucket.If the PartialFunction did not cover all the possible generated values, then the totals field will not include the others, and the numbers in totals will add up to less than totalGenerated.
- totalGenerated
How many values were actually created by the Generator overall.
- totals
For each of the buckets defined in the PartialFunction, how many values belonged in each one.
- trait CommonGenerators extends AnyRef
Provides various specialized Generators that are often useful.
Provides various specialized Generators that are often useful.
This exists as both a trait that you can mix into your classes, and an object that you can import -- choose whichever better suits your tests. However, you usually should not need to pull this in directly, since it is already mixed into both GeneratorDrivenPropertyChecks and TableDrivenPropertyChecks.
This incorporates the standard Generators defined in the Generator object, so you generally shouldn't need both.
- trait Configuration extends AnyRef
Trait providing methods and classes used to configure property checks provided by the the
forAll
methods of traitGeneratorDrivenPropertyChecks
(for ScalaTest-style property checks) and thecheck
methods of traitCheckers
(for ScalaCheck-style property checks). - trait Generator[T] extends AnyRef
Base type for all Generators.
Base type for all Generators.
A Generator produces a stream of values of a particular type. This is usually a mix of randomly-created values (generally built using a Randomizer), as well as some well-known edge cases that tend to cause bugs in real-world code.
For example, consider an intGenerator that produces a sequence of Ints. Some of these will be taken from Randomizer.nextInt, which may result in any possible Int, so the values will be a very random mix of numbers. But it will also produce the known edge cases of Int:
- Int.MinValue, the smallest possible Int
- Int.MaxValue, the largest possible Int
- -1
- 0
- 1
The list of appropriate edge cases will vary from type to type, but they should be chosen so as to exercise the type broadly, and at extremes.
Creating Your Own Generators
Generator.intGenerator, and Generators for many other basic types, are already built into the system, so you can just use them. You can (and should) define Generators for your own types, as well.
In most cases, you do not need to write Generators from scratch -- Generators for most non-primitive types can be composed using for comprehensions, as described in the section Composing Your Own Generators in the documentation for the org.scalatest.prop pacakge. You can also often create them using the CommonGenerators.instancesOf method. You should only need to write a Generator from scratch for relatively primitive types, that aren't composed of other types.
If you decide that you do need to build a Generator from scratch, here is a rough outline of how to go about it.
First, look at the source code for some of the Generators in the Generator companion object. These follow a pretty standard pattern, that you will likely want to follow.
Size
Your Generator may optionally have a concept of size. What this means varies from type to type: for a String it might be the number of characters, whereas for a List it might be the number of elements. The test system will try using the Generator with a variety of sizes; you can control the maximum and minimum sizes via Configuration.
Decide whether the concept of size is relevant for your type. If it is relevant, you should mix the HavingSize or HavingLength trait into your Generator, and you'll want to take it into account in your
next
andshrink
functions.Randomization
The Generator should do all of its "random" data generation using the Randomizer instance passed in to it, and should return the next Randomizer with its results. Randomizer produces intentionally pseudo-random data: it looks reasonably random, but is actually entirely deterministic based on the seed used to initialize it. By consistently using Randomizer, the Generator can be re-run, producing the same values, when given an identically-seeded Randomizer. This can often make debugging much easier, since it allows you to reproduce your "random" failures.
So figure out how to create a pseudo-random value of your type using Randomizer. This will likely involve writing a function similar to the various
nextT()
functions inside of Randomizer itself.next()
Using this randomization function, write a first draft of your Generator, filling in the
next()
method. This is the only required method, and should suffice to start playing with your Generator. Once this is working, you have a useful Generator.Edges
The edges are the edge cases for this type. You may have as many or as few edge cases as seem appropriate, but most types involve at least a few. Edges are generally values that are particularly big/full, or particularly small/empty. The test system will prioritize applying the edge cases to the property, since they are assumed to be the values most likely to cause failures.
Figure out some appropriate edge cases for your type. Override
initEdges()
to return those, and enhancenext()
to produce them ahead of the random values. Identifying these will tend to make your property checks more effective, by catching these edge cases early.Canonicals
Now figure out some canonical values for your type -- a few common, ordinary values that are frequently worth testing. These will be used when shrinking your type in higher-order Generators, so it is helpful to have some. Override the
canonicals()
method to return these.Canonicals should always be in order from "smallest" to less-small, in the shrinking sense. This is not the same thing as starting with the lowest number, though! For example, the canonicals for Generator.byteGenerator are:
private val byteCanonicals: List[Byte] = List(0, 1, -1, 2, -2, 3, -3)
Zero is "smallest" -- the most-shrunk Byte.
Shrinking
Optionally but preferably, your Generator can have a concept of shrinking. This starts with a value that is known to cause the property evaluation to fail, and produces a list of smaller/simpler values, to see if those also fail. So for example, if a String of length 15 causes a failure, its Generator could try Strings of length 3, and then 1, and then 0, to see if those also cause failure.
You to not have to implement the Generator.shrink method, but it is helpful to do so when it makes sense; the test system will use that to produce smaller, easier-to-debug examples when something fails.
One important rule: the values returned from
shrink
must always be smaller than -- not equal to -- the values passed in. Otherwise, an infinite loop can result. Also, similar to Canonicals, the "smallest" values should be returned at the front of this Iterator, with less-small values later.- T
the type that this Generator produces
- trait GeneratorDrivenPropertyChecks extends CommonGenerators with Whenever with Configuration
Trait containing methods that faciliate property checks against generated data using Generator.
Trait containing methods that faciliate property checks against generated data using Generator.
This trait contains
forAll
methods that provide various ways to check properties using generated data. It also contains awherever
method that can be used to indicate a property need only hold whenever some condition is true.For an example of trait
GeneratorDrivenPropertyChecks
in action, imagine you want to test thisFraction
class:class Fraction(n: Int, d: Int) { require(d != 0) require(d != Integer.MIN_VALUE) require(n != Integer.MIN_VALUE) val numer = if (d < 0) -1 * n else n val denom = d.abs override def toString = numer + " / " + denom }
To test the behavior of
Fraction
, you could mix in or import the members ofGeneratorDrivenPropertyChecks
(andMatchers
) and check a property using aforAll
method, like this:forAll { (n: Int, d: Int) => whenever (d != 0 && d != Integer.MIN_VALUE && n != Integer.MIN_VALUE) { val f = new Fraction(n, d) if (n < 0 && d < 0 || n > 0 && d > 0) f.numer should be > 0 else if (n != 0) f.numer should be < 0 else f.numer should be === 0 f.denom should be > 0 } }
Trait
GeneratorDrivenPropertyChecks
provides overloadedforAll
methods that allow you to check properties using the data provided by Generator. The simplest form offorAll
method takes two parameter lists, the second of which is implicit. The first parameter list is a "property" function with one to six parameters. An implicit Generator generator object needs to be supplied for. TheforAll
method will pass each row of data to each parameter type. ScalaTest provides many implicit Generators for common types such asInt
,String
,List[Float]
, etc., in its Generator companion object. So long as you use types for which ScalaTest already provides implicit Generators, you needn't worry about them. Most often you can simply pass a property function toforAll
, and the compiler will grab the implicit values provided by ScalaTest.The
forAll
methods use the supplied Generators to generate example arguments and pass them to the property function, and generate aGeneratorDrivenPropertyCheckFailedException
if the function completes abruptly for any exception that would normally cause a test to fail in ScalaTest other thanDiscardedEvaluationException
. AnDiscardedEvaluationException
, which is thrown by thewhenever
method (defined in trait Whenever, which this trait extends) to indicate a condition required by the property function is not met by a row of passed data, will simply causeforAll
to discard that row of data.Supplying argument names
You can optionally specify string names for the arguments passed to a property function, which will be used in any error message when describing the argument values that caused the failure. To supply the names, place them in a comma separated list in parentheses after
forAll
before the property function (a curried form offorAll
). Here's an example:forAll ("a", "b") { (a: String, b: String) => a.length + b.length should equal ((a + b).length + 1) // Should fail }
When this fails, you'll see an error message that includes this:
Occurred when passed generated values ( a = "", b = "" )
When you don't supply argument names, the error message will say
arg0
,arg1
, etc.. For example, this property check:forAll { (a: String, b: String) => a.length + b.length should equal ((a + b).length + 1) // Should fail }
Will fail with an error message that includes:
Occurred when passed generated values ( arg0 = "", arg1 = "" )
Supplying generators
ScalaTest provides a nice library of compositors that makes it easy to create your own custom generators. If you want to supply custom generators to a property check, place them in parentheses after
forAll
, before the property check function (a curried form offorAll
).For example, to create a generator of even integers between (and including) -2000 and 2000, you could write this:
import org.scalatest.prop.Generator val evenInts = for (n <- Generator.chooseInt(-1000, 1000)) yield 2 * n
Given this generator, you could use it on a property check like this:
forAll (evenInts) { (n) => n % 2 should equal (0) }
Custom generators are necessary when you want to pass data types not supported by ScalaTest's Generators, but are also useful when some of the values in the full range for the passed types are not valid. For such values you would use a
whenever
clause. In theFraction
class shown above, neither the passed numerator or denominator can beInteger.MIN_VALUE
, and the passed denominator cannot be zero. This shows up in thewhenever
clause like this:whenever (d != 0 && d != Integer.MIN_VALUE && n != Integer.MIN_VALUE) { ...
You could in addition define generators for the numerator and denominator that only produce valid values, like this:
val validNumers = for (n <- Generator.chooseInt(Integer.MIN_VALUE + 1, Integer.MAX_VALUE)) yield n val validDenoms = for (d <- validNumers if d != 0) yield d
You could then use them in the property check like this:
forAll (validNumers, validDenoms) { (n: Int, d: Int) => whenever (d != 0 && d != Integer.MIN_VALUE && n != Integer.MIN_VALUE) { val f = new Fraction(n, d) if (n < 0 && d < 0 || n > 0 && d > 0) f.numer should be > 0 else if (n != 0) f.numer should be < 0 else f.numer should be === 0 f.denom should be > 0 } }
Supplying both generators and argument names
If you want to supply both generators and named arguments, you can do so by providing a list of
(<generator>, <name>)
pairs in parentheses afterforAll
, before the property function. Here's an example:forAll ((validNumers, "n"), (validDenoms, "d")) { (n: Int, d: Int) => whenever (d != 0 && d != Integer.MIN_VALUE && n != Integer.MIN_VALUE) { val f = new Fraction(n, d) if (n < 0 && d < 0 || n > 0 && d > 0) f.numer should be > 0 else if (n != 0) f.numer should be < 0 else f.numer should be === 0 f.denom should be > 0 } }
Were this property check to fail, it would mention the names n and d in the error message, like this:
Occurred when passed generated values ( n = 17, d = 21 )
Property check configuration
The property checks performed by the
forAll
methods of this trait can be flexibly configured via the services provided by supertraitConfiguration
. The five configuration parameters for property checks along with their default values and meanings are described in the following table:Configuration Parameter Default Value Meaning minSuccessful 100 the minimum number of successful property evaluations required for the property to pass maxDiscarded 500 the maximum number of discarded property evaluations allowed during a property check minSize 0 the minimum size parameter to provide to ScalaCheck, which it will use when generating objects for which size matters (such as strings or lists) sizeRange 100 the size range parameter to provide to ScalaCheck, which it will use when generating objects for which size matters (such as strings or lists) workers 1 specifies the number of worker threads to use during property evaluation The
forAll
methods of traitGeneratorDrivenPropertyChecks
each take aPropertyCheckConfiguration
object as an implicit parameter. This object provides values for each of the five configuration parameters. TraitConfiguration
provides an implicitval
namedgeneratorDrivenConfig
with each configuration parameter set to its default value. If you want to set one or more configuration parameters to a different value for all property checks in a suite you can override this val (or hide it, for example, if you are importing the members of theGeneratorDrivenPropertyChecks
companion object rather than mixing in the trait.) For example, if you want all parameters at their defaults except forminSize
andsizeRange
, you can overridegeneratorDrivenConfig
, like this:implicit override val generatorDrivenConfig = PropertyCheckConfiguration(minSize = 10, sizeRange = 10)
Or, hide it by declaring a variable of the same name in whatever scope you want the changed values to be in effect:
implicit val generatorDrivenConfig = PropertyCheckConfiguration(minSize = 10, sizeRange = 10)
In addition to taking a
PropertyCheckConfiguration
object as an implicit parameter, theforAll
methods of traitGeneratorDrivenPropertyChecks
also take a variable length argument list ofPropertyCheckConfigParam
objects that you can use to override the values provided by the implicitPropertyCheckConfiguration
for a singleforAll
invocation. For example, if you want to setminSuccessful
to 500 for just one particularforAll
invocation, you can do so like this:forAll (minSuccessful(500)) { (n: Int, d: Int) => ...
This invocation of
forAll
will use 500 forminSuccessful
and whatever values are specified by the implicitly passedPropertyCheckConfiguration
object for the other configuration parameters. If you want to set multiple configuration parameters in this way, just list them separated by commas:forAll (minSuccessful(500), maxDiscardedFactor(0.6)) { (n: Int, d: Int) => ...
If you are using an overloaded form of
forAll
that already takes an initial parameter list, just add the configuration parameters after the list of generators, names, or generator/name pairs, as in:// If providing argument names forAll ("n", "d", minSuccessful(500), maxDiscardedFactor(0.6)) { (n: Int, d: Int) => ... // If providing generators forAll (validNumers, validDenoms, minSuccessful(500), maxDiscardedFactor(0.6)) { (n: Int, d: Int) => ... // If providing (<generators>, <name>) pairs forAll ((validNumers, "n"), (validDenoms, "d"), minSuccessful(500), maxDiscardedFactor(0.6)) { (n: Int, d: Int) => ...
For more information, see the documentation for supertrait
Configuration
. - trait HavingLength[T] extends HavingSize[T]
This trait is mixed in to Generators that have a well-defined notion of "length".
This trait is mixed in to Generators that have a well-defined notion of "length".
Broadly speaking, this applies when T is a type that has a
length
method. For example, Generator.listGenerator (also known as CommonGenerators.lists) has the HavingLength trait because List has alength
method.Generators with this trait provide several functions that allow you to create more-specialized Generators, with specific length bounds.
Note that this trait extends HavingSize, and is quite similar to it, reflecting the relationship between the
length
andsize
methods in many standard library types. The functions in here are basically just a shell around those in HavingSize.- T
the type that this Generator produces
- trait HavingSize[T] extends AnyRef
This trait is mixed in to Generators that have a well-defined notion of "size".
This trait is mixed in to Generators that have a well-defined notion of "size".
Broadly speaking, this applies when T is a type that has a
size
method. For example, Generator.setGenerator (also known as CommonGenerators.sets) has the HavingSize trait because Set has asize
method.Generators with this trait provide several functions that allow you to create more-specialized Generators, with specific size bounds.
- T
the type that this Generator produces
- class PrettyFunction0[A] extends () => A
A nullary (zero-parameter) "function" that is a bit friendlier to testing.
A nullary (zero-parameter) "function" that is a bit friendlier to testing.
This is a variant of
() => A
-- that is, a function that takes no parameters and returns an A. In practice, that isn't quite true: where() => A
is lazy (it is not evaluated until you call it), this one is strict (you pass the result in as a parameter).In exchange, this is more usable and reproducible for test environments. Its
hashCode
andequals
are based on those of the passed-in value (so they are consistent and reproducible), and itstoString
nicely displays the result that will always be returned.- A
the type that is returned by this function
- case class PropertyArgument(label: Option[String], value: Any) extends Product with Serializable
Describes one argument passed in to a check.
Describes one argument passed in to a check.
This is returned as part of PropertyCheckResult, so that you can find out what arguments were passed in to the check.
- label
The label provided for that argument, if any.
- value
The value of the argument.
- sealed trait PropertyCheckResult extends AnyRef
Describes the outcome of a Property Check operation such as 'forAll()'.
Describes the outcome of a Property Check operation such as 'forAll()'.
This will always be one of three subtypes: org.scalatest.prop.PropertyCheckResult.Success, org.scalatest.prop.PropertyCheckResult.Exhausted, or org.scalatest.prop.PropertyCheckResult.Failure. See those subclasses for details on what each one means.
- trait PropertyChecks extends TableDrivenPropertyChecks with GeneratorDrivenPropertyChecks
Trait that facilitates property checks on data supplied by tables and generators.
Trait that facilitates property checks on data supplied by tables and generators.
This trait extends both
TableDrivenPropertyChecks
andGeneratorDrivenPropertyChecks
. Thus by mixing in this trait you can perform property checks on data supplied either by tables or generators. For the details of table- and generator-driven property checks, see the documentation for each by following the links above.For a quick example of using both table and generator-driven property checks in the same suite of tests, however, imagine you want to test this
Fraction
class:class Fraction(n: Int, d: Int) { require(d != 0) require(d != Integer.MIN_VALUE) require(n != Integer.MIN_VALUE) val numer = if (d < 0) -1 * n else n val denom = d.abs override def toString = numer + " / " + denom }
If you mix in
PropertyChecks
, you could use a generator-driven property check to test that the passed values for numerator and denominator are properly normalized, like this:forAll { (n: Int, d: Int) => whenever (d != 0 && d != Integer.MIN_VALUE && n != Integer.MIN_VALUE) { val f = new Fraction(n, d) if (n < 0 && d < 0 || n > 0 && d > 0) f.numer should be > 0 else if (n != 0) f.numer should be < 0 else f.numer shouldEqual 0 f.denom should be > 0 } }
And you could use a table-driven property check to test that all combinations of invalid values passed to the
Fraction
constructor produce the expectedIllegalArgumentException
, like this:val invalidCombos = Table( ("n", "d"), (Integer.MIN_VALUE, Integer.MIN_VALUE), (1, Integer.MIN_VALUE), (Integer.MIN_VALUE, 1), (Integer.MIN_VALUE, 0), (1, 0) ) forAll (invalidCombos) { (n: Int, d: Int) => an [IllegalArgumentException] should be thrownBy { new Fraction(n, d) } }
- class Randomizer extends AnyRef
Provide random values, of many different types.
Provide random values, of many different types.
This is loosely inspired by java.util.Random (and is designed to produce the same values in conventional cases), with two major differences:
- It provides random values for many more types;
- In proper Scala fashion, this class is immutable.
On the first of those points, this returns many data types, including many of the tightly-defined numeric types from Scalactic. These allow you to put tight constraints on precisely what numbers you want to have available -- positive, negative, zeroes, infinities and so on. We strongly recommend that you use the function that most exactly describes the values you are looking for.
That second point is the more important one. You shouldn't call the same Randomizer over and over, the way you would do in Java. Instead, each call to a Randomizer function returns the next Randomizer, which you should use for the next call.
If you are using random floating-point values: the algorithms in use here produce random values across the potential space of values. But due to the way floating-point works, this means that these values are strongly biased towards small numbers. There are many floating-point numbers with negative exponents, so you may get more numbers in the range between -1 and 1 than you expect.
- case class SizeParam(minSize: PosZInt, sizeRange: PosZInt, size: PosZInt) extends Product with Serializable
Describes the "size" to use in order to generate a value.
Describes the "size" to use in order to generate a value.
The Generator.next() function takes a
SizeParam
as a parameter, and uses it if it is relevant to this Generator.The semantics of "size" depend on the Generator and the type it is producing. For a simple scalar such as an Int or a Float, "size" is irrelevant, and the parameter is ignored. For a String, the "size" is the length of the desired
String
. For a List, the "size" is the length of the desiredList
. And so on -- in general, the meaning of "size" is usually pretty intuitive.The SizeParam data structure represents both a target size range and a specific size.
The
minSize
member says the smallest allowed size; thesizeRange
is added tominSize
to get the largest allowed size. So ifminSize
is 10 andsizeRange
is 0, that means that 10 is the only size desired; ifminSize
is 10 andsizeRange
is 10, then values from 10 to 20 are desired.The
size
member gives the desired size for this particular invocation of Generator.next(). Most Generators will create a result of that size. However, it is up to the individual Generator to choose how it interprets SizeParam.You should not usually need to create a SizeParam directly -- most of the time, you should be able to use the HavingSize or HavingLength traits to describe the desired sizes of your Generators. You may occasionally need to manipulate SizeParam directly if you want to use HavingSize.havingSizesDeterminedBy(), or if you want to call Generator.next() directly.
- trait TableDrivenPropertyChecks extends Whenever with Tables
Trait containing methods that faciliate property checks against tables of data.
Trait containing methods that faciliate property checks against tables of data.
This trait contains one
exists
,forAll
, andforEvery
method for eachTableForN
class,TableFor1
throughTableFor22
, which allow properties to be checked against the rows of a table. It also contains awhenever
method that can be used to indicate a property need only hold whenever some condition is true.For an example of trait
TableDrivenPropertyChecks
in action, imagine you want to test thisFraction
class:class Fraction(n: Int, d: Int) { require(d != 0) require(d != Integer.MIN_VALUE) require(n != Integer.MIN_VALUE) val numer = if (d < 0) -1 * n else n val denom = d.abs override def toString = numer + " / " + denom }
TableDrivenPropertyChecks
allows you to create tables with between 1 and 22 columns and any number of rows. You create a table by passing tuples to one of the factory methods of objectTable
. Each tuple must have the same arity (number of members). The first tuple you pass must all be strings, because it defines names for the columns. Subsequent tuples define the data. After the initial tuple that contains string column names, all tuples must have the same type. For example, if the first tuple after the column names contains twoInt
s, all subsequent tuples must contain twoInt
(i.e., have typeTuple2[Int, Int]
).To test the behavior of
Fraction
, you could create a table of numerators and denominators to pass to the constructor of theFraction
class using one of theapply
factory methods declared inTable
, like this:import org.scalatest.prop.TableDrivenPropertyChecks._ val fractions = Table( ("n", "d"), // First tuple defines column names ( 1, 2), // Subsequent tuples define the data ( -1, 2), ( 1, -2), ( -1, -2), ( 3, 1), ( -3, 1), ( -3, 0), ( 3, -1), ( 3, Integer.MIN_VALUE), (Integer.MIN_VALUE, 3), ( -3, -1) )
You could then check a property against each row of the table using a
forAll
method, like this:import org.scalatest.Matchers._ forAll (fractions) { (n: Int, d: Int) => whenever (d != 0 && d != Integer.MIN_VALUE && n != Integer.MIN_VALUE) { val f = new Fraction(n, d) if (n < 0 && d < 0 || n > 0 && d > 0) f.numer should be > 0 else if (n != 0) f.numer should be < 0 else f.numer should be === 0 f.denom should be > 0 } }
Trait
TableDrivenPropertyChecks
provides 22 overloadedexists
,forAll
, andforEvery
methods that allow you to check properties using the data provided by a table. Eachexists
,forAll
, andforEvery
method takes two parameter lists. The first parameter list is a table. The second parameter list is a function whose argument types and number matches that of the tuples in the table. For example, if the tuples in the table supplied toforAll
each contain anInt
, aString
, and aList[Char]
, then the function supplied toforAll
must take 3 parameters, anInt
, aString
, and aList[Char]
. TheforAll
method will pass each row of data to the function, and generate aTableDrivenPropertyCheckFailedException
if the function completes abruptly for any row of data with any exception that would normally cause a test to fail in ScalaTest other thanDiscardedEvaluationException
. ADiscardedEvaluationException
, which is thrown by thewhenever
method (also defined in this trait) to indicate a condition required by the property function is not met by a row of passed data, will simply causeforAll
to skip that row of data.The full list of table methods are:
exists
- succeeds if the assertion holds true for at least one elementforAll
- succeeds if the assertion holds true for every elementforEvery
- same asforAll
, but lists all failing elements if it fails (whereasforAll
just reports the first failing element) and throwsTestFailedException
with the first failed check as the cause.
Testing stateful functions
One way to use a table with one column is to test subsequent return values of a stateful function. Imagine, for example, you had an object named
FiboGen
whosenext
method returned the next fibonacci number, where next means the next number in the series following the number previously returned bynext
. So the first timenext
was called, it would return 0. The next time it was called it would return 1. Then 1. Then 2. Then 3, and so on.FiboGen
would need to maintain state, because it has to remember where it is in the series. In such a situation, you could create aTableFor1
(a table with one column, which you could alternatively think of as one row), in which each row represents the next value you expect.val first14FiboNums = Table("n", 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233)
Then in your
forAll
simply call the function and compare it with the expected return value, like this:forAll (first14FiboNums) { n => FiboGen.next should equal (n) }
Testing mutable objects
If you need to test a mutable object, one way you can use tables is to specify state transitions in a table. For example, imagine you wanted to test this mutable
Counter
class:class Counter { private var c = 0 def reset() { c = 0 } def click() { c += 1 } def enter(n: Int) { c = n } def count = c }
A
Counter
keeps track of how many times itsclick
method is called. The count starts out at zero and increments with eachclick
invocation. You can also set the count to a specific value by callingenter
and passing the value in. And thereset
method returns the count back to zero. You could define the actions that initiate state transitions with case classes, like this:abstract class Action case object Start extends Action case object Click extends Action case class Enter(n: Int) extends Action
Given these actions, you could define a state-transition table like this:
val stateTransitions = Table( ("action", "expectedCount"), (Start, 0), (Click, 1), (Click, 2), (Click, 3), (Enter(5), 5), (Click, 6), (Enter(1), 1), (Click, 2), (Click, 3) )
To use this in a test, simply do a pattern match inside the function you pass to
forAll
. Make a pattern for each action, and have the body perform that action when there's a match. Then check that the actual value equals the expected value:val counter = new Counter forAll (stateTransitions) { (action, expectedCount) => action match { case Start => counter.reset() case Click => counter.click() case Enter(n) => counter.enter(n) } counter.count should equal (expectedCount) }
Testing invalid argument combinations
A table-driven property check can also be helpful to ensure that the proper exception is thrown when invalid data is passed to a method or constructor. For example, the
Fraction
constructor shown above should throwIllegalArgumentException
ifInteger.MIN_VALUE
is passed for either the numerator or denominator, or zero is passed for the denominator. This yields the following five combinations of invalid data:n
d
Integer.MIN_VALUE
Integer.MIN_VALUE
a valid value Integer.MIN_VALUE
Integer.MIN_VALUE
a valid value Integer.MIN_VALUE
zero a valid value zero You can express these combinations in a table:
val invalidCombos = Table( ("n", "d"), (Integer.MIN_VALUE, Integer.MIN_VALUE), (1, Integer.MIN_VALUE), (Integer.MIN_VALUE, 1), (Integer.MIN_VALUE, 0), (1, 0) )
Given this table, you could check that all invalid combinations produce
IllegalArgumentException
, like this:forAll (invalidCombos) { (n: Int, d: Int) => evaluating { new Fraction(n, d) } should produce [IllegalArgumentException] }
- class TableFor1[A] extends IndexedSeq[A] with IndexedSeqOps[A, IndexedSeq, IndexedSeq[A]]
A table with 1 column.
A table with 1 column.
For an overview of using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of objects, where each object represents one row of the (one-column) table. This table also carries with it a heading tuple that gives a string name to the lone column of the table.
A handy way to create a
TableFor1
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( "a", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 )
Because you supplied a list of non-tuple objects, the type you'll get back will be a
TableFor1
.The table provides an
apply
method that takes a function with a parameter list that matches the type of the objects contained in this table. Theapply
method will invoke the function with the object in each row passed as the lone argument, in ascending order by index. (I.e., the zeroth object is checked first, then the object with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor1
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor1
, passing in the property check function. Here's an example:forAll (examples) { (a) => a should equal (a * 1) }
Because
TableFor1
is aSeq[(A)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
One other way to use a
TableFor1
is to test subsequent return values of a stateful function. Imagine, for example, you had an object namedFiboGen
whosenext
method returned the next fibonacci number, where next means the next number in the series following the number previously returned bynext
. So the first timenext
was called, it would return 0. The next time it was called it would return 1. Then 1. Then 2. Then 3, and so on.FiboGen
would need to be stateful, because it has to remember where it is in the series. In such a situation, you could create aTableFor1
(a table with one column, which you could alternatively think of as one row), in which each row represents the next value you expect.val first14FiboNums = Table("n", 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233)
Then in your
forAll
simply call the function and compare it with the expected return value, like this:forAll (first14FiboNums) { n => FiboGen.next should equal (n) }
- class TableFor10[A, B, C, D, E, F, G, H, I, J] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J)]]
A table with 10 columns.
A table with 10 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple10
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor10
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 10 members in each tuple, the type you'll get back will be a
TableFor10
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor10
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor10
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j) => a + b + c + d + e + f + g + h + i + j should equal (a * 10) }
Because
TableFor10
is aSeq[(A, B, C, D, E, F, G, H, I, J)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor11[A, B, C, D, E, F, G, H, I, J, K] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K)]]
A table with 11 columns.
A table with 11 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple11
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor11
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 11 members in each tuple, the type you'll get back will be a
TableFor11
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor11
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor11
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k) => a + b + c + d + e + f + g + h + i + j + k should equal (a * 11) }
Because
TableFor11
is aSeq[(A, B, C, D, E, F, G, H, I, J, K)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor12[A, B, C, D, E, F, G, H, I, J, K, L] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L)]]
A table with 12 columns.
A table with 12 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple12
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor12
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 12 members in each tuple, the type you'll get back will be a
TableFor12
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor12
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor12
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l) => a + b + c + d + e + f + g + h + i + j + k + l should equal (a * 12) }
Because
TableFor12
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor13[A, B, C, D, E, F, G, H, I, J, K, L, M] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M)]]
A table with 13 columns.
A table with 13 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple13
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor13
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 13 members in each tuple, the type you'll get back will be a
TableFor13
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor13
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor13
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m) => a + b + c + d + e + f + g + h + i + j + k + l + m should equal (a * 13) }
Because
TableFor13
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor14[A, B, C, D, E, F, G, H, I, J, K, L, M, N] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M, N), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N)]]
A table with 14 columns.
A table with 14 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple14
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor14
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 14 members in each tuple, the type you'll get back will be a
TableFor14
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor14
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor14
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m, n) => a + b + c + d + e + f + g + h + i + j + k + l + m + n should equal (a * 14) }
Because
TableFor14
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor15[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)]]
A table with 15 columns.
A table with 15 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple15
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor15
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 15 members in each tuple, the type you'll get back will be a
TableFor15
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor15
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor15
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) => a + b + c + d + e + f + g + h + i + j + k + l + m + n + o should equal (a * 15) }
Because
TableFor15
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor16[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)]]
A table with 16 columns.
A table with 16 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple16
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor16
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 16 members in each tuple, the type you'll get back will be a
TableFor16
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor16
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor16
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) => a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p should equal (a * 16) }
Because
TableFor16
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor17[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)]]
A table with 17 columns.
A table with 17 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple17
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor17
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 17 members in each tuple, the type you'll get back will be a
TableFor17
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor17
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor17
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) => a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q should equal (a * 17) }
Because
TableFor17
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor18[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)]]
A table with 18 columns.
A table with 18 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple18
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor18
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 18 members in each tuple, the type you'll get back will be a
TableFor18
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor18
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor18
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) => a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r should equal (a * 18) }
Because
TableFor18
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor19[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)]]
A table with 19 columns.
A table with 19 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple19
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor19
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 19 members in each tuple, the type you'll get back will be a
TableFor19
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor19
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor19
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) => a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s should equal (a * 19) }
Because
TableFor19
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor2[A, B] extends IndexedSeq[(A, B)] with IndexedSeqOps[(A, B), IndexedSeq, IndexedSeq[(A, B)]]
A table with 2 columns.
A table with 2 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple2
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor2
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b"), ( 0, 0), ( 1, 1), ( 2, 2), ( 3, 3), ( 4, 4), ( 5, 5), ( 6, 6), ( 7, 7), ( 8, 8), ( 9, 9) )
Because you supplied 2 members in each tuple, the type you'll get back will be a
TableFor2
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor2
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor2
, passing in the property check function. Here's an example:forAll (examples) { (a, b) => a + b should equal (a * 2) }
Because
TableFor2
is aSeq[(A, B)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor20[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)]]
A table with 20 columns.
A table with 20 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple20
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor20
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 20 members in each tuple, the type you'll get back will be a
TableFor20
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor20
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor20
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) => a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s + t should equal (a * 20) }
Because
TableFor20
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor21[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)]]
A table with 21 columns.
A table with 21 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple21
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor21
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 21 members in each tuple, the type you'll get back will be a
TableFor21
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor21
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor21
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) => a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s + t + u should equal (a * 21) }
Because
TableFor21
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor22[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V] extends IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)]]
A table with 22 columns.
A table with 22 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple22
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor22
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 22 members in each tuple, the type you'll get back will be a
TableFor22
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor22
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor22
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) => a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s + t + u + v should equal (a * 22) }
Because
TableFor22
is aSeq[(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor3[A, B, C] extends IndexedSeq[(A, B, C)] with IndexedSeqOps[(A, B, C), IndexedSeq, IndexedSeq[(A, B, C)]]
A table with 3 columns.
A table with 3 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple3
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor3
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c"), ( 0, 0, 0), ( 1, 1, 1), ( 2, 2, 2), ( 3, 3, 3), ( 4, 4, 4), ( 5, 5, 5), ( 6, 6, 6), ( 7, 7, 7), ( 8, 8, 8), ( 9, 9, 9) )
Because you supplied 3 members in each tuple, the type you'll get back will be a
TableFor3
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor3
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor3
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c) => a + b + c should equal (a * 3) }
Because
TableFor3
is aSeq[(A, B, C)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor4[A, B, C, D] extends IndexedSeq[(A, B, C, D)] with IndexedSeqOps[(A, B, C, D), IndexedSeq, IndexedSeq[(A, B, C, D)]]
A table with 4 columns.
A table with 4 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple4
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor4
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d"), ( 0, 0, 0, 0), ( 1, 1, 1, 1), ( 2, 2, 2, 2), ( 3, 3, 3, 3), ( 4, 4, 4, 4), ( 5, 5, 5, 5), ( 6, 6, 6, 6), ( 7, 7, 7, 7), ( 8, 8, 8, 8), ( 9, 9, 9, 9) )
Because you supplied 4 members in each tuple, the type you'll get back will be a
TableFor4
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor4
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor4
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d) => a + b + c + d should equal (a * 4) }
Because
TableFor4
is aSeq[(A, B, C, D)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor5[A, B, C, D, E] extends IndexedSeq[(A, B, C, D, E)] with IndexedSeqOps[(A, B, C, D, E), IndexedSeq, IndexedSeq[(A, B, C, D, E)]]
A table with 5 columns.
A table with 5 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple5
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor5
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e"), ( 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9) )
Because you supplied 5 members in each tuple, the type you'll get back will be a
TableFor5
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor5
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor5
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e) => a + b + c + d + e should equal (a * 5) }
Because
TableFor5
is aSeq[(A, B, C, D, E)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor6[A, B, C, D, E, F] extends IndexedSeq[(A, B, C, D, E, F)] with IndexedSeqOps[(A, B, C, D, E, F), IndexedSeq, IndexedSeq[(A, B, C, D, E, F)]]
A table with 6 columns.
A table with 6 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple6
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor6
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f"), ( 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9) )
Because you supplied 6 members in each tuple, the type you'll get back will be a
TableFor6
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor6
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor6
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f) => a + b + c + d + e + f should equal (a * 6) }
Because
TableFor6
is aSeq[(A, B, C, D, E, F)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor7[A, B, C, D, E, F, G] extends IndexedSeq[(A, B, C, D, E, F, G)] with IndexedSeqOps[(A, B, C, D, E, F, G), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G)]]
A table with 7 columns.
A table with 7 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple7
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor7
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g"), ( 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 7 members in each tuple, the type you'll get back will be a
TableFor7
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor7
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor7
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g) => a + b + c + d + e + f + g should equal (a * 7) }
Because
TableFor7
is aSeq[(A, B, C, D, E, F, G)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor8[A, B, C, D, E, F, G, H] extends IndexedSeq[(A, B, C, D, E, F, G, H)] with IndexedSeqOps[(A, B, C, D, E, F, G, H), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H)]]
A table with 8 columns.
A table with 8 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple8
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor8
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h"), ( 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 8 members in each tuple, the type you'll get back will be a
TableFor8
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor8
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor8
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h) => a + b + c + d + e + f + g + h should equal (a * 8) }
Because
TableFor8
is aSeq[(A, B, C, D, E, F, G, H)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- class TableFor9[A, B, C, D, E, F, G, H, I] extends IndexedSeq[(A, B, C, D, E, F, G, H, I)] with IndexedSeqOps[(A, B, C, D, E, F, G, H, I), IndexedSeq, IndexedSeq[(A, B, C, D, E, F, G, H, I)]]
A table with 9 columns.
A table with 9 columns.
For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
This table is a sequence of
Tuple9
objects, where each tuple represents one row of the table. The first element of each tuple comprise the first column of the table, the second element of each tuple comprise the second column, and so on. This table also carries with it a heading tuple that gives string names to the columns of the table.A handy way to create a
TableFor9
is via anapply
factory method in theTable
singleton object provided by theTables
trait. Here's an example:val examples = Table( ("a", "b", "c", "d", "e", "f", "g", "h", "i"), ( 0, 0, 0, 0, 0, 0, 0, 0, 0), ( 1, 1, 1, 1, 1, 1, 1, 1, 1), ( 2, 2, 2, 2, 2, 2, 2, 2, 2), ( 3, 3, 3, 3, 3, 3, 3, 3, 3), ( 4, 4, 4, 4, 4, 4, 4, 4, 4), ( 5, 5, 5, 5, 5, 5, 5, 5, 5), ( 6, 6, 6, 6, 6, 6, 6, 6, 6), ( 7, 7, 7, 7, 7, 7, 7, 7, 7), ( 8, 8, 8, 8, 8, 8, 8, 8, 8), ( 9, 9, 9, 9, 9, 9, 9, 9, 9) )
Because you supplied 9 members in each tuple, the type you'll get back will be a
TableFor9
.The table provides an
apply
method that takes a function with a parameter list that matches the types and arity of the tuples contained in this table. Theapply
method will invoke the function with the members of each row tuple passed as arguments, in ascending order by index. (I.e., the zeroth tuple is checked first, then the tuple with index 1, then index 2, and so on until all the rows have been checked (or until a failure occurs). The function represents a property of the code under test that should succeed for every row of the table. If the function returns normally, that indicates the property check succeeded for that row. If the function completes abruptly with an exception, that indicates the property check failed and theapply
method will complete abruptly with aTableDrivenPropertyCheckFailedException
that wraps the exception thrown by the supplied property function.The usual way you'd invoke the
apply
method that checks a property is via aforAll
method provided by traitTableDrivenPropertyChecks
. TheforAll
method takes aTableFor9
as its first argument, then in a curried argument list takes the property check function. It invokesapply
on theTableFor9
, passing in the property check function. Here's an example:forAll (examples) { (a, b, c, d, e, f, g, h, i) => a + b + c + d + e + f + g + h + i should equal (a * 9) }
Because
TableFor9
is aSeq[(A, B, C, D, E, F, G, H, I)]
, you can use it as aSeq
. For example, here's how you could get a sequence ofOutcome
s for each row of the table, indicating whether a property check succeeded or failed on each row of the table:for (row <- examples) yield { outcomeOf { row._1 should not equal (7) } }
Note: the
outcomeOf
method, contained in theOutcomeOf
trait, will execute the supplied code (a by-name parameter) and transform it to anOutcome
. If no exception is thrown by the code,outcomeOf
will result in aSucceeded
, indicating the "property check" succeeded. If the supplied code completes abruptly in an exception that would normally cause a test to fail,outcomeOf
will result in in aFailed
instance containing that exception. For example, the previous for expression would give you:Vector(Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Succeeded, Failed(org.scalatest.TestFailedException: 7 equaled 7), Succeeded, Succeeded)
This shows that all the property checks succeeded, except for the one at index 7.
- trait Tables extends AnyRef
Trait containing the
Table
object, which offers oneapply
factory method for eachTableForN
class,TableFor1
throughTableFor22
.Trait containing the
Table
object, which offers oneapply
factory method for eachTableForN
class,TableFor1
throughTableFor22
.For an introduction to using tables, see the documentation for trait TableDrivenPropertyChecks.
- trait Whenever extends AnyRef
Trait that contains the
whenever
clause that can be used in table- or generator-driven property checks.
Value Members
- def valueOf[A](first: Any, others: Any*)(multiplier: Int)(implicit genOfA: Generator[A]): A
Deterministically generate a value for the given Generator.
Deterministically generate a value for the given Generator.
This function takes a set of anywhere from 1-22 parameters, plus a "multiplier". It combines these to generate a pseudo-random (but deterministic) seed, feeds that into the Generator, and returns the result. Since the results are deterministic, calling this repeatedly with the same parameters will produce the same output.
This is mainly helpful when generating random Functions -- since the inputs for a test run are complex, you need more than a simple random seed to reproduce the same results. In order to make this more useful, the
toString
of a instance of a Function Generator shows how to invokevalueOf()
to reproduce the same result.- A
The type of the Generator.
- first
The first parameter to use for calculating the seed.
- others
Any additional parameters to use for calculating the seed.
- multiplier
A number to combine with the other parameters, to calculate the seed.
- genOfA
A Generator. (Usually a Function Generator.)
- returns
An instance of A, computed by feeding the calculated seed into the Generator.
- object Chooser
Provides Chooser instances for all of the major numeric types in the Scala Standard Library and Scalactic.
Provides Chooser instances for all of the major numeric types in the Scala Standard Library and Scalactic.
All of the instances provided here are simply shells over functions in Randomizer, but there is nothing sacred about that -- your own instances should use that for randomization, but will not usually be direct calls to its built-in "choose" functions.
- object CommonGenerators extends CommonGenerators
An import-able version of CommonGenerators.
An import-able version of CommonGenerators.
You should not usually need to import this directly, since it is mixed into GeneratorDrivenPropertyChecks and TableDrivenPropertyChecks.
- object Configuration extends Configuration
Companion object that facilitates the importing of
Configuration
members as an alternative to mixing it in.Companion object that facilitates the importing of
Configuration
members as an alternative to mixing it in. One use case is to importConfiguration
members so you can use them in the Scala interpreter. - object Generator
Companion to the Generator trait, which contains many of the standard implicit Generators.
Companion to the Generator trait, which contains many of the standard implicit Generators.
For the most part, you should not need to use the values and functions in here directly; the useful values in here are generally aliased in CommonGenerators (albeit with different names), which in turn is mixed into GeneratorDrivenPropertyChecks and TableDrivenPropertyChecks.
Note that this provides
Generator
s for the common Scalactic types, as well as the common standard library ones. - object GeneratorDrivenPropertyChecks extends GeneratorDrivenPropertyChecks
- object PrettyFunction0
- object PropertyCheckResult
- object PropertyChecks extends PropertyChecks
Companion object that facilitates the importing of
PropertyChecks
members as an alternative to mixing it in.Companion object that facilitates the importing of
PropertyChecks
members as an alternative to mixing it in. One use case is to importPropertyChecks
members so you can use them in the Scala interpreter. - object Randomizer
- object TableDrivenPropertyChecks extends TableDrivenPropertyChecks
- object TableFor1
Companion object for class
TableFor1
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor1
to return anotherTableFor1
. - object TableFor10
Companion object for class
TableFor10
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor10
to return anotherTableFor10
. - object TableFor11
Companion object for class
TableFor11
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor11
to return anotherTableFor11
. - object TableFor12
Companion object for class
TableFor12
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor12
to return anotherTableFor12
. - object TableFor13
Companion object for class
TableFor13
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor13
to return anotherTableFor13
. - object TableFor14
Companion object for class
TableFor14
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor14
to return anotherTableFor14
. - object TableFor15
Companion object for class
TableFor15
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor15
to return anotherTableFor15
. - object TableFor16
Companion object for class
TableFor16
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor16
to return anotherTableFor16
. - object TableFor17
Companion object for class
TableFor17
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor17
to return anotherTableFor17
. - object TableFor18
Companion object for class
TableFor18
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor18
to return anotherTableFor18
. - object TableFor19
Companion object for class
TableFor19
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor19
to return anotherTableFor19
. - object TableFor2
Companion object for class
TableFor2
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor2
to return anotherTableFor2
. - object TableFor20
Companion object for class
TableFor20
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor20
to return anotherTableFor20
. - object TableFor21
Companion object for class
TableFor21
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor21
to return anotherTableFor21
. - object TableFor22
Companion object for class
TableFor22
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor22
to return anotherTableFor22
. - object TableFor3
Companion object for class
TableFor3
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor3
to return anotherTableFor3
. - object TableFor4
Companion object for class
TableFor4
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor4
to return anotherTableFor4
. - object TableFor5
Companion object for class
TableFor5
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor5
to return anotherTableFor5
. - object TableFor6
Companion object for class
TableFor6
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor6
to return anotherTableFor6
. - object TableFor7
Companion object for class
TableFor7
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor7
to return anotherTableFor7
. - object TableFor8
Companion object for class
TableFor8
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor8
to return anotherTableFor8
. - object TableFor9
Companion object for class
TableFor9
that provides an implicitcanBuildFrom
method that enables higher order functions defined onTableFor9
to return anotherTableFor9
. - object Tables extends Tables
Companion object that facilitates the importing of
Tables
members as an alternative to mixing it in.Companion object that facilitates the importing of
Tables
members as an alternative to mixing it in. One use case is to importTables
members so you can use them in the Scala interpreter:Welcome to Scala version 2.8.0.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_22). Type in expressions to have them evaluated. Type :help for more information. scala> import org.scalatest.prop.Tables._ import org.scalatest.prop.Tables._ scala> val examples = | Table( | ("a", "b"), | ( 1, 2), | ( 3, 4) | ) examples: org.scalatest.prop.TableFor2[Int,Int] = TableFor2((1,2), (3,4))