Пример #1
0
 def test_CurrentAndSavedInterface_get_label_non_empty(self):
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.assertEqual(self.interface.get_label_saved(),
                      [('1D1', [(1, 1)]), ('2D1', [(2, 1)])])
Пример #2
0
 def test_ChangeBox_display_normal(self):
     self.DTM.request_add(2, dt.Die(100))
     self.DTM.request_add(1, dt.Die(101))
     expected = [
         (['-5', '-1', '2D100', '+1', '+5'], dt.Die(100)),
         (['-1', '1D101', '+1'], dt.Die(101))]
     self.assertEqual(self.CB.display(), expected)
Пример #3
0
 def test_graph_box_reload_does_nothing_if_obj_not_in_hist(self):
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(1))
     current_state = self.TM.request_plot_obj(False)
     self.GB.reload('abc', [(1, 2)])
     self.assertEqual(self.TM.request_plot_obj(False), current_state)
Пример #4
0
 def test_CurrentAndSavedInterface_get_requested_gets_current(self):
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.DTM.request_add(1, dt.Die(1))
     from_interface = self.interface.get_requested([('1D1', [(1, 1)]), ('2D1', [(2, 1)])])
     self.assertEqual(from_interface, [fh.SavedDiceTable('1D1', [(1, 1)], [], []),
                                       fh.SavedDiceTable('2D1', [(2, 1)], [], [])])
Пример #5
0
    def test_graph_box_reload_works_as_expected(self):
        self.TM.request_add(1, dt.Die(1))
        obj = self.TM.request_plot_obj(True)
        self.HM.add_plot_obj(obj)
        self.TM.request_add(1, dt.Die(2))

        self.GB.reload('1D1', [(1, 1)])
        self.assertEqual(self.TM.request_plot_obj(True), obj)
Пример #6
0
 def test_CurrentAndSavedInterface_delete_requested_writes_to_file(self):
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.interface.delete_requested([('1D1', [(1, 1)])])
     self.ST.reload_from_file()
     self.assertEqual(self.ST.get_labels(), [('2D1', [(2, 1)])])
Пример #7
0
 def test_get_graphs_pts(self):
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.assertEqual(mvm.get_graphs(self.ST.get_all(), get_axes_not_pts=False),
                      ((1, 2), (100.0, 100.0),
                       [('1D1', [(1, 100.0)]), ('2D1', [(2, 100.0)])]))
Пример #8
0
 def test_GraphBox_get_requested_graphs_non_empty(self):
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.DTM.request_add(1, dt.Die(1))
     to_test = self.GB.get_requested_graphs([('2D1', [(2, 1)]), ('not there', [(1, 1)])])
     self.assertEqual(to_test, ((2, 2),
                                (100.0, 100.0),
                                [('2D1', [(2, ), (100.0, )])]))
Пример #9
0
 def test_SavedTables_get_labels_returns_as_expected(self):
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.DTM.request_add(1, dt.Die(2))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.assertEqual(
         self.ST.get_labels(),
         [('1D1', [(1, 1)]), ('1D1 \\ 1D2', [(2, 1), (3, 1)])])
Пример #10
0
 def test_history_manager_get_labels_returns_as_expected(self):
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(2))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.assertEqual(
         self.HM.get_labels(),
         [('1D1', [(1, 1)]), ('1D1 \\ 1D2', [(2, 1), (3, 1)])])
Пример #11
0
 def test_table_manager_request_plot_obj_use_axes(self):
     self.TM.request_add(1, dt.Die(2))
     self.TM.request_add(1, dt.Die(4))
     plot_obj = {'text': '1D2 \\ 1D4', 'x_range': (2, 6),
                 'y_range': (12.5, 25.0),
                 'dice': [(dt.Die(2), 1), (dt.Die(4), 1)],
                 'tuple_list': [(2, 1), (3, 2), (4, 2), (5, 2), (6, 1)],
                 'pts': [(2, 3, 4, 5, 6), (12.5, 25.0, 25.0, 25.0, 12.5)]}
     self.assertEqual(self.TM.request_plot_obj(True), plot_obj)
Пример #12
0
 def test_graph_box_display_returns_as_expected(self):
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(2))
     expected = (('2D1 \\ 1D2', [(3, 1), (4, 1)]),
                 [('1D1', [(1, 1)]), ('2D1', [(2, 1)])])
     self.assertEqual(self.GB.display(), expected)
Пример #13
0
 def test_DiceTableManager_request_reload(self):
     table = dt.DiceTable()
     table.add_die(1, dt.Die(2))
     table.add_die(1, dt.Die(4))
     data_obj = fh.SavedDiceTable('1D2 \\ 1D4', table.frequency_all(), table.get_list(), [])
     self.DTM.request_reload(data_obj)
     self.assertEqual(self.DTM.title, '1D2\n1D4')
     self.assertEqual(self.DTM.full_text,
                      '2: 1\n3: 2\n4: 2\n5: 2\n6: 1\n')
Пример #14
0
 def test_GraphBox_get_all_graphs(self):
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.DTM.request_add(1, dt.Die(1))
     to_test = self.GB.get_all_graphs()
     self.assertEqual(to_test, ((1, 2),
                                (100.0, 100.0),
                                [('1D1', [(1, ), (100.0, )]),
                                 ('2D1', [(2,), (100.0,)])]))
Пример #15
0
 def test_SavedTables_get_all_works(self):
     self.assertEqual(self.ST.get_all(), [])
     self.DTM.request_add(1, dt.Die(2))
     obj_1 = self.DTM.get_obj_to_save()
     self.ST.save_new(obj_1)
     self.DTM.request_add(1, dt.Die(2))
     obj_2 = self.DTM.get_obj_to_save()
     self.ST.save_new(obj_2)
     self.assertEqual(self.ST.get_all(), [obj_1, obj_2])
Пример #16
0
 def test_check_data_all_die_types_pass(self):
     table = dt.DiceTable()
     table.add_die(1, dt.Die(4))
     table.add_die(1, dt.ModDie(4, 2))
     table.add_die(1, dt.WeightedDie({1: 2}))
     table.add_die(1, dt.ModWeightedDie({1: 2}, 3))
     table.add_die(1, dt.StrongDie(dt.Die(3), 3))
     obj = create_plot_object(table)
     self.assertEqual(fh.check_data(obj), 'ok')
Пример #17
0
 def test_graph_box_graph_it_retrieves_from_HM_not_TM(self):
     self.TM.request_add(1, dt.Die(2))
     obj_1 = self.TM.request_plot_obj(True)
     self.HM.add_plot_obj(obj_1)
     #populating HM and TM with different stuff
     self.TM.request_add(1, dt.Die(3))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(5))
     text_pts = self.GB.graph_it([('1D2', [(1, 1), (2, 1)])])[2]
     self.assertEqual(text_pts, [('1D2', [(1, 2), (50.0, 50.0)])])
Пример #18
0
 def test_graph_box_clear_selected_works_as_expected(self):
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(2))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.GB.clear_selected([('2D1', [(2, 1)]),
                             ('2D1 \\ 1D2', [(3, 1), (4, 1)])])
     self.assertEqual(self.HM.get_labels(), [('1D1', [(1, 1)])])
Пример #19
0
 def test_graph_box_clear_all_works_and_writes_empty_history(self):
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(2))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.GB.clear_all()
     self.assertEqual(self.HM.get_labels(), [])
     self.assertEqual(np.load('numpy_history.npy').size, 0)
Пример #20
0
 def test_table_manager_request_reload(self):
     plot_obj = {'text': '1D2 \\ 1D4', 'x_range': (2, 6),
                 'y_range': (12.5, 25.0),
                 'dice': [(dt.Die(2), 1), (dt.Die(4), 1)],
                 'tuple_list': [(2, 1), (3, 2), (4, 2), (5, 2), (6, 1)],
                 'pts': ([2, 3, 4, 5, 6], [12.5, 25.0, 25.0, 25.0, 12.5])}
     self.TM.request_reload(plot_obj)
     self.assertEqual(self.TM.request_info('text'), '1D2\n1D4')
     self.assertEqual(self.TM.request_info('full_text'),
                      '2: 1\n3: 2\n4: 2\n5: 2\n6: 1\n')
Пример #21
0
 def test_SavedTables_delete_selected_works_as_expected(self):
     self.DTM.request_add(1, dt.Die(1))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.DTM.request_add(1, dt.Die(2))
     self.ST.save_new(self.DTM.get_obj_to_save())
     self.DTM.request_add(1, dt.Die(3))
     self.ST.save_new(self.DTM.get_obj_to_save())
     del_1, keep, del_2 = self.ST.get_labels()
     self.ST.delete_requested([del_1, del_2])
     self.assertEqual(self.ST.get_labels(), [keep])
Пример #22
0
 def test_read_write_saved_tables_array_work_ok_for_normal_case(self):
     table = dt.DiceTable()
     table.add_die(1, dt.Die(3))
     obj1 = create_saved_dice_table(table)
     table.add_die(2, dt.Die(5))
     obj2 = create_saved_dice_table(table)
     save_data = np.array([obj1, obj2])
     fh.write_saved_tables_array(save_data)
     msg, new_save_data = fh.read_saved_tables_array()
     self.assertEqual(msg, 'ok')
     self.assertArrayEqual(save_data, new_save_data)
Пример #23
0
 def test_read_write_hist_np_work_ok_for_normal_case(self):
     table = dt.DiceTable()
     table.add_die(1, dt.Die(3))
     obj1 = create_plot_object(table)
     table.add_die(2, dt.Die(5))
     obj2 = create_plot_object(table)
     hist = np.array([obj1, obj2])
     fh.write_history_np(hist)
     msg, new_hist = fh.read_history_np()
     self.assertEqual(msg, 'ok')
     self.assertArrayEqual(hist, new_hist)
Пример #24
0
 def test_history_manager_clear_selected__works_as_expected(self):
     self.TM.request_add(1, dt.Die(1))
     obj_1 = self.TM.request_plot_obj(True)
     self.TM.request_add(1, dt.Die(2))
     obj_2 = self.TM.request_plot_obj(True)
     self.TM.request_add(1, dt.Die(3))
     obj_3 = self.TM.request_plot_obj(True)
     self.HM.add_plot_obj(obj_1)
     self.HM.add_plot_obj(obj_2)
     self.HM.add_plot_obj(obj_3)
     self.HM.clear_selected([obj_1, obj_3])
     self.assertEqual(self.HM.get_labels(),
                      [(obj_2['text'], obj_2['tuple_list'])])
Пример #25
0
 def test_history_manager_get_graphs(self):
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.assertEqual(
         self.HM.get_graphs(),
         (
             (1, 2),
             (100.0, 100.0),
             [('1D1', [(1,), (100.0,)]), ('2D1', [(2,), (100.0,)])]
         )
     )
Пример #26
0
 def test_graph_box_clear_selected_writes_history(self):
     self.TM.request_add(1, dt.Die(1))
     expected_for_hist = self.TM.request_plot_obj(True)
     self.HM.add_plot_obj(expected_for_hist)
     self.TM.request_add(1, dt.Die(1))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.TM.request_add(1, dt.Die(2))
     self.HM.add_plot_obj(self.TM.request_plot_obj(True))
     self.GB.clear_selected([('2D1', [(2, 1)]),
                             ('2D1 \\ 1D2', [(3, 1), (4, 1)])])
     history = np.load('numpy_history.npy')
     self.assertEqual(history.size, 1)
     self.assertEqual(history[0], expected_for_hist)
Пример #27
0
 def test_DiceTableManager_get_obj_to_save(self):
     self.DTM.request_add(1, dt.Die(2))
     self.DTM.request_add(1, dt.Die(4))
     expected_object_data = {'title': '1D2 \\ 1D4', 'x_range': (2, 6),
                             'y_range': (12.5, 25.0),
                             'dice': [(dt.Die(2), 1), (dt.Die(4), 1)],
                             'tuple_list': [(2, 1), (3, 2), (4, 2), (5, 2), (6, 1)],
                             'graph_axes': [(2, 3, 4, 5, 6), (12.5, 25.0, 25.0, 25.0, 12.5)]}
     data_object = self.DTM.get_obj_to_save()
     self.assertEqual(data_object.title, expected_object_data['title'])
     self.assertEqual(data_object.x_range, expected_object_data['x_range'])
     self.assertEqual(data_object.y_range, expected_object_data['y_range'])
     self.assertEqual(data_object.dice_table.get_list(), expected_object_data['dice'])
     self.assertEqual(data_object.tuple_list, expected_object_data['tuple_list'])
     self.assertEqual(data_object.graph_axes, expected_object_data['graph_axes'])
Пример #28
0
 def test_InfoBox_display_current_page_adjusts_current_page_variable(self):
     self.DTM.request_add(1, dt.Die(10))
     self.IB.make_pages('full_text', 2)
     self.IB._current_page['full_text'] = 12
     self.IB.display_current_page('full_text')
     self.assertEqual(self.IB._current_page,
                      {'weights_info': 1, 'full_text': 2})
Пример #29
0
 def test_InfoBox_display_paged_works_as_expected(self):
     self.DTM.request_add(1, dt.Die(10))
     general_info = ('the range of numbers is 1-10\n' +
                     'the mean is 5.5\nthe stddev is 2.8723')
     self.assertEqual(self.IB.display_paged(2, 2),
                      [general_info, '1D10', ('1D10\n    No weights', 1, 1),
                       (' 1: 1\n 2: 1', 1, 5)])
Пример #30
0
 def test_InfoBox_make_pages_with_weights_info(self):
     self.DTM.request_add(1, dt.Die(3))
     self.DTM.request_add(1, dt.WeightedDie({1: 2}))
     self.IB.make_pages('weights_info', 2)
     self.assertEqual(self.IB._pages['weights_info'], ['1D1  W:2\n    1 has weight: 2',
                                                       '\n1D3',
                                                       '    No weights\n '])