Exemple #1
0
    def test_add_multiple_to_dict(self):

        d = {}
        line_1 = "1|NASDAQ|-1234.56"
        hour, stock, price = ip.format_line(line_1)
        ip.add_stockline_to_dict(d, hour, stock, price)
        d_true = {stock: {hour: price}}

        line_2 = "2|ABCDEF|789.10"
        hour, stock, price = ip.format_line(line_2)
        ip.add_stockline_to_dict(d, hour, stock, price)
        d_true[stock] = {hour: price}

        self.assertEqual(d, d_true)
Exemple #2
0
    def test_makes_correct_output(self):

        example_actual = [
            "1|SLKWVA|94.51",
            "1|CMWTQH|81.27",
            "1|ATAYJP|25.74",
            "1|HVIWZR|22.81",
            "2|ATAYJP|29.62",
            "2|SLKWVA|81.87",
            "2|CMWTQH|116.11",
            "2|HVIWZR|22.15",
            "3|ATAYJP|21.93",
            "3|HVIWZR|22.24",
            "3|SLKWVA|78.01",
            "3|CMWTQH|113.63",
        ]

        example_predicted = [
            "1|ATAYJP|25.71",
            "1|HVIWZR|22.80",
            "1|SLKWVA|94.49",
            "1|CMWTQH|81.22",
            "2|ATAYJP|29.92",
            "2|HVIWZR|22.06",
            "3|ATAYJP|21.84",
            "3|HVIWZR|22.36",
            "3|SLKWVA|79.49",
        ]

        actual = [ip.format_line(line) for line in example_actual]
        acutal_dict = {}
        for line in actual:
            hour, stock, price = line[0], line[1], line[2]
            ip.add_stockline_to_dict(acutal_dict, hour, stock, price)

        predicted = [ip.format_line(line) for line in example_predicted]
        predicted_dict = {}
        for line in predicted:
            hour, stock, price = line[0], line[1], line[2]
            ip.add_stockline_to_dict(predicted_dict, hour, stock, price)

        current_hour = 1
        hour_1_error = ip.get_hour_error(acutal_dict, predicted_dict,
                                         current_hour)
        hour_1_error_true = (0.11, 4)

        self.assertAlmostEqual(hour_1_error[0], hour_1_error_true[0])
        self.assertEqual(hour_1_error[1], hour_1_error_true[1])
Exemple #3
0
    def test_add_to_empty_dict(self):

        d = {}
        line = "1|NASDAQ|-1234.56"
        hour, stock, price = ip.format_line(line)
        ip.add_stockline_to_dict(d, hour, stock, price)
        d_true = {stock: {hour: price}}
        self.assertEqual(d, d_true)
Exemple #4
0
    def test_deletes_in_place(self):

        d = {}
        line = "1|NASDAQ|-1234.56"
        hour, stock, price = ip.format_line(line)
        ip.add_stockline_to_dict(d, hour, stock, price)
        ip.del_hour_from_dict(d, hour)
        d_true = {stock: {}}
        self.assertEqual(d, d_true)
Exemple #5
0
    def test_makes_correct_output(self):

        line = "1|NASDAQ|-1234.56"
        self.assertEqual([1, "NASDAQ", -1234.56], ip.format_line(line))