1+ import unittest
2+ import sys
3+ import os
4+
5+ # Add the project root to Python's module search path
6+ sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." )))
7+
8+ import aika
9+
10+ class SumTestCase (unittest .TestCase ):
11+
12+ def testSum (self ):
13+ print ("Module 'aika' was loaded from:" , aika .__file__ )
14+
15+ TEST_RELATION_FROM = aika .RelationOne (1 , "TEST_FROM" )
16+ TEST_RELATION_TO = aika .RelationOne (2 , "TEST_TO" )
17+ TEST_RELATION_TO .setReversed (TEST_RELATION_FROM )
18+ TEST_RELATION_FROM .setReversed (TEST_RELATION_TO )
19+
20+ registry = aika .TypeRegistry ()
21+
22+ typeA = aika .TestType (registry , "A" )
23+ typeB = aika .TestType (registry , "B" )
24+
25+ a = typeA .inputField ("a" )
26+ b = typeA .inputField ("b" )
27+
28+ c = typeB .add ("c" )
29+
30+ c .input (TEST_RELATION_FROM , a , 0 )
31+ c .input (TEST_RELATION_FROM , b , 1 )
32+
33+ registry .flattenTypeHierarchy ()
34+
35+ oa = typeA .instantiate ()
36+ ob = typeB .instantiate ()
37+
38+ aika .TestObj .linkObjects (oa , ob )
39+ ob .initFields ()
40+
41+ oa .setFieldValue (a , 50.0 )
42+ oa .setFieldValue (b , 20.0 )
43+
44+ print ("ob.getFieldValue(c):" , ob .getFieldValue (c ))
45+
46+ self .assertEqual (70.0 , ob .getFieldValue (c ))
47+
48+ if __name__ == '__main__' :
49+ unittest .main ()
0 commit comments