예제 #1
0
    def test_simulate__n_loop(self, mock_ui, mock_step, *_):
        mock_data = generate_data_mock()
        simulation = Simulation(mock_data)
        mock_step.side_effect = ([False] * 9) + [True]
        simulation.simulate()

        mock_ui.end.assert_called_once()
        self.assertEqual(mock_step.call_count, 10)
        self.assertEqual(simulation.month, 10)
예제 #2
0
    def test_simulate__single_loop(self, mock_ui, mock_step, *_):
        mock_data = generate_data_mock()
        simulation = Simulation(mock_data)
        mock_step.return_value = True
        simulation.simulate()

        mock_ui.end.assert_called_once()
        mock_step.assert_called_once()
        self.assertEqual(simulation.month, 1)
예제 #3
0
    def test_achieved_goal__false(self, mock_group_init, _):
        mock_group = Mock()
        mock_group.total_saved.return_value = Decimal('24000')
        mock_group_init.return_value = mock_group
        mock_data = generate_data_mock()
        simulation = Simulation(mock_data)
        simulation.savings_goal = Decimal('25000')

        result = simulation._achieved_goal()
        self.assertFalse(result)
예제 #4
0
    def test_step_forward__standard_month(self, mock_goal, mock_group_init, _):
        mock_group = Mock()
        mock_group.updated = False
        mock_group_init.return_value = mock_group
        mock_goal.return_value = False
        mock_data = generate_data_mock()
        simulation = Simulation(mock_data)
        simulation.month = 4

        result = simulation._step_forward()

        mock_group.simulate_month.assert_called_once()
        mock_goal.assert_called_once()
        mock_group.begin_year.assert_not_called()
        mock_group.end_year.assert_not_called()
        mock_group.strategise.assert_not_called()
        self.assertFalse(result)
예제 #5
0
    def test_init__single_mode(self, mock_group_init, mock_person_init):
        mock_data = generate_data_mock(group_mode=False)
        simulation = Simulation(mock_data)

        self.assertFalse(simulation.group_mode)
        self.assertEqual(simulation.savings_goal, Decimal('10000'))
        mock_person_init.assert_called_once()
        mock_group_init.assert_not_called()
예제 #6
0
    def test_step_forward__updated_and_goal_achieved_in_last_month(
            self, mock_goal, mock_group_init, _):
        mock_group = Mock()
        mock_group.updated = True
        mock_group_init.return_value = mock_group
        mock_goal.return_value = True
        mock_data = generate_data_mock()
        simulation = Simulation(mock_data)
        simulation.month = 12

        result = simulation._step_forward()

        mock_group.simulate_month.assert_called_once()
        mock_goal.assert_called_once()
        mock_group.begin_year.assert_not_called()
        mock_group.end_year.assert_not_called()
        mock_group.strategise.assert_not_called()
        self.assertTrue(result)
예제 #7
0
    def test_init__goal_not_provided(self, mock_ui, mock_group_init,
                                     mock_person_init):
        mock_data = generate_data_mock(group_mode=True, savings_goal=None)
        mock_ui.obtain_savings_goal.return_value = Decimal('25000')
        simulation = Simulation(mock_data)

        self.assertEqual(simulation.savings_goal, Decimal('25000'))
        mock_group_init.assert_called_once()
        mock_person_init.assert_not_called()
        mock_ui.obtain_savings_goal.assert_called_once()
예제 #8
0
파일: main.py 프로젝트: rhysb27/finsim
from finsim.ui import UI
from finsim.simulation import Simulation
from finsim.sim_data import SimData

UI.initialise()
sim_data = SimData()
simulation = Simulation(sim_data)

UI.begin()
simulation.simulate()