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