All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.scalatest.prop.Tables.scala Maven / Gradle / Ivy

Go to download

ScalaTest is a free, open-source testing toolkit for Scala and Java programmers.

There is a newer version: 2.0.M6-SNAP4
Show newest version
/*
 * Copyright 2001-2012 Artima, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.scalatest
package prop

/**
 * Trait containing the Table object, which offers one apply factory method for
 * each TableForN class, TableFor1 through TableFor22.
 * 
 * 

* For an introduction to using tables, see the documentation for trait * TableDrivenPropertyChecks. *

* * @author Bill Venners */ trait Tables { /** * Object containing one apply factory method for each TableFor<n> class. * *

* For example, you could create a table of 5 rows and 2 colums like this: *

* *
   * import org.scalatest.prop.Tables._
   *
   * val examples =
   *   Table(
   *     ("a", "b"),
   *     (  1,   2),
   *     (  2,   4),
     *     (  4,   8),
   *     (  8,  16),
   *     ( 16,  32)
   *   )
   * 
* *

* Because you supplied 2 members in each tuple, the type you'll get back will be a TableFor2. If * you wanted a table with just one column you could write this: *

* *
   * val moreExamples =
   *   Table(
   *     "powerOfTwo",
   *          1,
   *          2,
   *          4,
   *          8,
   *          16
   *   )
   * 
* *

* Or if you wanted a table with 10 columns and 10 rows, you could do this: *

* *
   * val multiplicationTable =
   *   Table(
   *     ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),
   *     (  1,   2,   3,   4,   5,   6,   7,   8,   9,  10),
   *     (  2,   4,   6,   8,  10,  12,  14,  16,  18,  20),
   *     (  3,   6,   9,  12,  15,  18,  21,  24,  27,  30),
   *     (  4,   8,  12,  16,  20,  24,  28,  32,  36,  40),
   *     (  5,  10,  15,  20,  25,  30,  35,  40,  45,  50),
   *     (  6,  12,  18,  24,  30,  36,  42,  48,  54,  60),
   *     (  7,  14,  21,  28,  35,  42,  49,  56,  63,  70),
   *     (  8,  16,  24,  32,  40,  48,  56,  64,  72,  80),
   *     (  9,  18,  27,  36,  45,  54,  63,  72,  81,  90),
   *     ( 10,  20,  30,  40,  50,  60,  70,  80,  90, 100)
   *   )
   * 
* *

* The type of multiplicationTable would be TableFor10. You can pass the resulting * tables to a forAll method (defined in trait PropertyChecks), to perform a property * check with the data in the table. Or, because tables are sequences of tuples, you can treat them as a Seq. *

* * @author Bill Venners */ object Table { /** * Factory method for creating a new TableFor1. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple1s containing the data of this table */ def apply[A](heading: (String), rows: (A)*) = new TableFor1(heading, rows: _*) /** * Factory method for creating a new TableFor2. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple2s containing the data of this table */ def apply[A, B](heading: (String, String), rows: (A, B)*) = new TableFor2(heading, rows: _*) /** * Factory method for creating a new TableFor3. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple3s containing the data of this table */ def apply[A, B, C](heading: (String, String, String), rows: (A, B, C)*) = new TableFor3(heading, rows: _*) /** * Factory method for creating a new TableFor4. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple4s containing the data of this table */ def apply[A, B, C, D](heading: (String, String, String, String), rows: (A, B, C, D)*) = new TableFor4(heading, rows: _*) /** * Factory method for creating a new TableFor5. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple5s containing the data of this table */ def apply[A, B, C, D, E](heading: (String, String, String, String, String), rows: (A, B, C, D, E)*) = new TableFor5(heading, rows: _*) /** * Factory method for creating a new TableFor6. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple6s containing the data of this table */ def apply[A, B, C, D, E, F](heading: (String, String, String, String, String, String), rows: (A, B, C, D, E, F)*) = new TableFor6(heading, rows: _*) /** * Factory method for creating a new TableFor7. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple7s containing the data of this table */ def apply[A, B, C, D, E, F, G](heading: (String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G)*) = new TableFor7(heading, rows: _*) /** * Factory method for creating a new TableFor8. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple8s containing the data of this table */ def apply[A, B, C, D, E, F, G, H](heading: (String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H)*) = new TableFor8(heading, rows: _*) /** * Factory method for creating a new TableFor9. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple9s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I](heading: (String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I)*) = new TableFor9(heading, rows: _*) /** * Factory method for creating a new TableFor10. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple10s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J](heading: (String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J)*) = new TableFor10(heading, rows: _*) /** * Factory method for creating a new TableFor11. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple11s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K](heading: (String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K)*) = new TableFor11(heading, rows: _*) /** * Factory method for creating a new TableFor12. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple12s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L](heading: (String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L)*) = new TableFor12(heading, rows: _*) /** * Factory method for creating a new TableFor13. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple13s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M)*) = new TableFor13(heading, rows: _*) /** * Factory method for creating a new TableFor14. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple14s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M, N](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N)*) = new TableFor14(heading, rows: _*) /** * Factory method for creating a new TableFor15. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple15s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)*) = new TableFor15(heading, rows: _*) /** * Factory method for creating a new TableFor16. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple16s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)*) = new TableFor16(heading, rows: _*) /** * Factory method for creating a new TableFor17. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple17s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)*) = new TableFor17(heading, rows: _*) /** * Factory method for creating a new TableFor18. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple18s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)*) = new TableFor18(heading, rows: _*) /** * Factory method for creating a new TableFor19. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple19s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)*) = new TableFor19(heading, rows: _*) /** * Factory method for creating a new TableFor20. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple20s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)*) = new TableFor20(heading, rows: _*) /** * Factory method for creating a new TableFor21. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple21s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U)*) = new TableFor21(heading, rows: _*) /** * Factory method for creating a new TableFor22. * * @param heading a tuple containing string names of the columns in this table * @param rows a variable length parameter list of Tuple22s containing the data of this table */ def apply[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V](heading: (String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String), rows: (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V)*) = new TableFor22(heading, rows: _*) } } /** * Companion object that facilitates the importing of Tables members as * an alternative to mixing it in. One use case is to import Tables 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))
 * 
* * @author Bill Venners */ object Tables extends Tables




© 2015 - 2024 Weber Informatics LLC | Privacy Policy