Commits

Matt Oswald  committed ce4304d

Edited online

  • Participants
  • Parent commits 2c1bd20

Comments (0)

Files changed (1)

 }
 
 THEORY_PROVIDER(DoubleTestData, int, int)
-   THEORY_DATA(1, 2)
-   THEORY_DATA(2, 4)
-   THEORY_DATA(-1, -2)
+   THEORY_DATA(2, 1)
+   THEORY_DATA(4, 2)
+   THEORY_DATA(-2, -1)
    THEORY_DATA(0, 0)
 THEORY_PROVIDER_END
 
-THEORY(DoubleTest, (int value, int expected), DoubleTestData)
+THEORY(DoubleTest, (int expected, int value), DoubleTestData)
+{
+   Assert.Equal(expected, Double(value));
+}
+}}}
+
+In this example, the {{{THEORY_PROVIDER}}}/{{{THEORY_PROVIDER_END}}} macros simply aid in creating a local function that returns {{{std::vector<std::tuple<int, int>>}}}, but {{{THEORY}}}s can accept //any// object that matches that signature:
+{{{
+#!c++
+
+// functor
+struct
+{
+   std::vector<std::tuple<int, int>> operator()() const
+   {
+      return std::vector<std::tuple<int, int>>();
+   }
+} functor;
+
+// std::function
+std::function<std::vector<std::tuple<int, int>>()> stdFn = ...;
+
+// or even a lambda!
+THEORY(LambdaTheory, (int expected, int value), []() -> std::vector<std::tuple<int, int>>
+{
+   std::vector<std::tuple<int, int>> data;
+   data.push_back(std::make_tuple(2, 1));
+   return data;
+})
 {
    Assert.Equal(expected, Double(value));
 }