How to optimise this code?

David N Montgomery monty.python at fastmail.fm
Tue Aug 21 11:59:34 EDT 2007


class testCase:
    def __init__(self, tc):
        if tc == 1:self.testCase1()
        if tc == 2:self.testCase2()
        if tc == 3:self.testCase3()
        if tc == 4:self.testCase4()
        if tc == 5:self.testCase5()
        if tc == 6:self.testCase6()

    def testCase1(self):
        print "tc1"

    def testCase2(self):
        print "tc2"

    def testCase3(self):
        print "tc3"

    def testCase4(self):
        print "tc4"

    def testCase5(self):
        print "tc5"

    def testCase6(self):
        print "tc6"


    def testCaseX(self):
        print "tcX"

totalNumberOfTestCases = 6
x = 0
while x <= totalNumberOfTestCases:
    x += 1
    testCase(x)


This template code is working, but I envisage having 100+ test cases and
am concerned about my useage of if statements. I would be grateful for
any pointers as to how I can run all tests cases, regardless of how
many, in a more efficient manner.

Thank you in advance.



More information about the Python-list mailing list