Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mdmurbach committed Jan 11, 2019
1 parent d5f9fc9 commit e1b9ea3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.ipynb_checkpoints
*.DS_Store
*.json

impedance/__pycache__/
impedance/tests/__pycache__/
Expand Down
15 changes: 0 additions & 15 deletions impedance/tests/test_circuit_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,6 @@
import numpy as np


def correct_vals():
""" Creates the correct values for test_all() """
funcs = [R, C, W, A, E, G]
freqs = [0.001, 1.0, 1000]
input_vals = [0.1, 0.2]
inputs = [1, 1, 2, 1, 2, 2]
count = 0
val_list = []
for f in funcs:
val = f(input_vals[:inputs[count]], freqs)
val_list.append(list(val))
count += 1
return val_list


def test_all():
funcs = [R, C, W, A, E, G]
freqs = [0.001, 1.0, 1000]
Expand Down
23 changes: 23 additions & 0 deletions impedance/tests/test_model_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import numpy as np
from impedance.model_io import model_export, model_import
from impedance.circuits import CustomCircuit


def test_model_io():
# get example data
data = np.genfromtxt('./data/exampleData.csv', delimiter=',')

frequencies = data[:, 0]
Z = data[:, 1] + 1j*data[:, 2]

randles = CustomCircuit(initial_guess=[.01, .005, .1, .005, .1, .001, 200],
circuit='R_0-p(R_1,C_1)-p(R_1,C_1)-W_1/W_2')
randles.fit(frequencies, Z)

print(randles)

model_export(randles, './test_io.json')
randles2 = model_import('./test_io.json')
print(randles2)

assert randles == randles2
9 changes: 9 additions & 0 deletions impedance/tests/test_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from impedance.validation import calc_mu


def test_calc_mu():
Rs = [1, 2, 3, -3, -2, -1]
assert calc_mu(Rs) == 0

Rs = [-1, 2, 4, -3, 4, -1]
assert calc_mu(Rs) == 0.5

0 comments on commit e1b9ea3

Please sign in to comment.