git.fiddlerwoaroof.com
Browse code

basic generator

Greg Wiley authored on 03/05/2017 22:35:32
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,14 @@
1
+#ifndef GENERATOR_H_
2
+#define GENERATOR_H_
3
+
4
+#include <string>
5
+#include <functional>
6
+
7
+using generator = std::function<std::string()>;
8
+
9
+inline generator make_generator() {
10
+    return [] {return std::string("234567");};
11
+}
12
+
13
+#endif
14
+
0 15
new file mode 100644
... ...
@@ -0,0 +1,29 @@
1
+#include <algorithm>
2
+
3
+#include "generator.h"
4
+#include "test_util.h"
5
+
6
+int six_digits()  {
7
+   // given
8
+   generator generator = make_generator();
9
+
10
+  // when
11
+  auto actual = generator();
12
+
13
+
14
+  // then
15
+  check(actual.size() == 6, "size is wrong");
16
+  check(std::all_of(actual.begin(), actual.end(), [](char c){ return c >= '0' && c <= '9';}), "not just digits");
17
+  succeed();
18
+}
19
+
20
+
21
+int run_tests() {
22
+    test(six_digits);
23
+    succeed();
24
+}
25
+
26
+int main(int argc, char *argv[]) {
27
+    return !run_tests();
28
+}
29
+