-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathconnection_director.py
More file actions
31 lines (23 loc) · 872 Bytes
/
connection_director.py
File metadata and controls
31 lines (23 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cmf
import unittest
t = cmf.Time()
class CustomConnection(cmf.BaseConnection):
def __init__(self, left, right):
super().__init__(left, right, type(self).__name__)
self.left = left
self.right = right
def calc_q(self, t):
return self.left.volume - self.right.volume
class ConnectionDirectorTest(unittest.TestCase):
def test_connection(self):
"""Test a Python connection"""
p = cmf.project()
s1 = p.NewStorage('S1')
s1.volume = 1.0
s2 = p.NewStorage('S2')
con = CustomConnection(s1, s2)
self.assertEqual(s1.flux_to(s2, t), con.calc_q(t), 'Flux S1->S2 does not equal difference')
s2.volume = 1.5
self.assertEqual(s1.flux_to(s2, t), con.calc_q(t), 'Flux S1<-S2 does not equal difference')
if __name__ == '__main__':
unittest.main(verbosity=2)