def test_print_inventory_list(self, mock_output): test_list = [ "Gandalf", ["Strength", 1], ["Dexterity", 2], ["Constitution", 3], ["Intelligence", 4], ["Wisdom", 5], ["Charisma", 6], [ "sidesword", "rapier", "dagger", "longsword", "cloak of 'what the hell is this?'" ] ] expected_output = ("Gandalf\n" "Strength: 1!\n" "Dexterity: 2!\n" "Constitution: 3!\n" "Intelligence: 4!\n" "Wisdom: 5!\n" "Charisma: 6!\n" "sidesword\n" "rapier\n" "dagger\n" "longsword\n" "cloak of 'what the hell is this?'\n") Lab_05.print_character(test_list) self.assertEqual(mock_output.getvalue(), expected_output)
def test_generate_consonant(self): my_consonant = Lab_05.generate_consonant() self.assertIn(my_consonant, [ 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' ])
def test_print_character_attributes(self, mock_output): test_list = [ "Gandalf", ["Strength", 1], ["Dexterity", 2], ["Constitution", 3], ["Intelligence", 4], ["Wisdom", 5], ["Charisma", 6] ] expected_output = ("Gandalf\n" "Strength: 1!\n" "Dexterity: 2!\n" "Constitution: 3!\n" "Intelligence: 4!\n" "Wisdom: 5!\n" "Charisma: 6!\n") Lab_05.print_character(test_list) self.assertEqual(mock_output.getvalue(), expected_output)
def test_generate_syllable_first_char_is_consonant(self): my_syllable = Lab_05.generate_syllable() self.assertIn(my_syllable[0], [ 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' ])
def test_odds_are_consonants(self): test_name = Lab_05.generate_name(9) for i in range(0, len(test_name), 2): self.assertIn(test_name[i].lower(), [ 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z' ])
def main(): print("********** WELCOME, adventurer!! **********") syl_count = input( "Forgot my glasses; can't read my attendance sheet..... how many syllables are in your name?" ) character = Lab_05.create_character(int(syl_count)) print("********** Welcome " + character[0] + "! Announce yourself!**********") print("Behold! I am the mighty " + character[0] + " - scourge of a place with an equally incomprehensible name.\n") print("My uproarious abilities:\n") print('####################') Lab_05.print_character(character) print('####################') items_list = [ "Rapier", "Broadsword", "Vorpal sword", "The constrictor", "A newt", "giant spoon", "icingdeath", "bag of holding", "boomstick", "stabstick" ] eq_count = input( "********** " + character[0] + ", I have " + str(len(items_list)) + " items for you! But, they're secret. How many you would like?**********\n " ) eq_count = int(eq_count) - 0 # enough of these f'ing string errors eq_list = [] if eq_count > len(items_list) or eq_count <= 0: Lab_05.choose_inventory(items_list, eq_count) elif eq_count > 0: character.append(Lab_05.choose_inventory(items_list, eq_count)) print( "********** You are a new person! Behold, world! I give you: **********\n " ) Lab_05.print_character(character)
def test_generate_name_correct_length(self): test_name = Lab_05.generate_name(4) self.assertEqual(len(test_name), 8)
def test_roll_3_rolls_of_6(self, mock_roll): self.assertEqual(Lab_05.roll_die(3, 6), 11)
def test_evens_are_vowels(self): test_name = Lab_05.generate_name(9) for i in range(1, len(test_name), 2): self.assertIn(test_name[i], ['a', 'e', 'i', 'o', 'u', 'y'])
def test_roll_die_0_rolls(self): self.assertEqual(Lab_05.roll_die(0, 5), 0)
def test_choose_inventory_selection_gt_inventory_length(self, mock_output): expected_output = "Getting greedy. Venger would be proud.\n" Lab_05.choose_inventory(['bucket'], 2) self.assertEqual(mock_output.getvalue(), expected_output)
def test_choose_inventory_inventory_size_eq_selection( self, mock_inventory): expected_output = ['a', 'b', 'c', 'd'] self.assertEqual(Lab_05.choose_inventory(['b', 'a', 'd', 'c'], 4), expected_output)
def test_roll_1_rolls_of_6(self, mock_roll): self.assertEqual(Lab_05.roll_die(1, 6), 3)
def test_attributes_element_0_are_strings(self): my_char = Lab_05.create_character(5) for i in range(1, len(my_char)): self.assertIsInstance(my_char[i][0], str)
def test_first_element_is_string(self): my_char = Lab_05.create_character(5) self.assertIsInstance(my_char[0], str)
def test_generate_syllable_is_2_char_long(self): my_syllable = Lab_05.generate_syllable() self.assertEqual(len(my_syllable), 2)
def test_single_roll_6_side(self, mock_sides): self.assertEqual(Lab_05.single_roll(mock_sides), 5)
def test_create_character_is_7_elements(self): my_char = Lab_05.create_character(5) self.assertEqual(len(my_char), 7)
def test_attributes_element_1_are_ints(self): my_char = Lab_05.create_character(5) for i in range(1, len(my_char)): self.assertIsInstance(my_char[i][1], int)
def test_roll_2_rolls_of_6(self, mock_roll): self.assertEqual(Lab_05.roll_die(2, 6), 8)
def test_choose_inventory_selection_lt_0(self, mock_output): expected_output = 'Error: selection < 0 is NOT permitted.\n' Lab_05.choose_inventory(['bucket'], -1) self.assertEqual(mock_output.getvalue(), expected_output)
def test_generate_vowel(self): my_vowel = Lab_05.generate_vowel() self.assertIn(my_vowel, ['a', 'e', 'i', 'o', 'u', 'y'])
def test_other_elements_are_lists(self): my_char = Lab_05.create_character(5) for i in range(1, len(my_char)): self.assertIsInstance(my_char[i], list)
def test_generate_syllable_char_2_is_vowel(self): my_syllable = Lab_05.generate_syllable() self.assertIn(my_syllable[1], ['a', 'e', 'i', 'o', 'u', 'y'])
def test_choose_inventory_inventory_empty(self): return_list = Lab_05.choose_inventory([], 4) self.assertEqual(len(return_list), 0)
def test_choose_inventory_selection_0(self): return_list = Lab_05.choose_inventory(['bucket'], 0) self.assertEqual(len(return_list), 0)
def test_roll_die_0_sided_die(self): self.assertEqual(Lab_05.roll_die(5, 0), 0)