Пример #1
0
 def test_multiplica(self):
     """
     Target function returns the sum of the multilica of two given vector.
     Expect output as np.float object.
     """
     dict_1, n, param = file_read.read_file(
         './data/10mM_2,7-AQDS_1M_KOH_25mVs_0.5step_2.txt')
     data = file_read.data_frame(dict_1, 1)
     col_x1, col_x2 = baseline.split(data.Potential, param)
     col_y1, col_y2 = baseline.split(data.Current, param)
     a_val = baseline.multiplica(col_x1, col_y1)
     assert isinstance(a_val, np.float64), \
         "Output should be float object, but fuction is returning{}".format(
         type(a_val))
     b_val = np.multiply(col_x1, col_y1).sum()
     np.testing.assert_almost_equal(a_val, b_val, decimal=3), \
         "Calculation is incorrect"
     return "Test Passed for multiplica function!"
Пример #2
0
def test_critical_idx():
    """
    Critical_idx returns idx of the index of the intercepts of different moving average curves.
    Test the output if it is a single index.
    Test if the output is integer.
    Test if the index exist in original input.
    """
    dict_1 = file_read.read_file(
        '../../data/10mM_2,7-AQDS_1M_KOH_25mVs_0.5step_2.txt')
    data = file_read.data_frame(dict_1, 1)
    col_x1, col_x2 = baseline.split(data.Potential)
    col_y1, col_y2 = baseline.split(data.Current)
    idx = baseline.critical_idx(col_x1, col_y1)
    assert isinstance(idx == np.int64), ("Output should be integer, but"
                                         "Function is returning {}".format(
                                             type(idx)))
    assert idx.shape == (), "This function should return single idx"
    assert 0 < idx < len(col_x1), "Output index is out of order"
    return "Test of critical_idx function passed!"
Пример #3
0
 def test_sum_mean(self):
     """
     Target function returns the mean and sum of the given vector.
     Expect output to be a list, with length 2.
     Can also test if the mean is correctly calculated.
     """
     dict_1, n, param = file_read.read_file(
         './data/10mM_2,7-AQDS_1M_KOH_25mVs_0.5step_2.txt')
     data = file_read.data_frame(dict_1, 1)
     col_x1, col_x2 = baseline.split(data.Potential, param)
     a_val = baseline.sum_mean(np.array(col_x1))
     assert isinstance(a_val, list), \
         "Output should be list object, but fuction is returning{}".format(
         type(a_val))
     assert len(a_val) == 2, \
         "length of output should be 2, but function is returning a" +\
         "list with length{}".format(len(a_val))
     np.testing.assert_almost_equal(a_val[1], np.mean(col_x1), decimal=3), \
         "Mean is calculated incorrectly"
     return "Test of sum_mean function passed!"
Пример #4
0
 def test_linear_background(self):
     """
     Target function is wrapping function which returns
     linear fitted line.Should exam if the output is
     correct shape, correct type, and correct value.
     """
     dict_1, n, param = file_read.read_file(
         './data/10mM_2,7-AQDS_1M_KOH_25mVs_0.5step_2.txt')
     data = file_read.data_frame(dict_1, 1)
     col_x1, col_x2 = baseline.split(data.Potential, param)
     col_y1, col_y2 = baseline.split(data.Current, param)
     y_fit = baseline.linear_background(col_x1, col_y1)
     assert isinstance(y_fit, list), "Output should be list object"
     if len(y_fit) != len(col_x1):
         raise ValueError("Output must have same length as input x,"
                          "but have lenth {}".format(len(y_fit)))
     if len(y_fit) != len(col_y1):
         raise ValueError("Output must have same length as input y,"
                          "but have lenth {}".format(len(y_fit)))
     return "Test passed for linear_background function!"
Пример #5
0
 def test_split(self):
     """
     This function tests the split function.
     The output of the function has to be np.array.
     Split function splits the length of input vector
     in two. So, len of output should equal to half len
     of input.
     """
     dict_1, n, param = file_read.read_file(
         './data/10mM_2,7-AQDS_1M_KOH_25mVs_0.5step_2.txt')
     data = file_read.data_frame(dict_1, 1)
     vec_x = data.Potential
     a_val, b_val = baseline.split(vec_x, param)
     assert isinstance(a_val, np.ndarray), "The output type is incorrect."
     assert isinstance(b_val, np.ndarray), "The output type is incorrect."
     # assert len(a)  int(len(x)/2), "The output should be "
     np.testing.assert_almost_equal(len(a_val), (len(vec_x)/2), decimal=0),\
         "Output length is incorrect"
     np.testing.assert_almost_equal(len(b_val), (len(vec_x)/2), decimal=0),\
         "Output length is incorrect"
     return "Test of split function passed!"
Пример #6
0
"""This module tests the calculation functions."""
import numpy as np
import pandas as pd
import unittest
from voltcycle import calculations
from voltcycle import file_read

# param = {'vinit(V)': 0.0, 'vlimit_1(V)': -1.5, 'vlimit_2(V)': 0.0,
#          'vfinal(V)': 0.0, 'scan_rate(mV/s)': 499.999, 'step_size(V)': 0.008}

dict_1, n, param = file_read.read_file(
    './data/10mM_2,7-AQDS_1M_KOH_25mVs_0.5step_2.txt')
data = file_read.data_frame(dict_1, 1)
potentials_d = pd.DataFrame(data.Potential)
currents_d = pd.DataFrame(data.Current)


class TestSimulationTools(unittest.TestCase):
    def test_peak_values(self):
        """This function tests peak_values() function."""

        # dict_1, n, param = file_read.read_file(
        #     './data/10mM_2,7-AQDS_1M_KOH_25mVs_0.5step_2.txt')
        # data = file_read.data_frame(dict_1, 1)
        # potentials_d = pd.DataFrame(data.Potential)
        # currents_d = pd.DataFrame(data.Current)

        assert isinstance(calculations.peak_values(
            potentials_d, currents_d, param), np.ndarray), \
            "output is not an array"
        # assert calculations.peak_values(potentials_d, currents_d, param)[0] \