示例#1
0
    def test___getitem___slice(self):
        ts = TimeSeries(init=self.__valid_initial_data[0])
        actual_ts = ts[self.__valid_initial_data[0][1][0]:]

        expected_ts = TimeSeries(init=self.__valid_initial_data[0][1:])

        self.assertEqual(actual_ts, expected_ts)
示例#2
0
    def test___delitem___normal(self):
        actual_ts = TimeSeries(init=self.__valid_initial_data[0])
        del actual_ts[self.__valid_initial_data[0][0][0]]

        expected_ts = TimeSeries(init=self.__valid_initial_data[0][1:])

        self.assertEqual(actual_ts, expected_ts)
示例#3
0
    def test_remove_normal(self):
        actual_ts = TimeSeries(init=self.__valid_initial_data[0])
        actual_ts.remove(self.__valid_initial_data[0][0][0])

        expected_ts = TimeSeries(init=self.__valid_initial_data[0][1:])

        self.assertEqual(actual_ts, expected_ts)
示例#4
0
    def test___sub___normal(self):
        a = TimeSeries(init=self.__valid_initial_data[0])
        b = TimeSeries(init=self.__valid_initial_data[0])
        c = a - b

        expected_ts = TimeSeries()

        self.assertEqual(c, expected_ts)
示例#5
0
    def test___setitem___not_found(self):
        actual_ts = TimeSeries(init=self.__valid_initial_data[0])
        actual_ts[self.__not_found_key] = self.__not_found_value

        data = deepcopy(self.__valid_initial_data[0])
        data.append((self.__not_found_key, self.__not_found_value))
        expected_ts = TimeSeries(init=data)

        self.assertEqual(actual_ts, expected_ts)
示例#6
0
    def test___getitem___normal(self):
        actual_ts = TimeSeries(init=self.__valid_initial_data[0])
        actual_item = actual_ts[self.__valid_initial_data[0][0][0]]

        expected_ts = TimeSeries(init=self.__valid_initial_data[0])
        expected_item = self.__valid_initial_data[0][0][1]

        self.assertEqual(actual_item, expected_item)
        self.assertEqual(len(actual_ts), len(expected_ts))
示例#7
0
    def test___add___normal(self):
        a = TimeSeries(init=self.__valid_initial_data[0])
        b = TimeSeries(init=self.__valid_initial_data[1])
        c = a + b

        expected_ts = TimeSeries(init=self.__valid_initial_data[0] +
                                 self.__valid_initial_data[1])

        self.assertEqual(c, expected_ts)
示例#8
0
    def test_insert_normal(self):
        actual_ts = TimeSeries(init=self.__valid_initial_data[0])
        actual_ts.insert(self.__not_found_key, self.__not_found_value)

        expected_values = deepcopy(self.__valid_initial_data[0])
        expected_values.append((self.__not_found_key, self.__not_found_value))

        expected_ts = TimeSeries(init=expected_values)

        self.assertEqual(actual_ts, expected_ts)
示例#9
0
    def test___iter___normal(self):
        actual_ts = TimeSeries(init=self.__valid_initial_data[0])

        actual_items = []

        for k, v in actual_ts:
            actual_items.append((k, v))

        expected_items = deepcopy(self.__valid_initial_data[0])

        expected_ts = TimeSeries(init=expected_items)

        self.assertEqual(actual_items, expected_items)
        self.assertEqual(actual_ts, expected_ts)
示例#10
0
    def test___setitem___normal(self):
        actual_ts = TimeSeries(init=self.__valid_initial_data[0])
        actual_ts[self.__valid_initial_data[0][0]
                  [0]] = self.__valid_initial_data[0][1][1]

        self.assertEqual(actual_ts[self.__valid_initial_data[0][0][0]],
                         self.__valid_initial_data[0][1][1])
示例#11
0
class TestAsset(unittest.TestCase):
    __valid_asset_name = "Tulips"
    __valid_ts_data = [(datetime(2018, 1, 1),
                        OHLCVData(1.00, 2.43, 0.52, 1.50, 100)),
         (datetime(2018, 1, 2), OHLCVData(2.00, 2.05, 1.95, 2.00, 5400))]

    __valid_asset_prices = TimeSeries(init=__valid_ts_data)

    def test___init___normal(self):
        actual_asset = Asset(self.__valid_asset_name, self.__valid_asset_prices)

        expected_asset = Asset(self.__valid_asset_name,
                               self.__valid_asset_prices)

        self.assertEqual(actual_asset, expected_asset)

    def test_name_normal(self):
        asset = Asset(self.__valid_asset_name, self.__valid_asset_prices)
        actual_name = asset.name

        expected_name = self.__valid_asset_name

        self.assertEqual(actual_name, expected_name)

    def test_prices_normal(self):
        asset = Asset(self.__valid_asset_name, self.__valid_asset_prices)
        actual_prices = asset.prices

        expected_prices = self.__valid_asset_prices

    def test___repr___normal(self):
        asset = Asset(self.__valid_asset_name, self.__valid_asset_prices)
        actual_representation = repr(asset)

        expected_representation = self.__valid_asset_name

        self.assertEqual(actual_representation, expected_representation)

    def test_price_at_normal(self):
        asset = Asset(self.__valid_asset_name, self.__valid_asset_prices)
        actual_price = asset.price_at(datetime(2018, 1, 2))

        expected_price = self.__valid_asset_prices[datetime(2018, 1, 2)]

        self.assertEqual(actual_price, expected_price)
示例#12
0
    def test___eq___unequal(self):
        a = TimeSeries(init=self.__valid_initial_data[0])
        b = TimeSeries(init=self.__valid_initial_data[1])

        self.assertFalse(a == b)
示例#13
0
    def test___eq___normal(self):
        a = TimeSeries(init=self.__valid_initial_data[0])
        b = TimeSeries(init=self.__valid_initial_data[0])

        self.assertTrue(a == b)
示例#14
0
    def test___delitem___not_found(self):
        actual_ts = TimeSeries(init=self.__valid_initial_data[0])

        with self.assertRaises(KeyError):
            del actual_ts[self.__not_found_key]
示例#15
0
    def test___init___initial_data(self):
        actual_ts = TimeSeries(init=self.__valid_initial_data[0])

        expected_ts = TimeSeries(init=self.__valid_initial_data[0])

        self.assertEqual(actual_ts, expected_ts)
示例#16
0
    def test___init___normal(self):
        actual_ts = TimeSeries()

        expected_ts = TimeSeries()

        self.assertEqual(actual_ts, expected_ts)