def test_choose_inventory_print_output_with_negative_integer( self, mock_stdout): """Test choose_inventory function with an empty list and negative integer. The result is expected to same as expected_output """ dungeonsanddragons.choose_inventory([], -3) expected_output = "Selection must be positive integer!\n" self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_choose_inventory_print_output_with_selection_greater_than_length_of_list( self, mock_stdout): """Test choose_inventory function with positive integer bigger than the length of list. The result is expected to same as expected_output """ my_list = ['a', 'b'] dungeonsanddragons.choose_inventory(my_list, 3) expected_output = "Selection must be less than the length of inventory!\n" self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_choose_inventory_with_selection_greater_than_length_of_list(self): """Test choose_inventory function with positive integer bigger than the length of list. The result is expected None """ my_list = ['a', 'b'] self.assertIsNone(dungeonsanddragons.choose_inventory(my_list, 3))
def test_choose_inventory_buy_two_items_check_if_list(self, mock_input): actual = choose_inventory([ 'The Fantastic Plane Tradepost', 'Adamantine Armor', 'Demon Armor', 'Dwarven Plate', 'Mariner\'s Armor', 'Sentinel Shield', 'Spellguard Shield', 'Sun Blade', 'Wand of Enemy Destruction', 'Javelin of Lightning' ]) self.assertEqual(type(actual), list)
def test_choose_inventory_output_type(self): """Test choose_inventory function if type of output is list. The result is expected True """ my_list = ['b', 'c', 'a'] self.assertTrue( type(dungeonsanddragons.choose_inventory(my_list, 2)) == list)
def test_choose_inventory_with_positive_integer(self): """Test choose_inventory function if the length of output is same as selection argument. The result is expected True """ my_list = ['b', 'c', 'a'] self.assertTrue( len(dungeonsanddragons.choose_inventory(my_list, 2)) == 2)
def test_choose_inventory_buy_nothing(self, mock_input): expected = [] actual = choose_inventory([ 'The Fantastic Plane Tradepost', 'Adamantine Armor', 'Demon Armor', 'Dwarven Plate', 'Mariner\'s Armor', 'Sentinel Shield', 'Spellguard Shield', 'Sun Blade', 'Wand of Enemy Destruction', 'Javelin of Lightning' ]) self.assertEqual(expected, actual)
def test_choose_inventory_with_length_of_list_is_same_as_selection(self): """Test choose_inventory function with positive integer same as the length of list. The result is expected copy of original list """ my_list = ['a', 'f', 'd', 'z', 'y', 'b'] my_list.sort() self.assertEqual(dungeonsanddragons.choose_inventory(my_list, 6), my_list)
def test_choose_inventory_if_output_is_in_original_list(self): """Test choose_inventory if all the elements of output are in the original list. The result is expected True """ my_list = ['b', 'c', 'e', 'a', 'f', 'd'] output = dungeonsanddragons.choose_inventory(my_list, 3) is_in = [ self.assertTrue(output[i] in my_list) for i in range(0, len(output)) ]
def test_choose_inventory_if_sorted(self): """Test choose_inventory function if the list output is sorted properly. The result is expected True """ my_list = ['b', 'c', 'e', 'a', 'f', 'd'] sorted_list = dungeonsanddragons.choose_inventory(my_list, 5) # output sorted is_sorted = [ self.assertTrue(ord(sorted_list[i - 1]) < ord(sorted_list[i])) for i in range(1, len(sorted_list)) ]
def test_choose_inventory_number_of_items(self, mock_input): actual_value = choose_inventory() self.assertTrue(len(actual_value) == 3)
def test_choose_inventory5(self): self.assertEqual( 2, len(dungeonsanddragons.choose_inventory([1, 2, 3, 4], 2)))
def test_choose_inventory4(self): self.assertEqual([1, 2, 3], dungeonsanddragons.choose_inventory( [1, 2, 3], 3)) # Tests selection =list length,
def test_choose_inventory7(self): # Tests random output random.seed(3) self.assertEqual(['Ring', 'Staff'], dungeonsanddragons.choose_inventory( ['Ring', 'Staff', 'Scroll'], 2)) random.seed()
def test_choose_inventory6(self): self.assertEqual(list, type(dungeonsanddragons.choose_inventory([1, 2], 2)))
def test_choose_inventory(self): self.assertEqual([], dungeonsanddragons.choose_inventory( [], 0)) # Tests that 0 as selection
def test_choose_inventory_with_empty_list_and_negative_integer(self): """Test choose_inventory function with an empty list and negative integer. The result is expected None """ self.assertIsNone(dungeonsanddragons.choose_inventory([], -3))
def test_choose_inventory_with_empty_list_and_zero(self): """Test choose_inventory function with an empty list and zero integer. The result is expected an empty list """ self.assertEqual(dungeonsanddragons.choose_inventory([], 0), [])
def test_choose_inventory3(self): self.assertIsNone(dungeonsanddragons.choose_inventory( [1, 2, 3], 4)) # Tests that selection
def test_choose_inventory_duplicate_items(self, mock_input): actual_value = choose_inventory() expected_value = ["sword", "sword", "sword", "sword"] self.assertEqual(actual_value, expected_value)
def test_choose_inventory_no_items_bought(self, mock_input): actual_value = choose_inventory() expected_value = [] self.assertEqual(actual_value, expected_value)
def test_choose_inventory2(self): self.assertIsNone(dungeonsanddragons.choose_inventory( [1, 2], -1)) # Tests that negative selection is None