예제 #1
0
 def test_print_state_print_correctly_when_is_end_true(self, mock_print):
     mass = MassSimulator()
     mass.config = {
         "title": "mass simulation test",
         "currency": "ETH",
         "description": "unit test config",
         "budget": 5000000,
         "strategy": "show me the money",
         "period_list": [{
             "start": "today",
             "end": "tomorrow"
         }],
     }
     mass.analyzed_result = (123.45, 456, 789, 10)
     mass.start = mass.last_print = datetime.now() - timedelta(seconds=4)
     mass.print_state(is_end=True)
     self.assertEqual(
         mock_print.call_args_list[0][0][0].find("simulation completed"),
         36)
     self.assertEqual(mock_print.call_args_list[2][0][0],
                      "수익률 평균:   123.45")
     self.assertEqual(mock_print.call_args_list[3][0][0],
                      "수익률 편차:      456")
     self.assertEqual(mock_print.call_args_list[4][0][0],
                      "수익률 최대:      789")
     self.assertEqual(mock_print.call_args_list[5][0][0],
                      "수익률 최소:       10")
예제 #2
0
 def test_print_state_print_correctly_when_is_start_true(self, mock_print):
     mass = MassSimulator()
     mass.config = {
         "title": "mass simulation test",
         "currency": "ETH",
         "description": "unit test config",
         "budget": 5000000,
         "strategy": "show me the money",
         "period_list": [{
             "start": "today",
             "end": "tomorrow"
         }],
     }
     mass.print_state(is_start=True)
     self.assertEqual(mock_print.call_args_list[1][0][0],
                      "Title: mass simulation test, Currency: ETH")
     self.assertEqual(mock_print.call_args_list[2][0][0],
                      "Description: unit test config")
     self.assertEqual(mock_print.call_args_list[3][0][0],
                      "Budget: 5000000, Strategy: show me the money")
     self.assertEqual(mock_print.call_args_list[4][0][0],
                      "today ~ tomorrow (1)")
     self.assertEqual(
         mock_print.call_args_list[6][0][0].find(
             "+0          simulation start!"), 24)
예제 #3
0
    def test_analyze_result_should_call_file_write_correctly(self, mock_file):
        mass = MassSimulator()
        dummy_config = {
            "title":
            "BnH-2Hour",
            "budget":
            50000,
            "strategy":
            0,
            "interval":
            1,
            "currency":
            "BTC",
            "description":
            "mass-simluation-unit-test",
            "period_list": [
                {
                    "start": "2020-04-30T17:00:00",
                    "end": "2020-04-30T19:00:00"
                },
                {
                    "start": "2020-04-30T18:00:00",
                    "end": "2020-04-30T20:00:00"
                },
            ],
        }
        dummy_result = [
            (0, 0, 1.12, 0, 0, 0, 2.99, 1.88),
            (0, 0, 2.25, 0, 0, 0, 1.99, -1.88),
            (0, 0, 2.01, 0, 0, 0, 4.99, 2.88),
        ]
        mass.draw_graph = MagicMock()
        mass.analyze_result(dummy_result, dummy_config)
        self.assertEqual(mock_file.call_args_list[1][0][0],
                         "output/BnH-2Hour.result")
        self.assertEqual(mock_file.call_args_list[1][0][1], "w")
        self.assertEqual(mock_file.call_args_list[1][1]["encoding"], "utf-8")

        handle = mock_file()
        expected = [
            "Title: BnH-2Hour\n",
            "Description: mass-simluation-unit-test\n",
            "Strategy: BnH, Budget: 50000, Currency: BTC\n",
            "2020-04-30T17:00:00 ~ 2020-04-30T20:00:00 (3)\n",
            "수익률 평균:    1.793\n",
            "수익률 편차:    0.595\n",
            "수익률 최대:     2.25,   1\n",
            "수익률 최소:     1.12,   0\n",
            "순번, 인덱스, 구간 수익률, 최대 수익률, 최저 수익률 ===\n",
            "   1,      1,        2.25,       -1.88,        1.99\n",
            "   2,      2,        2.01,        2.88,        4.99\n",
            "   3,      0,        1.12,        1.88,        2.99\n",
        ]

        for idx, val in enumerate(expected):
            self.assertEqual(
                handle.write.call_args_list[idx][0][0],
                val,
            )
        self.assertEqual(mass.analyzed_result[0], 1.793)
        self.assertEqual(mass.analyzed_result[1], 0.595)
        self.assertEqual(mass.analyzed_result[2], 2.25)
        self.assertEqual(mass.analyzed_result[3], 1.12)
        mass.draw_graph.assert_called_with([1.12, 2.25, 2.01],
                                           mean=1.793,
                                           filename="output/BnH-2Hour.jpg")
예제 #4
0
 def test__update_result_should_update_result_correctly(self):
     mass = MassSimulator()
     mass.result.append(0)
     mass._update_result([{"idx": 0, "result": "mango"}])
     self.assertEqual(mass.result[0], "mango")
예제 #5
0
 def test_print_state_print_correctly(self, mock_print):
     mass = MassSimulator()
     mass.start = mass.last_print = datetime.now() - timedelta(seconds=4)
     mass.print_state()
     self.assertEqual(
         mock_print.call_args[0][0].find("simulation is running"), 36)
예제 #6
0
    def test_run_should_call_run_simulation_correctly(self,
                                                      mock_set_stream_level):
        mass = MassSimulator()
        dummy_config = {
            "title":
            "BnH-2Hour",
            "budget":
            50000,
            "strategy":
            0,
            "interval":
            1,
            "currency":
            "BTC",
            "description":
            "mass-simluation-unit-test",
            "period_list": [
                {
                    "start": "2020-04-30T17:00:00",
                    "end": "2020-04-30T19:00:00"
                },
                {
                    "start": "2020-04-30T18:00:00",
                    "end": "2020-04-30T20:00:00"
                },
            ],
        }
        mass._load_config = MagicMock(return_value=dummy_config)
        mass.analyze_result = MagicMock()
        mass.print_state = MagicMock()
        mass._execute_simulation = MagicMock()
        mass.run("mass_config_file_name", 2)

        mass._load_config.assert_called_once_with("mass_config_file_name")
        self.assertEqual(
            mass._execute_simulation.call_args[0][0],
            [
                {
                    "title":
                    "BnH-2Hour",
                    "budget":
                    50000,
                    "strategy":
                    0,
                    "interval":
                    1,
                    "currency":
                    "BTC",
                    "partial_idx":
                    0,
                    "partial_period_list": [
                        {
                            "idx": 0,
                            "period": {
                                "start": "2020-04-30T17:00:00",
                                "end": "2020-04-30T19:00:00",
                            },
                        },
                    ],
                },
                {
                    "title":
                    "BnH-2Hour",
                    "budget":
                    50000,
                    "strategy":
                    0,
                    "interval":
                    1,
                    "currency":
                    "BTC",
                    "partial_idx":
                    1,
                    "partial_period_list": [
                        {
                            "idx": 1,
                            "period": {
                                "start": "2020-04-30T18:00:00",
                                "end": "2020-04-30T20:00:00",
                            },
                        },
                    ],
                },
            ],
        )
        self.assertEqual(mass._execute_simulation.call_args[0][1], 2)
        mass.analyze_result.assert_called_once_with(mass.result, dummy_config)
        mass.print_state.assert_called()
예제 #7
0
    def test_ITG_run_single_simulation(self, mock_print):
        mass = MassSimulator()

        mass.run("integration_tests/data/mass_simulation_config.json")