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)], [], [])])
def test_CurrentAndSavedInterface_get_all_current_not_empty_not_in_saved(self): self.DTM.request_add(1, dt.Die(1)) current = self.DTM.get_obj_to_save() saved = fh.SavedDiceTable('saved', [(1, 1)], [], []) self.ST.save_new(saved) self.assertEqual(self.ST.get_all(), [saved]) self.assertEqual(self.interface.get_all(), [saved, current])
def test_SavedDiceTable_equality_test_true(self): table = dt.DiceTable() table.add_die(2, dt.Die(2)) data_obj = create_saved_dice_table(table) not_really_equal_data_obj = fh.SavedDiceTable('2D2', [(2, 1), (3, 2), (4, 1)], [], []) self.assertTrue(data_obj == not_really_equal_data_obj)
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')
def test_CurrentAndSavedInterface_get_all_current_in_saved(self): self.DTM.request_add(1, dt.Die(1)) from_current = self.DTM.get_obj_to_save() asserts_equal_but_isnt = fh.SavedDiceTable('1D1', [(1, 1)], [], [(789, 1.234)]) self.assertEqual(from_current, asserts_equal_but_isnt) self.ST.save_new(asserts_equal_but_isnt) expect_from_saved = self.interface.get_all()[0] self.assertEqual(expect_from_saved.graph_axes, asserts_equal_but_isnt.graph_axes) self.assertNotEqual(expect_from_saved.graph_axes, from_current.graph_axes) self.assertEqual(self.interface.get_all(), [asserts_equal_but_isnt])
def delete_requested(self, title_tuple_list_pairs): exclude_from_new = [ fh.SavedDiceTable(title, tuple_list, [], []) for title, tuple_list in title_tuple_list_pairs ] new_data_array = np.array([], dtype=object) for saved_table in self._saved_tables: if saved_table not in exclude_from_new: new_data_array = np.append(new_data_array, saved_table) self._saved_tables = new_data_array
def test_CurrentAndSavedInterface_get_requested_gets_saved_not_current(self): self.DTM.request_add(1, dt.Die(1)) from_current = self.DTM.get_obj_to_save() asserts_equal_but_isnt = fh.SavedDiceTable('1D1', [(1, 1)], [], [(789, 1.234)]) self.assertEqual(from_current, asserts_equal_but_isnt) self.ST.save_new(asserts_equal_but_isnt) self.assertEqual(len(self.interface.get_requested([('1D1', [(1, 1)])])), 1) from_interface = self.interface.get_requested([('1D1', [(1, 1)])])[0] self.assertEqual(from_interface.graph_pts, asserts_equal_but_isnt.graph_pts) self.assertEqual(from_interface.dice_table.get_list(), asserts_equal_but_isnt.dice_table.get_list()) self.assertNotEqual(from_current.graph_pts, asserts_equal_but_isnt.graph_pts) self.assertNotEqual(from_current.dice_table.get_list(), asserts_equal_but_isnt.dice_table.get_list())
def test_CurrentAndSavedInterface_get_all_current_empty(self): saved = fh.SavedDiceTable('saved', [(1, 1)], [], []) self.ST.save_new(saved) self.assertTrue(self.interface.current_is_empty()) self.assertEqual(self.interface.get_all(), [saved])
def test_CurrentAndSavedInterface_get_and_save_current_gets(self): self.DTM.request_add(1, dt.Die(2)) self.assertEqual(self.interface.get_and_save_current(), fh.SavedDiceTable('1D2', [(1, 1), (2, 1)], [], []))
def create_saved_dice_table(table): title = str(table).replace('\n', ' \\ ') graph_data = dt.graph_pts(table) tuple_list = table.frequency_all() dice_list = table.get_list() return fh.SavedDiceTable(title, tuple_list, dice_list, graph_data)
def get_obj_to_save(self): title = self.title_one_line graph_data = dt.graph_pts(self._table) tuple_list = self.tuple_list dice_list = self.dice_list return fh.SavedDiceTable(title, tuple_list, dice_list, graph_data)
def get_requested(self, title, tuple_list): dummy_saved_table = fh.SavedDiceTable(title, tuple_list, [], []) for data_obj in self._saved_tables: if dummy_saved_table == data_obj: return data_obj return fh.SavedDiceTable.empty_object()
def has_requested(self, title, tuple_list): """ :return: bool """ return fh.SavedDiceTable(title, tuple_list, [], []) in self._saved_tables