1+ import unittest
2+ import sys
3+ import os
4+ from parameterized import parameterized
5+
6+ # Add the project root to Python's module search path
7+ sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." )))
8+
9+ import aika
10+
11+ class DivisionTestCase (unittest .TestCase ):
12+
13+ @parameterized .expand ([
14+ (0 , "linking_pos_0" ),
15+ (1 , "linking_pos_1" ),
16+ (2 , "linking_pos_2" )
17+ ])
18+ def testDivision (self , linking_pos , test_name ):
19+ print ("Module 'aika' was loaded from:" , aika .__file__ )
20+
21+ TEST_RELATION_FROM = aika .RelationOne (1 , "TEST_FROM" )
22+ TEST_RELATION_TO = aika .RelationOne (2 , "TEST_TO" )
23+ TEST_RELATION_TO .setReversed (TEST_RELATION_FROM )
24+ TEST_RELATION_FROM .setReversed (TEST_RELATION_TO )
25+
26+ assert isinstance (TEST_RELATION_FROM , aika .Relation )
27+ assert isinstance (TEST_RELATION_TO , aika .Relation )
28+
29+ registry = aika .TypeRegistry ()
30+
31+ typeA = aika .TestType (registry , "A" )
32+ typeB = aika .TestType (registry , "B" )
33+
34+ a = typeA .inputField ("a" )
35+ b = typeA .inputField ("b" )
36+
37+ c = typeB .div ("c" )
38+
39+ print ("Type of c:" , type (c ))
40+ print ("Type of TEST_RELATION_FROM:" , type (TEST_RELATION_FROM ))
41+ print ("Type of a:" , type (a ))
42+
43+ assert isinstance (a , aika .FieldDefinition )
44+ assert isinstance (c , aika .FieldDefinition )
45+
46+ c .input (TEST_RELATION_FROM , a , 0 )
47+ c .input (TEST_RELATION_FROM , b , 1 )
48+
49+ registry .flattenTypeHierarchy ()
50+
51+ oa = typeA .instantiate ()
52+ ob = typeB .instantiate ()
53+
54+ print ("linking_pos:" , linking_pos )
55+
56+ if linking_pos == 0 :
57+ aika .TestObj .linkObjects (oa , ob )
58+ ob .initFields ()
59+
60+ oa .setFieldValue (a , 50.0 )
61+ print ("oa.getFieldValue(a):" , oa .getFieldValue (a ))
62+
63+ if linking_pos == 1 :
64+ aika .TestObj .linkObjects (oa , ob )
65+ ob .initFields ()
66+
67+ oa .setFieldValue (b , 2.0 )
68+ print ("oa.getFieldValue(b):" , oa .getFieldValue (b ))
69+
70+ if linking_pos == 2 :
71+ aika .TestObj .linkObjects (oa , ob )
72+ ob .initFields ()
73+
74+ print ("ob.getFieldValue(c):" , ob .getFieldValue (c ))
75+
76+ print ("ob.getFieldAsString(c):" , ob .getFieldAsString (c ))
77+
78+ self .assertEqual (25.0 , ob .getFieldValue (c ))
79+
80+ if __name__ == '__main__' :
81+ unittest .main ()
0 commit comments