Skip to content

Commit

Permalink
unit tests for power module. Moved power tests out of test_wave.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rpauly18 committed Jun 2, 2020
1 parent ca86bbf commit 9b23df7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
59 changes: 59 additions & 0 deletions mhkit/tests/test_power.py
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()

21 changes: 0 additions & 21 deletions mhkit/tests/test_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,27 +400,6 @@ def test_mean_annual_energy_production(self):

self.assertAlmostEqual(maep, 1754020.077, 2)

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 = wave.performance.ac_power_three_phase(current, voltage, 1, False)
P1b = wave.performance.ac_power_three_phase(current, voltage, 0.5, False)
P2 = wave.performance.ac_power_three_phase(current, voltage, 1, True)
P2b = wave.performance.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 = wave.performance.dc_power(current, voltage)

self.assertEqual(P.sum()['Gross'], 584)

def test_plot_matrix(self):
filename = abspath(join(testdir, 'wave_plot_matrix.png'))
Expand Down

0 comments on commit 9b23df7

Please sign in to comment.