22
33#include < vector>
44#include < string>
5- #include < any >
5+ #include < variant >
66#include < optional>
77#include < memory>
8+ #include < random>
89
9- enum class Kind {
10- PRIMITIVE_TYPE,
11- POINTER
12- };
10+ struct Type ;
1311
1412enum class PrimitiveType {
1513 CHAR,
@@ -18,19 +16,16 @@ enum class PrimitiveType {
1816
1917std::string printPrimitiveType (PrimitiveType type);
2018
21- struct Type {
22- union {
23- PrimitiveType primitiveType;
24- std::unique_ptr<Type> pointerTo;
25- };
19+ struct PointerTo {
20+ std::shared_ptr<Type> type;
21+ };
2622
27- Kind kind;
23+ struct Type {
24+ std::variant<PrimitiveType, PointerTo> type;
2825
2926 [[nodiscard]] std::string print () const ;
3027};
3128
32- std::any fillValue (Type x);
33-
3429struct TestSignature {
3530 std::string name;
3631 std::vector<Type> parameterTypes;
@@ -40,7 +35,14 @@ struct TestSignature {
4035struct Value {
4136 Type type;
4237 int value;
38+
4339 [[nodiscard]] std::string print () const ;
40+
41+ template <class Generator >
42+ static Value generate (Generator& gen, const Type& type) {
43+ std::uniform_int_distribution<int > distribution;
44+ return Value { type, distribution (gen) };
45+ }
4446};
4547
4648struct Test
@@ -50,7 +52,20 @@ struct Test
5052 std::vector<Value> arguments;
5153
5254 // after test launch
53- Value returnValue;
55+ std::optional< Value> returnValue;
5456
5557 [[nodiscard]] std::string print () const ;
58+
59+ template <class Generator >
60+ static Test generate (Generator gen, std::string name, TestSignature signature) {
61+ Test test;
62+ test.name = std::move (name);
63+ test.signature = std::move (signature);
64+
65+ for (const auto &type : test.signature .parameterTypes ) {
66+ test.arguments .push_back (Value::generate (gen, type));
67+ }
68+
69+ return test;
70+ }
5671};
0 commit comments