root/trunk/src/tutorials/examples/dm_D_learn_826/myclass.d

Revision 6, 0.6 kB (checked in by jcc7, 3 years ago)

Made more progress in developing convertToWiki and added some files.

Line 
1 /* Example Name: Unittest within a class */
2 /* Category: Intermediate */
3 /* Description: Unittest within a class */
4
5 class Sum
6
7 /*
8    based on http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.learn/826
9    see also http://www.digitalmars.com/d/class.html
10 */
11
12 {
13     int add(int x, int y) { return x + y; }
14
15     unittest
16
17     /* To try the unittest, compile with "dmd myclass.d -unittest" and then run the executable. */
18
19     {
20         Sum s = new Sum(); /* remember to "new" it. */
21         assert(s.add(3,4) == 7);
22         assert(s.add(-2,0) == -2);
23     }
24 }
25
26
27 int main(char[][] argv)
28 {
29        return 0;
30 }
Note: See TracBrowser for help on using the browser.