예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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))
예제 #4
0
 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)
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
 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)
예제 #8
0
    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)
예제 #9
0
    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))
        ]
예제 #10
0
    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))
        ]
예제 #11
0
 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
예제 #17
0
    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))
예제 #18
0
    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
예제 #20
0
 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)
예제 #21
0
 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