コード例 #1
0
class MyTest(unittest.TestCase):
    def setUp(self):
        self.flight = Flight()
        self.angle = 0
        self.flag = 'n'
        self.flag1 = 'y'

    def test_to_string_method_should_return_empty_string(self):
        self.assertEqual(str(self.flight), '')
        print self.flight

    def test_should_print_welcome_message(self):
        with captured_output() as (out, err):
            Flight()

        output = out.getvalue().strip()
        self.assertEqual(output, "Start!")

    def test_should_print_given_arguments(self):
        argument1 = 1
        argument2 = ['z', 2]
        with captured_output() as (out, err):
            Travel.simulator_reply(argument1, argument2)

        output = out.getvalue().strip()
        self.assertEqual(output, str(argument1) + '\n' + str(argument2))

    def test_should_have_proper_field_values_set(self):
        self.assertEqual(Travel.angle, self.angle)
        self.assertEqual(Travel.flag, self.flag)
        self.assertEqual(Travel.flag1, self.flag1)

    def test_should_not_print_info_when_flag_is_yes_and_flag1_is_yes(self):
        self.flight.flag = 'y'
        self.flight.flag1 = 'y'
        self.verify_flight_go_empty_output()

    def test_should_not_print_info_when_flag_is_no_flag1_is_no(self):
        self.flight.flag = 'n'
        self.flight.flag1 = 'n'
        self.verify_flight_go_empty_output()

    def test_should_not_print_info_when_flag_is_no_flag1_is_yes(self):
        self.flight.flag = 'n'
        self.flight.flag1 = 'yes'
        self.verify_flight_go_empty_output()

    def verify_flight_go_empty_output(self):
        with captured_output() as (out, err):
            self.flight.go()

        output = out.getvalue().strip()
        self.assertEqual(output, '')

    @mock.patch.object(__builtin__, 'raw_input')
    def test_should_return_users_input(self, mock_raw_input):
        mock_raw_input.return_value = 'n'
        self.assertEqual(self.flight.user_action(''), 'n')

    @mock.patch.object(__builtin__, 'raw_input')
    def test_should_print_init_angle(self, mock_raw_input):
        mock_raw_input.return_value = 'n'
        with captured_output() as (out, err):
            self.flight.go()

        output = out.getvalue().strip()
        self.assertTrue(output.startswith('The angle is:'))
        self.assertTrue(output.endswith('We crashed!'))
コード例 #2
0
ファイル: kol1.py プロジェクト: 4papiez/2017win_gr2
###Flight simulator.
#Write a code in python that simulates the tilt correction of the plane (angle between plane wings and earth).
##The program should:
# - print out current orientation
# - applied tilt correction
# - run in infinite loop
# - until user breaks the loop
#Assume that plane orientation in every new simulation step is random angle with gaussian distribution (the planes is experiencing "turbulations").
#With every simulation step the orentation should be corrected, applied and printed out.
#If you can thing of any other features, you can add them.
#This code shoud be runnable with 'python kol1.py'.
#If you have spare time you can implement: Command Line Interface, generators, or even multiprocessing.
#Do your best, show off with good, clean, well structured code - this is more important than number of features.
#After you finish, be sure to UPLOAD this (add, commit, push) to the remote repository.
#Good Luck

#!/usr/bin/env python2.7

from Flight import Flight

if __name__ == "__main__":
    flight = Flight()
    flight.go()