How To Write Unit Tests In Python: Sample

import AirportConnectionsAssignment

import unittest

class TestPrgm(unittest.TestCase):

    

    def test_case_1(self):

        AIRPORTS = [ "BGI", "CDG", "DEL", "DOH", "DSM", "EWR", "EYW", "HND", "ICN", "JFK", "LGA", "LHR", "ORD", "SAN", "SFO", "SIN", "TLV", "BUD" ]

        STARTING_AIRPORT = "LGA"

        routes = [ ["DSM", "ORD"], ["ORD", "BGI"], ["BGI", "LGA"], ["SIN", "CDG"], ["CDG", "SIN"], ["CDG", "BUD"], ["DEL", "DOH"], ["DEL", "CDG"], ["TLV", "DEL"], ["EWR", "HND"], ["HND", "ICN"], ["HND", "JFK"], ["ICN", "JFK"], ["JFK", "LGA"], ["EYW", "LHR"], ["LHR", "SFO"], ["SFO", "SAN"], ["SFO", "DSM"], ["SAN", "EYW"] ]

        aptConnects = AirportConnectionsAssignment.aptConnects(AIRPORTS, routes, STARTING_AIRPORT)

        self.assertTrue(aptConnects == (3, [['LGA', 'SFO'], ['LGA', 'TLV'], ['LGA', 'EWR']]))

    def test_case_2(self):

        AIRPORTS = ["1", "2", "3"]

        STARTING_AIRPORT = "2"

        routes = [ ["1", "2"], ["2", "3"]]

        aptConnects = AirportConnectionsAssignment.aptConnects(AIRPORTS, routes, STARTING_AIRPORT)

        self.assertTrue(aptConnects == (1, [['2', '1']]))

    def test_case_3(self):

        AIRPORTS = ["1", "2", "3"]

        STARTING_AIRPORT = "3"

        routes = [ ["1", "2"], ["2", "3"]]

        aptConnects = AirportConnectionsAssignment.aptConnects(AIRPORTS, routes, STARTING_AIRPORT)

        self.assertFalse(aptConnects == (1, [['2', '1']]))

    def test_case_4(self):

        AIRPORTS = ["1", "2", "3",  "4"]

        STARTING_AIRPORT = "3"

        routes = [ ["1", "2"], ["2", "3"]]

        aptConnects = AirportConnectionsAssignment.aptConnects(AIRPORTS, routes, STARTING_AIRPORT)

        self.assertTrue(aptConnects == (2, [['3', '1'], ['3', '4']]))

    def test_case_5(self):

        AIRPORTS = []

        STARTING_AIRPORT = "3"

        routes = []

        aptConnects = AirportConnectionsAssignment.aptConnects(AIRPORTS, routes, STARTING_AIRPORT)

        self.assertTrue(aptConnects == "No Input Airport List")

    def test_case_6(self):

        AIRPORTS = ["1", "2", "ABC"]

        STARTING_AIRPORT = None

        routes = []

        aptConnects = AirportConnectionsAssignment.aptConnects(AIRPORTS, routes, STARTING_AIRPORT)

        self.assertTrue(aptConnects == "No Starting Airport Provided")

        

if __name__ == '__main__':

    unittest.main()