1 /**
2  * Unit tests for listiteratingsystem.d
3  *
4  */
5 module listiteratingsys_test;
6 
7 import ashd.core.component              : Component;
8 import ashd.core.componentMatchingFamily: ComponentMatchingFamily;
9 import ashd.core.engine                 : Engine;
10 import ashd.core.iengine                : IEngine;
11 import ashd.core.entity                 : Entity;
12 import ashd.core.node                   : Node;
13 import ashd.core.nodelist               : NodeList;
14 import ashd.tools.listIteratingSystem   : ListIteratingSystem;
15 
16 
17 import std.datetime                     : dur, Duration, SysTime;
18 
19 
20 
21 int main()
22 {
23     (new ListIteratingSystemTests).updateIteratesOverNodes();
24     return 0;
25 }
26 
27 class ListIteratingSystemTests
28 {
29 
30     Entity[] mEntities;
31     int      mCallCount;
32 
33 
34     public void updateIteratesOverNodes()
35     {
36         ComponentMatchingFamily!MockNode mockNodeFamily;
37         Engine engine = new Engine();
38         mockNodeFamily = new ComponentMatchingFamily!MockNode( engine );
39         engine.registerFamily!MockNode( mockNodeFamily );
40 
41         Entity entity1 = new Entity();
42         Point component1 = new Point();
43         entity1.add( component1 );
44         engine.addEntity( entity1 );
45         Entity entity2 = new Entity();
46         Point component2 = new Point();
47         entity2.add( component2 );
48         engine.addEntity( entity2 );
49         Entity entity3 = new Entity();
50         Point component3 = new Point();
51         entity3.add( component3 );
52         engine.addEntity( entity3 );
53 
54         ListIteratingSystem!MockNode system1 = new ListIteratingSystem!MockNode( &updateNode );
55         engine.addSystem!(ListIteratingSystem!MockNode)( system1, 1 );
56         mEntities = [entity1, entity2, entity3];
57         mCallCount = 0;
58         engine.update( dur!"msecs"(100) );
59 
60         assert( mCallCount == 3 );
61 
62     }
63 
64     private void updateNode( Node node_a, Duration time_a )
65     {
66         assert( node_a.entity is mEntities[mCallCount] );
67         assert( time_a == dur!"msecs"(100) );
68         mCallCount++;
69     }
70 
71 }
72 
73 class Point: Component
74 {
75     int x,y;
76 }
77 
78 class MockNode: Node
79 {
80     public Point value;
81 }
82