1 // file: summertest.d
 2 module SummerTests;
 3 
 4 import dunit;
 5 import summer;
 6 
 7 class SummerTestClass {
 8 
 9     mixin TestMixin;
10     Summer summer;
11 
12     void setUpClass() { summer = new Summer; }
13 
14     void tearDownClass() { delete( summer ); }
15 
16     void test_it_can_sum_a_line_with_expected_line_format() {
17         assertEquals( summer.sumString( "5 -10 +15\n\t 10" ), 20 );
18     }
19 
20     void test_it_can_sums_a_file_with_separated_integers() {
21         assertEquals( summer.sumFile( "summer_testfile.txt" ), 12 );
22     }
23 
24 }
25 
 1 // file: summer.d
 2 module summer;
 3 
 4 import std.array;
 5 import std.conv;
 6 
 7 /**
 8     Sums the space separated integers in a string which can be obtained by reading a file
 9 */
10 class Summer {
11 
12     int sumString( string line ) {
13         int sum;
14         foreach( value; std.array.split( line )) {
15             sum += std.conv.to!int(value);
16         }
17         return sum;
18     }
19 
20     int sumFile( string filename ) {
21         return sumString( cast(string)std.file.read( filename ));
22     }
23 
24 }
 1 // file:runTests.d
 2 // compiling : dmd runTests.d summertest.d summer.d dunit.d
 3 // launch tests : ./runTests
 4 
 5 import dunit;
 6 
 7 // mixin DUnitMain; // which is: void main() {dunit.runTests_Progress(); }
 8 // or:
 9 void main() { dunit.runTests_Tree(); }
10