-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
105 lines (77 loc) · 3.48 KB
/
test.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import unittest
from math import sqrt
from lib.PhaseToComplex import PhaseToComplex
from lib.ComplexToPhase import ComplexToPhase
from lib.TensaoFase import TensaoFase
from lib.FaseLinha import FaseLinha
from lib.Correntes import Correntes
import lib.DeltaEstrela as DeltaEstrela
import lib.EstrelaDelta as EstrelaDelta
import lib.TensaoNeutro as TensaoNeutro
class TestBase(unittest.TestCase):
def test_0_PhaseToComplex(self):
ans:complex = PhaseToComplex(100, 0)
ans = complex(
round(ans.real, 11),
round(ans.imag, 11)
)
self.assertEqual(ans, 100+0j)
ans = PhaseToComplex(100, 120)
ans = complex(
round(ans.real, 11),
round(ans.imag, 11)
)
self.assertEqual(ans, -50.0+86.60254037844j)
def test_1_ComplexToPhase(self):
ans = ComplexToPhase(PhaseToComplex(100, 0))
ans = ( round(ans[0], 11), round(ans[1], 11) )
self.assertEqual(ans, (100,0))
ans = ComplexToPhase(PhaseToComplex(100, 120))
ans = ( round(ans[0], 11), round(ans[1], 11) )
self.assertEqual(ans, (100, 120))
ans = ComplexToPhase(PhaseToComplex(100, -120))
ans = ( round(ans[0], 11), round(ans[1], 11) )
self.assertEqual(ans, (100, -120))
def test_2_TensaoFase(self):
ref = [PhaseToComplex(100, 0), PhaseToComplex(100, 120), PhaseToComplex(100, -120)]
self.assertEqual(TensaoFase(ref[0], 3), ref)
ref = [PhaseToComplex(100, 30), PhaseToComplex(100, 150), PhaseToComplex(100, -90)]
self.assertEqual(TensaoFase(ref[0], 3), ref)
def test_3_FaseLinha(self):
mod = 100/sqrt(3)
ref = []
for i in range(0,3):
tmp = PhaseToComplex(mod, -30 + i*120)
tmp = complex(round(tmp.real, 10), round(tmp.imag, 10))
ref.append(tmp)
ans = FaseLinha(TensaoFase(PhaseToComplex(100,0)))
for i in range(0,3):
ans[i] = complex( round(ans[i].real, 10), round(ans[i].imag, 10) )
self.assertEqual(ans, ref)
#######
ref = []
for i in range(0,3):
tmp = PhaseToComplex(mod, -30 + i*120 + 30)
tmp = complex(round(tmp.real, 10), round(tmp.imag, 10))
ref.append(tmp)
ans = FaseLinha(TensaoFase(PhaseToComplex(100,30)))
for i in range(0,3): # fail due to rounding
ans[i] = complex( round(ans[i].real, 10), round(ans[i].imag, 10) )
self.assertEqual(ans, ref)
def test_4_Correntes(self):
ref = [1 + 0j]
self.assertEqual(Correntes([2+0j], [2+0j]), ref)
self.assertEqual(Correntes([2+1j], [2+1j]), ref)
self.assertEqual(Correntes([0+1j], [0+1j]), ref)
def test_5_DeltaEstrela(self):
self.assertEqual(DeltaEstrela.Impedancia([3 + 0j, 3 + 0j, 3 + 0j]), [1 + 0j, 1 + 0j, 1 + 0j])
self.assertEqual(DeltaEstrela.Impedancia([3 + 3j, 3 + 3j, 3 + 3j]), [1 + 1j, 1 + 1j, 1 + 1j])
self.assertEqual(DeltaEstrela.Impedancia([0 + 3j, 0 + 3j, 0 + 3j]), [0 + 1j, 0 + 1j, 0 + 1j])
def test_6_EstrelaDelta(self):
self.assertEqual(EstrelaDelta.Impedancia([1 + 0j, 1 + 0j, 1 + 0j]), [3 + 0j, 3 + 0j, 3 + 0j])
self.assertEqual(EstrelaDelta.Impedancia([1 + 1j, 1 + 1j, 1 + 1j]), [3 + 3j, 3 + 3j, 3 + 3j])
self.assertEqual(EstrelaDelta.Impedancia([0 + 1j, 0 + 1j, 0 + 1j]), [0 + 3j, 0 + 3j, 0 + 3j])
def test_7_TensaoNeutro(self):
pass
if __name__ == '__main__':
unittest.main()