1 module tests.pass.normal;
2 
3 import unit_threaded.all;
4 
5 
6 class IntEqualTest: TestCase {
7     override void test() {
8         1.shouldNotEqual(5);
9         5.shouldNotEqual(1);
10         3.shouldEqual(3);
11         2.shouldEqual(2);
12     }
13 }
14 
15 class DoubleEqualTest: TestCase {
16     override void test() {
17         shouldNotEqual(1.0, 2.0);
18         (2.0).shouldEqual(2.0);
19         (2.0).shouldEqual(2.0);
20     }
21 }
22 
23 void testEqual() {
24     1.shouldEqual(1);
25     checkEqual(1.0, 1.0);
26     "foo".shouldEqual("foo");
27 }
28 
29 void testNotEqual() {
30     3.shouldNotEqual(4);
31     checkNotEqual(5.0, 6.0);
32     "foo".shouldNotEqual("bar");
33 }
34 
35 
36 private class MyException: Exception {
37     this() {
38         super("MyException");
39     }
40 }
41 
42 void testThrown() {
43     throwFunc.shouldThrow!MyException;
44 }
45 
46 void testNotThrown() {
47     nothrowFunc.shouldNotThrow;
48 }
49 
50 private void throwFunc() {
51     throw new MyException;
52 }
53 
54 private void nothrowFunc() nothrow {
55     {}
56 }
57 
58 unittest {
59     writelnUt("First unit test block\n");
60     assert(true); //unit test block that always passes
61 }
62 
63 unittest {
64     writelnUt("Second unit test block\n");
65     assert(true); //unit test block that always passes
66 }
67 
68 
69 private class MyClass {
70     int i;
71     double d;
72     this(int i, double d) {
73         this.i = i;
74         this.d = d;
75     }
76     override string toString() const {
77         import std.conv;
78         return text("MyClass(", i, ", ", d, ")");
79     }
80 }
81 
82 void testEqualClass() {
83     const foo = new MyClass(2, 3.0);
84     const bar = new MyClass(2, 3.0);
85     const baz = new MyClass(3, 3.0);
86 
87     foo.shouldEqual(bar);
88     bar.shouldEqual(foo);
89     foo.shouldNotEqual(baz);
90     bar.shouldNotEqual(baz);
91     baz.shouldNotEqual(foo);
92     baz.shouldNotEqual(bar);
93 }
94 
95 
96 private struct Pair {
97     string s;
98     int i;
99 }
100 
101 void testPairAA() {
102     auto map = [Pair("foo", 5): 105];
103     [Pair("foo", 5): 105].shouldEqual(map);
104     map.dup.shouldEqual(map);
105     auto pair = Pair("foo", 5);
106     auto othermap = [pair: 105];
107     map.shouldEqual(othermap);
108 }