Skip to content

Commit 5235dc3

Browse files
Fixes
1 parent 59d67ae commit 5235dc3

File tree

5 files changed

+37
-28
lines changed

5 files changed

+37
-28
lines changed

include/fields/field_definition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class FieldDefinition {
5555
void addOutput(FieldLinkDefinition* fl);
5656
std::vector<FieldLinkDefinition*> getOutputs();
5757

58-
FieldDefinition& in(Relation* relation, FieldDefinition* input, int arg);
59-
FieldDefinition& out(Relation* relation, FieldDefinition* output, int arg);
58+
FieldDefinition& input(Relation& relation, FieldDefinition& input, int arg);
59+
FieldDefinition& output(Relation& relation, FieldDefinition& output, int arg);
6060

6161
FieldDefinition& setName(const std::string& name);
6262
std::string getName() const;

src/fields/field_definition.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ FieldDefinition::FieldDefinition(Type* objectType, const std::string& name, int
1414
objectType->setFieldDefinition(this);
1515

1616
if (numArgs > 0) {
17+
std::cout << "numArgs : " << numArgs << std::endl;
1718
inputs.reserve(numArgs);
1819
}
1920
}
@@ -66,11 +67,16 @@ void FieldDefinition::initializeField(Field* field) {
6667
}
6768

6869
void FieldDefinition::addInput(FieldLinkDefinition* fl) {
69-
throw std::logic_error("Unsupported operation.");
70+
std::cout << "fl->getArgument() : " << fl->getArgument() << " inputs.size : " << inputs.size() << std::endl;
71+
72+
if(fl->getArgument() >= 0)
73+
inputs[fl->getArgument()] = fl;
74+
else
75+
inputs.push_back(fl);
7076
}
7177

7278
std::vector<FieldLinkDefinition*> FieldDefinition::getInputs() {
73-
throw std::logic_error("Unsupported operation.");
79+
return inputs;
7480
}
7581

7682
void FieldDefinition::addOutput(FieldLinkDefinition* fl) {
@@ -81,14 +87,14 @@ std::vector<FieldLinkDefinition*> FieldDefinition::getOutputs() {
8187
return outputs;
8288
}
8389

84-
FieldDefinition& FieldDefinition::in(Relation* relation, FieldDefinition* input, int arg) {
85-
FieldLinkDefinition::link(input, this, relation, arg);
90+
FieldDefinition& FieldDefinition::input(Relation& relation, FieldDefinition& input, int arg) {
91+
FieldLinkDefinition::link(&input, this, &relation, arg);
8692
// assert(relation || objectType->isInstanceOf(output->getObjectType()) || output->getObjectType()->isInstanceOf(objectType));
8793
return *this;
8894
}
8995

90-
FieldDefinition& FieldDefinition::out(Relation* relation, FieldDefinition* output, int arg) {
91-
FieldLinkDefinition::link(this, output, relation, arg);
96+
FieldDefinition& FieldDefinition::output(Relation& relation, FieldDefinition& output, int arg) {
97+
FieldLinkDefinition::link(this, &output, &relation, arg);
9298
// assert(relation || objectType->isInstanceOf(output->getObjectType()) || output->getObjectType()->isInstanceOf(objectType));
9399
return *this;
94100
}

src/fields/field_link_definition.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void FieldLinkDefinition::link(FieldDefinition* input,
1616

1717
flo->setOppositeSide(fli);
1818
fli->setOppositeSide(flo);
19+
1920
}
2021

2122
FieldLinkDefinition::FieldLinkDefinition(FieldDefinition* originFD,

src/fields/subtraction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// Constructor
55
Subtraction::Subtraction(Type* ref, const std::string& name)
6-
: AbstractFunctionDefinition(ref, name, 0, 0.0) {}
6+
: AbstractFunctionDefinition(ref, name, 2, 0.0) {}
77

88
// Overridden computeUpdate method
99
double Subtraction::computeUpdate(Obj* obj, FieldLinkDefinition* fl, double u) {

tests/subtraction-test.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
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+
28
import aika
39

410
class MyTestCase(unittest.TestCase):
511
def test_something(self):
612
self.assertEqual(True, False) # add assertion here
713

814
def testSubtraction(self):
15+
print("Module 'aika' was loaded from:", aika.__file__)
16+
917
TEST_RELATION_FROM = aika.RelationOne(1, "TEST_FROM")
1018
TEST_RELATION_TO = aika.RelationOne(2, "TEST_TO")
1119
TEST_RELATION_TO.setReversed(TEST_RELATION_FROM)
1220
TEST_RELATION_FROM.setReversed(TEST_RELATION_TO)
1321

22+
assert isinstance(TEST_RELATION_FROM, aika.Relation)
23+
assert isinstance(TEST_RELATION_TO, aika.Relation)
24+
1425
registry = aika.TypeRegistry()
1526

1627
typeA = aika.TestType(registry, "A")
@@ -20,31 +31,22 @@ def testSubtraction(self):
2031
b = typeB.inputField("b")
2132

2233
c = typeB.sub("c")
23-
c.in(TEST_RELATION_FROM, a, 0)
24-
c.in(TEST_RELATION_FROM, b, 1)
25-
26-
registry.flattenTypeHierarchy()
2734

28-
oa = typeA.instantiate()
29-
ob = typeB.instantiate()
30-
31-
if(linkingPos == 0)
32-
linkObjects(oa, ob)
33-
ob.initFields()
35+
print("Type of c:", type(c))
36+
print("Type of TEST_RELATION_FROM:", type(TEST_RELATION_FROM))
37+
print("Type of a:", type(a))
3438

35-
oa.setFieldValue(a, 50.0)
39+
assert isinstance(a, aika.FieldDefinition)
40+
assert isinstance(c, aika.FieldDefinition)
3641

37-
if(linkingPos == 1)
38-
linkObjects(oa, ob)
39-
ob.initFields()
42+
c.input(TEST_RELATION_FROM, a, 0)
43+
c.input(TEST_RELATION_FROM, b, 1)
4044

41-
oa.setFieldValue(b, 20.0)
45+
registry.flattenTypeHierarchy()
4246

43-
if(linkingPos == 2)
44-
linkObjects(oa, ob)
45-
ob.initFields()
47+
oa = typeA.instantiate()
48+
ob = typeB.instantiate()
4649

47-
Assertions.assertEquals(30.0, ob.getFieldOutput(c).getValue())
4850

4951
if __name__ == '__main__':
5052
unittest.main()

0 commit comments

Comments
 (0)