Commits

Matt Oswald  committed 29a9274

just realized that theories don't have to accept vectors, anything with begin/end will do

  • Participants
  • Parent commits 3f81236

Comments (0)

Files changed (2)

 
 A //Theory// creates a parameterized test. Each set of parameters is bound to an instance of the test and run individually. In this example, the {{{THEORY}}} macro creates a test named {{{Double Test}}} which takes parameters {{{(int expected, int value)}}}. The rest of the macro's parameters are {{{std::tuples}}} whose members resolve to the same type as the test parameters.
 
-If your //Theory// data requires detailed setup (for instance, if the details of the test parameters are stored in a local database or CSV file), another macro {{{DATA_THEORY}}} creates the same sort of test, only instead of individual {{{std::tuples}}}, it takes any function object (raw function pointer, {{{std::function}}}, or functor object) that returns {{{std::vector<std::tuple>>}}}:
+If your //Theory// data requires detailed setup (for instance, if the details of the test parameters are stored in a local database or CSV file), another macro {{{DATA_THEORY}}} creates the same sort of test, only instead of individual {{{std::tuples}}}, it takes any function object (raw function pointer, {{{std::function}}}, or functor object) that returns a container of {{{std::tuple}}}s with a {{{begin}}}/{{{end}}} pair:
 
 {{{
 #!c++
       // fill data
    }
 
-   const std::vector<std::tuple<int, int>> &operator()() const
+   const std::set<std::tuple<int, int>> &operator()() const
    {
       return data;
    }
 
-   std::vector<std::tuple<int, int>> data;
+   std::set<std::tuple<int, int>> data;
 } functor;
 
 // std::function
 std::function<std::vector<std::tuple<int, int>>()> stdFn = ...;
 
+// a custom container
+struct CustomContainer
+{
+   CustomContainer()
+   {
+      // fill data
+   }
+
+   const CustomContainer &operator ()() const
+   {
+      return *this;
+   }
+
+   friend const std::tuple<int, int> *begin(const CustomContainer &cc)
+   {
+      return &cc.data[0];
+   }
+
+   friend const std::tuple<int, int> *end(const CustomContainer &cc)
+   {
+      return &cc.data[10];
+   }
+
+   std::tuple<int, int> data[10];
+}
+
 // or even a lambda! (note the parens around the lambda)
 DATA_THEORY("Lambda Theory", (int expected, int value),
 ([]() -> std::vector<std::tuple<int, int>>
 
 There are several forms of {{{THEORY}}} as well.
 
- * {{{DATA_THEORY}}} accepts a data provider function object that returns {{{std::vector<std::tuple>>}}} instead a list of inline data. This lets you define more complex methods of providing the test data. For example, your test data could come from an external database. You can also pass in lambdas as the test parameter, and with that we could re-write the two above tests thusly:
+ * {{{DATA_THEORY}}} accepts a data provider function object that returns a container of {{{std::tuple}}} that supports {{{begin}}}/{{{end}}} instead a list of inline data. This lets you define more complex methods of providing the test data. For example, your test data could come from an external database. You can also pass in lambdas as the test parameter, and with that we could re-write the two above tests thusly:
 
 {{{
 #!c++