From e1b9ea3e3ac7fd66779f6138f7ec594e194abfd1 Mon Sep 17 00:00:00 2001 From: Matt Murbach Date: Fri, 11 Jan 2019 15:48:25 -0800 Subject: [PATCH] add tests --- .gitignore | 1 + impedance/tests/test_circuit_elements.py | 15 --------------- impedance/tests/test_model_io.py | 23 +++++++++++++++++++++++ impedance/tests/test_validation.py | 9 +++++++++ 4 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 impedance/tests/test_model_io.py create mode 100644 impedance/tests/test_validation.py diff --git a/.gitignore b/.gitignore index 7b6190f0..e3e79b56 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.ipynb_checkpoints *.DS_Store +*.json impedance/__pycache__/ impedance/tests/__pycache__/ diff --git a/impedance/tests/test_circuit_elements.py b/impedance/tests/test_circuit_elements.py index 8af024d2..52325b52 100644 --- a/impedance/tests/test_circuit_elements.py +++ b/impedance/tests/test_circuit_elements.py @@ -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] diff --git a/impedance/tests/test_model_io.py b/impedance/tests/test_model_io.py new file mode 100644 index 00000000..e80c557c --- /dev/null +++ b/impedance/tests/test_model_io.py @@ -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 diff --git a/impedance/tests/test_validation.py b/impedance/tests/test_validation.py new file mode 100644 index 00000000..47bac58c --- /dev/null +++ b/impedance/tests/test_validation.py @@ -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