def test_off_lowercase(self): with captured_io(StringIO('hal\noff')) as (out,err): robot.robot_start() output = out.getvalue() value ='''What do you want to name your robot? hal: Hello kiddo! hal: What must I do next? hal: Shutting down.. ''' self.assertEqual(output,value)
def test_step1_then_off(self): with captured_io(StringIO('HAL\noff\n')) as (out): random.randint = lambda a, b: 0 robot.robot_start() output = out.getvalue().strip() self.assertEqual( """What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? HAL: Shutting down..""", output)
def test_step2_then_wrong_then_off(self): with captured_io(StringIO('HAL\nJump up\noff\n')) as (out): robot.robot_start() output = out.getvalue().strip() self.assertEqual( """What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? HAL: Sorry, I did not understand 'Jump up'. HAL: What must I do next? HAL: Shutting down..""", output)
def test_step1_then_off_camelcase(self): with captured_io(StringIO('HAL\nOff\n')) as (out, err): robot.robot_start() output = out.getvalue().strip() self.assertEqual("""What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? HAL: Shutting down..""", output)
def test_run(self): hangman.random.randint = lambda a, b: 0 with captured_io(StringIO('d\n')) as (out, err): hangman.run_game('tests/test_list.txt') output = out.getvalue().strip() self.assertEqual( "Guess the word: _bc\nGuess the missing letter: The word was: abc\nWrong! Do better next time.", output)
def test_step8_right_then_off(self): with captured_io(StringIO('HAL\nright\noff\n')) as (out): robot.robot_start() output = out.getvalue().strip() self.assertEqual( """What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? > HAL turned right. > HAL now at position (0,0). HAL: What must I do next? HAL: Shutting down..""", output)
def test_step7_back10_then_off(self): with captured_io(StringIO('HAL\nback 10\noff\n')) as (out): robot.robot_start() output = out.getvalue().strip() self.assertEqual( """What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? > HAL moved back by 10 steps. > HAL now at position (0,-10). HAL: What must I do next? HAL: Shutting down..""", output)
def test_step3_help_then_off(self): with captured_io(StringIO('HAL\nhelp\noff\n')) as (out): robot.robot_start() output = out.getvalue().strip() self.assertEqual( """What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? I can understand these commands: OFF - Shut down robot HELP - provide information about commands""", output[:178])
def test_step4(self): with captured_io(StringIO('')) as (out, err): draw.draw_triangle(3, False) output = out.getvalue() self.assertEqual("""* ** *** """, output) with captured_io(StringIO('')) as (out, err): draw.draw_triangle(5, False) output = out.getvalue() self.assertEqual("""* ** *** **** ***** """, output)
def test_step5_mazerun_right(self): with captured_io(StringIO('HAL\nmazerun right\noff\n')) as (out, err): obstacles.random.randint = lambda a, b: 1 robot.robot_start() output = out.getvalue().strip() self.assertTrue(output.find('starting maze run..') > -1) self.assertTrue(output.find('I am at the right edge') > -1)
def test_step5_fwd10_then_off_uppercase(self): with captured_io(StringIO('HAL\nFORWARD 10\noff\n')) as (out, err): robot.robot_start() output = out.getvalue().strip() self.assertEqual("""What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? > HAL moved forward by 10 steps.""", output[:114])
def test_step4(self): with captured_io(StringIO('z\nx\ny\nw\nq\n')) as (out, err): hangman.run_game_loop('abc', "__c") output = out.getvalue().strip() self.assertEqual( """Guess the word: __c Guess the missing letter: Wrong! Number of guesses left: 4""", output[:78]) self.assertEqual('Sorry, you are out of guesses. The word was: abc', output[-48:])
def test_step5_none_left(self): with captured_io(StringIO('')) as (out, err): hangman.draw_figure(0) output = out.getvalue().strip() self.assertEqual("""/---- | 0 | /|\\ | | | / \\ _______""", output)
def test_step2(self): with captured_io(StringIO('a\nb\n')) as (out, err): hangman.run_game_loop('abc', "__c") output = out.getvalue().strip() self.assertEqual( "Guess the word: __c\nGuess the missing letter: a_c\nGuess the missing letter: abc", output) with captured_io(StringIO('f\na\nb\n')) as (out, err): hangman.run_game_loop('abc', "__c") output = out.getvalue().strip() self.assertEqual( """Guess the word: __c Guess the missing letter: Wrong! Number of guesses left: 4""", output[:78]) self.assertEqual( "Guess the missing letter: a_c\nGuess the missing letter: abc", output[-59:])
def test_step10_left_fwd101_then_off(self): with captured_io(StringIO('HAL\nleft\nforward 101\noff\n')) as (out): robot.robot_start() output = out.getvalue().strip() self.assertEqual( """What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? > HAL turned left. > HAL now at position (0,0). HAL: What must I do next? HAL: Sorry, I cannot go outside my safe zone. > HAL now at position (0,0). HAL: What must I do next? HAL: Shutting down..""", output)
def test_step9_left_fwd10_off(self): with captured_io(StringIO('HAL\nleft\nforward 10\noff\n')) as (out): robot.robot_start() output = out.getvalue().strip() self.assertEqual( """What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? > HAL turned left. > HAL now at position (0,0). HAL: What must I do next? > HAL moved forward by 10 steps. > HAL now at position (-10,0). HAL: What must I do next? HAL: Shutting down..""", output)
def test_forward_109(self): with captured_io(StringIO('hal\nforward 109\noff')) as (out,err): robot.robot_start() output = out.getvalue() # print(output) value ='''What do you want to name your robot? hal: Hello kiddo! hal: What must I do next? hal: Sorry, I cannot go outside my safe zone. > hal now at position (0,0). hal: What must I do next? hal: Shutting down.. ''' self.assertEqual(output,value)
def test_back_10(self): with captured_io(StringIO('hal\nback 10\noff')) as (out, err): robot.robot_start() output = out.getvalue() # print(output) value = '''What do you want to name your robot? hal: Hello kiddo! hal: What must I do next? > hal moved back by 10 steps. > hal now at position (0,-10). hal: What must I do next? hal: Shutting down.. ''' self.assertEqual(output, value)
def test_step8_right_then_off(self): with captured_io(StringIO('HAL\nright\noff\n')) as (out, err): robot.robot_start() output = out.getvalue().strip() self.assertEqual( """HAL: What must I do next? > HAL turned right. > HAL now at position (0,0). HAL: What must I do next? HAL: Shutting down..""", output[-123:])
def test_check_observations(self): with captured_io(StringIO('HAL\nleft\nforward 10\noff\n')) as (out, err): obstacles.random.randint = lambda a, b: 1 robot.robot_start() output = out.getvalue().strip() self.assertEqual("""What do you want to name your robot? HAL: Hello kiddo! There are some obstacles: - At position 1,1 (to 5,5)""", output[:107])
def test_step3_replay_silent_reversed_invalid(self): with captured_io(StringIO('HAL\nforward 10\nforward 5\nreplay REVERSED,SILENT\noff\n')) as (out, err): robot.robot_start() output = out.getvalue().strip() self.assertEqual("""What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? > HAL moved forward by 10 steps. > HAL now at position (0,10). HAL: What must I do next? > HAL moved forward by 5 steps. > HAL now at position (0,15). HAL: What must I do next? HAL: Sorry, I did not understand 'replay REVERSED,SILENT'. HAL: What must I do next? HAL: Shutting down..""", output)
def test_create_obstacle(self): with captured_io(StringIO('HAL\noff\n')) as (out, err): obstacles.random.randint = lambda a, b: 1 robot.robot_start() output = out.getvalue().strip() self.assertEqual( """What do you want to name your robot? HAL: Hello kiddo! HAL: Loaded obstacles. There are some obstacles: - At position 1,1 (to 5,5)""", output[:130])
def test_general_output(self): with captured_io(StringIO("test\n1\nwaxes27\nexit\nn\n")) as (out, err): monopoly.run() output = out.getvalue().strip() self.assertEqual( output, """Please enter a game name: How many players will be playing...: Enter Player Name: Player 1's Turn: Would you like to: [1] roll [2] buy [3] build Player 1 >: Would you like to save [y/n]:""")
def test_left_forward_10_off(self): with captured_io(StringIO('hal\nleft\nforward 10\noff')) as (out, err): robot.robot_start() output = out.getvalue() # print(output) value = '''What do you want to name your robot? hal: Hello kiddo! hal: What must I do next? > hal turned left. > hal now at position (0,0). hal: What must I do next? > hal moved forward by 10 steps. > hal now at position (-10,0). hal: What must I do next? hal: Shutting down.. ''' self.assertEqual(output, value)
def test_step3_replay_silent_reversed(self): with captured_io(StringIO('HAL\nforward 10\nforward 5\nreplay reversed silent\noff\n')) as (out, err): robot.robot_start() output = out.getvalue().strip() self.assertEqual("""What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? > HAL moved forward by 10 steps. > HAL now at position (0,10). HAL: What must I do next? > HAL moved forward by 5 steps. > HAL now at position (0,15). HAL: What must I do next? > HAL replayed 2 commands in reverse silently. > HAL now at position (0,30). HAL: What must I do next? HAL: Shutting down..""", output)
def test_check_volunteer_slot_conflict(self): with captured_io(StringIO('14 dec 2030 14:45\n')) as (out, err): check_volunteer_slot_conflict( 'patient.json', '14 dec 2030 14:45') output = out.getvalue().strip() self.assertEqual("""Please enter your volunteer slots DATE and START-TIME. Note, the duration of the volunteer slot will be 90-minutes. Day Month Time - [14 dec 14:30]: 14 dec 2030 14:45 'Python TDD' event time conflict found. The events end-time is in your volunteer slots proposed 90-minute time range. -> 'Python TDD' event info: [Saturday] [14-12-2030] [14:30 - 15:00]. Please select a different time for your volunteer slot.""", output)
def test_topic_input_empty_string(self): with captured_io(StringIO("\ncdu-pree\nbidaniel\n")) as (out, err): apiinput.book_topic() output = out.getvalue().strip() self.assertEqual( '''Coding Clinic Topics: Recursion Unittesting List Comprehensions Lambdas Please choose a topic you would like to clinic? Or leave blank to choose a 'General' topic You have chosen a General topic''', output)
def test_step11_sprint5_then_off(self): with captured_io(StringIO('HAL\nsprint 5\noff\n')) as (out): robot.robot_start() output = out.getvalue().strip() self.assertEqual( """What do you want to name your robot? HAL: Hello kiddo! HAL: What must I do next? > HAL moved forward by 5 steps. > HAL moved forward by 4 steps. > HAL moved forward by 3 steps. > HAL moved forward by 2 steps. > HAL moved forward by 1 steps. > HAL now at position (0,15). HAL: What must I do next? HAL: Shutting down..""", output)
def test_previous(self): words = hangman.read_file('tests/test_list.txt') self.assertEqual(1, len(words)) self.assertEqual('abc', words[0]) hangman.random.randint = lambda a, b: 0 with captured_io(StringIO('a\n')) as (out, err): hangman.select_random_word(['abc']) hangman.select_random_letter_from('abc') output = out.getvalue().strip() self.assertEqual("Guess the word: _bc", output)
def test_step5(self): with captured_io(StringIO('')) as (out, err): draw.draw_triangle(5, True) output = out.getvalue() self.assertEqual("""* ** * * * * ***** """, output) with captured_io(StringIO('')) as (out, err): draw.draw_square(5, True) output = out.getvalue() self.assertEqual("""***** * * * * * * ***** """, output) with captured_io(StringIO('')) as (out, err): draw.draw_pyramid(3, True) output = out.getvalue() self.assertEqual(""" * * * ***** """, output) with captured_io(StringIO('')) as (out, err): draw.draw_pyramid(5, True) output = out.getvalue() self.assertEqual(""" * * * * * * * ********* """, output)