1 module unit_threaded.randomized;
2 
3 public import unit_threaded.randomized.gen;
4 public import unit_threaded.randomized.random;
5 public import unit_threaded.randomized.benchmark;
6 
7 unittest
8 {
9     import core.thread : Thread;
10     import core.time : seconds;
11 
12     struct Foo
13     {
14         void superSlowMethod(int a, Gen!(int, -10, 10) b)
15             {
16                 Thread.sleep(1.seconds / 250000);
17                 doNotOptimizeAway(a);
18             }
19     }
20 
21     Foo a;
22 
23     auto del = delegate(int ai, Gen!(int, -10, 10) b) {
24         a.superSlowMethod(ai, b);
25     };
26 
27     benchmark!(del)();
28 }
29 
30 unittest // test that the function parameter names are correct
31 {
32     import std..string : indexOf;
33     import std.experimental.logger;
34 
35     class SingleLineLogger : Logger
36     {
37         this()
38             {
39                 super(LogLevel.info);
40             }
41 
42         override void writeLogMsg(ref LogEntry payload) @safe
43             {
44                 this.line = payload.msg;
45             }
46 
47         string line;
48     }
49 
50     auto oldLogger = stdThreadLocalLog;
51     auto newLogger = new SingleLineLogger();
52     stdThreadLocalLog = newLogger;
53     scope (exit)
54         stdThreadLocalLog = oldLogger;
55 
56     static int failingFun(int a, string b)
57     {
58         throw new Exception("Hello");
59     }
60 
61     log();
62     benchmark!failingFun();
63 
64     assert(newLogger.line.indexOf("'a'") != -1);
65     assert(newLogger.line.indexOf("'b'") != -1);
66 }