Skip to content

Commit 1ce6fe8

Browse files
committed
Add simple_efficiency tests for numpy array inputs
1 parent f3e73ba commit 1ce6fe8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/test_transformer.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pvlib import transformer
66

7+
import numpy as np
78

89
def test_simple_efficiency():
910

@@ -57,4 +58,41 @@ def test_simple_efficiency_known_values():
5758
transformer.simple_efficiency(rating*(1 + no_load_loss + load_loss),
5859
*args),
5960
rating,
61+
)
62+
63+
64+
def test_simple_efficiency_numpy_array_inputs():
65+
input_power = np.array([100.0, 500.0, 1000.0])
66+
no_load_loss = np.array([0.005, 0.005, 0.005])
67+
load_loss = np.array([0.01, 0.01, 0.01])
68+
rating = 1000.0
69+
70+
output_power = transformer.simple_efficiency(
71+
input_power=input_power,
72+
no_load_loss=no_load_loss,
73+
load_loss=load_loss,
74+
transformer_rating=rating
75+
)
76+
77+
assert isinstance(output_power, np.ndarray)
78+
assert output_power.shape == input_power.shape
79+
80+
def test_simple_efficiency_vector_equals_scalar():
81+
input_power = np.array([200.0, 600.0, 900.0])
82+
no_load_loss = 0.005
83+
load_loss = 0.01
84+
rating = 1000.0
85+
86+
vector_result = transformer.simple_efficiency(
87+
input_power=input_power,
88+
no_load_loss=no_load_loss,
89+
load_loss=load_loss,
90+
transformer_rating=rating
6091
)
92+
93+
scalar_result = np.array([
94+
transformer.simple_efficiency(p, no_load_loss, load_loss, rating)
95+
for p in input_power
96+
])
97+
98+
assert_allclose(vector_result, scalar_result)

0 commit comments

Comments
 (0)