-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit tests for power module. Moved power tests out of test_wave.py
- Loading branch information
Showing
2 changed files
with
59 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import unittest | ||
from os.path import abspath, dirname, join, isfile | ||
import os | ||
import numpy as np | ||
import pandas as pd | ||
import mhkit.power as power | ||
|
||
class TestDevice(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(self): | ||
self.t = 600 | ||
fs = 1000 | ||
|
||
self.samples = np.linspace(0, self.t, int(fs*self.t), endpoint=False) | ||
self.frequency = 60 | ||
self.freq_array = np.ones(len(self.samples))*60 | ||
|
||
self.signal = np.sin(2 * np.pi * self.frequency * self.samples) | ||
|
||
|
||
@classmethod | ||
def tearDownClass(self): | ||
pass | ||
|
||
|
||
def test_instfreq(self): | ||
um = pd.Series(self.signal,index = self.samples) | ||
|
||
freq = power.characteristics.instantaneous_frequency(um) | ||
for i in freq.values: | ||
self.assertAlmostEqual(i[0], self.frequency,1) | ||
|
||
|
||
def test_ac_power_three_phase(self): | ||
current = pd.DataFrame([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], columns=['A1', 'A2', 'A3']) | ||
voltage = pd.DataFrame([[1,5,9],[2,6,10],[3,7,11],[4,8,12]], columns=['V1', 'V2', 'V3']) | ||
|
||
P1 = power.characteristics.ac_power_three_phase(current, voltage, 1, False) | ||
P1b = power.characteristics.ac_power_three_phase(current, voltage, 0.5, False) | ||
P2 = power.characteristics.ac_power_three_phase(current, voltage, 1, True) | ||
P2b = power.characteristics.ac_power_three_phase(current, voltage, 0.5, True) | ||
|
||
self.assertEqual(P1.sum()[0], 584) | ||
self.assertEqual(P1b.sum()[0], 584/2) | ||
self.assertAlmostEqual(P2.sum()[0], 1011.518, 2) | ||
self.assertAlmostEqual(P2b.sum()[0], 1011.518/2, 2) | ||
|
||
def test_dc_power(self): | ||
current = pd.DataFrame([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], columns=['A1', 'A2', 'A3']) | ||
voltage = pd.DataFrame([[1,5,9],[2,6,10],[3,7,11],[4,8,12]], columns=['V1', 'V2', 'V3']) | ||
|
||
P = power.characteristics.dc_power(current, voltage) | ||
|
||
self.assertEqual(P.sum()['Gross'], 584) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters