<filename>tests/test_accumulation_distribution.py
from __future__ import absolute_import
import unittest
import numpy as np

from tests.sample_data import SampleData
from pyti import accumulation_distribution


class TestAccumulationDistribution(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.high_data = SampleData().get_sample_high_data()
        self.low_data = SampleData().get_sample_low_data()
        self.volume = SampleData().get_sample_volume()

        self.ad_expected = [0.0, 15862.38524593231, -36477.702708130804,
        -104733.80651442676, 40104.71949712043, 23939.254528920741,
        -62106.183239279555, 112915.24595464926, 39956.002218866488,
        -260.35553975040239, -116475.2497883655, -154687.74497142577,
        -292093.679550856, -133194.90662509997, -263680.69609877974,
        -299353.08397758257, -261929.08397757346, -320893.80364286253,
        -471609.22532958613, -708827.18185129401, -694912.50378286431,
        -792540.18692894513, -777300.311457203, -699904.16262002871,
        -790925.63820386841, -889485.5941157171, -805433.69146085251,
        -833917.85340419237, -833917.85340416594, -883999.91462867253,
        -1022927.0306024188, -1054143.0894259787, -1058939.2259721591,
        -1021271.5606829068, -913860.42762679141, -1035092.7994216527,
        -935298.84023796313, -792598.06027727341, -709809.99197603366,
        -577648.68356478063, -712915.33741098049, -1014517.9000277666,
        -729489.82981907623, -732989.08876652108, -437866.62941692042,
        -292705.11886841164, -208275.03902052308, -57775.565753187257,
        -41895.022706843985, -197234.22345034953, -217259.22123303646,
        -336135.09482219844, -340737.15732219425, -345832.65519452997,
        -282367.61014945683, -503852.77093379293, -542493.46938165138,
        -293054.95086318324, -349241.3657770899, -310266.53503439715,
        -427254.58609822171, -379701.86011959275, -245746.2914921554,
        -197685.67265809805, -201802.46902173068, -174468.61134385251,
        12276.114846627315, -21316.018077706984, -411927.14032219525,
        -465339.18257566751, -517829.09090903884, -526077.9668780705,
        -638881.56860968971, -535937.62266374112, -422292.58075894287,
        -585404.44057200733, -641343.11799134617, -442699.23563839833,
        -237900.56329794819, -15646.76484828876, 257481.51413010465,
        266545.23366587964, 296702.51703821769, 382165.68335837772,
        433020.58124570741, 559763.67215474963, 556301.17746264767,
        683881.16259275773, 671412.22763338394, 702418.43452995166,
        1269915.1092287663, 1369598.1903099443, 1813632.4712087966,
        1418193.9507626847, 1357868.9773113495, 1173146.9130543284,
        1370686.1802957729, 1559763.227204062, 1799516.493737207,
        1532620.7033441989, 1699573.5379898732, 1690914.5457118889,
        2050665.8326683058, 2199638.0771572837, 2242714.9091572445,
        2255814.5304043461, 2304978.8473854959, 2178583.2490768656,
        2209187.1812126297, 2279663.6510112993, 2416336.1883247532,
        2392955.8321879292, 2448552.5321879075, 2399441.1061789142,
        2494347.2758041751, 2406478.6085073589, 2498297.9406373627,
        2479423.9027995183, 2386354.6797225843, 2295492.9138876535,
        2280017.0204450153, 2238485.2116801129, 2242266.9907233468,
        2141284.6836367347, 2083933.3361190266, 2027200.0996044902,
        1922004.9567473496]

    def test_accumulation_distribution(self):
        ad = accumulation_distribution.accumulation_distribution(self.close_data, self.high_data, self.low_data, self.volume)
        np.testing.assert_array_equal(ad, self.ad_expected)

    def test_ad_invalid_data(self):
        self.close_data.append(1)
        with self.assertRaises(Exception) as cm:
            accumulation_distribution.accumulation_distribution(self.close_data, self.high_data, self.low_data, self.volume)
        expected = ("Error: mismatched data lengths, check to ensure that all input data is the same length and valid")
        self.assertEqual(str(cm.exception), expected)

<filename>tests/test_accumulation_distribution.py
from __future__ import absolute_import
import unittest
import numpy as np

from tests.sample_data import SampleData
from pyti import accumulation_distribution


class TestAccumulationDistribution(unittest.TestCase):
    def setUp(self):
        """Create data to use for testing."""
        self.close_data = SampleData().get_sample_close_data()
        self.high_data = SampleData().get_sample_high_data()
        self.low_data = SampleData().get_sample_low_data()
        self.volume = SampleData().get_sample_volume()

        self.ad_expected = [0.0, 15862.38524593231, -36477.702708130804,
        -104733.80651442676, 40104.71949712043, 23939.254528920741,
        -62106.183239279555, 112915.24595464926, 39956.002218866488,
        -260.35553975040239, -116475.2497883655, -154687.74497142577,
        -292093.679550856, -133194.90662509997, -263680.69609877974,
        -299353.08397758257, -261929.08397757346, -320893.80364286253,
        -471609.22532958613, -708827.18185129401, -694912.50378286431,
        -792540.18692894513, -777300.311457203, -699904.16262002871,
        -790925.63820386841, -889485.5941157171, -805433.69146085251,
        -833917.85340419237, -833917.85340416594, -883999.91462867253,
        -1022927.0306024188, -1054143.0894259787, -1058939.2259721591,
        -1021271.5606829068, -913860.42762679141, -1035092.7994216527,
        -935298.84023796313, -792598.06027727341, -709809.99197603366,
        -577648.68356478063, -712915.33741098049, -1014517.9000277666,
        -729489.82981907623, -732989.08876652108, -437866.62941692042,
        -292705.11886841164, -208275.03902052308, -57775.565753187257,
        -41895.022706843985, -197234.22345034953, -217259.22123303646,
        -336135.09482219844, -340737.15732219425, -345832.65519452997,
        -282367.61014945683, -503852.77093379293, -542493.46938165138,
        -293054.95086318324, -349241.3657770899, -310266.53503439715,
        -427254.58609822171, -379701.86011959275, -245746.2914921554,
        -197685.67265809805, -201802.46902173068, -174468.61134385251,
        12276.114846627315, -21316.018077706984, -411927.14032219525,
        -465339.18257566751, -517829.09090903884, -526077.9668780705,
        -638881.56860968971, -535937.62266374112, -422292.58075894287,
        -585404.44057200733, -641343.11799134617, -442699.23563839833,
        -237900.56329794819, -15646.76484828876, 257481.51413010465,
        266545.23366587964, 296702.51703821769, 382165.68335837772,
        433020.58124570741, 559763.67215474963, 556301.17746264767,
        683881.16259275773, 671412.22763338394, 702418.43452995166,
        1269915.1092287663, 1369598.1903099443, 1813632.4712087966,
        1418193.9507626847, 1357868.9773113495, 1173146.9130543284,
        1370686.1802957729, 1559763.227204062, 1799516.493737207,
        1532620.7033441989, 1699573.5379898732, 1690914.5457118889,
        2050665.8326683058, 2199638.0771572837, 2242714.9091572445,
        2255814.5304043461, 2304978.8473854959, 2178583.2490768656,
        2209187.1812126297, 2279663.6510112993, 2416336.1883247532,
        2392955.8321879292, 2448552.5321879075, 2399441.1061789142,
        2494347.2758041751, 2406478.6085073589, 2498297.9406373627,
        2479423.9027995183, 2386354.6797225843, 2295492.9138876535,
        2280017.0204450153, 2238485.2116801129, 2242266.9907233468,
        2141284.6836367347, 2083933.3361190266, 2027200.0996044902,
        1922004.9567473496]

    def test_accumulation_distribution(self):
        ad = accumulation_distribution.accumulation_distribution(self.close_data, self.high_data, self.low_data, self.volume)
        np.testing.assert_array_equal(ad, self.ad_expected)

    def test_ad_invalid_data(self):
        self.close_data.append(1)
        with self.assertRaises(Exception) as cm:
            accumulation_distribution.accumulation_distribution(self.close_data, self.high_data, self.low_data, self.volume)
        expected = ("Error: mismatched data lengths, check to ensure that all input data is the same length and valid")
        self.assertEqual(str(cm.exception), expected)

Create data to use for testing.