Example #1
0
    def test_empty(self):
        print("""
This happens when you do not correctly handle a license with no other data.
""")
        enter()
        from LabD6 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('MZZZ000'), [])
        exit()
Example #2
0
    def test_none(self):
        print("""
This happens when you do not correctly handle the license "None".
""")
        enter()
        from LabD6 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('None'), ['None'])
        exit()
Example #3
0
    def test_missing(self):
        print("""
This happens when you do not correctly return None when not found.
""")
        enter()
        from LabD6 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('NOVELPLATE'), None)
        exit()
Example #4
0
    def test_big(self):
        print("""
This happens when you do not correctly return None for something too big.
""")
        enter()
        from LabD6 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('ZYD2068'), None)
        exit()
Example #5
0
    def test_altfile(self):
        print("""
This happens when you do not correctly read the specified filename.
""")
        enter()
        from LabD6 import Plates
        plates = Plates('other.txt')
        self.assertEqual(plates.findByPlate('8LW1A4F'), \
            ['Meaningless notes about car with plate 8LW1A4F'])
        exit()
Example #6
0
    def test_middle(self):
        print("""
This happens when you do not correctly return an arbitrary item in the list.
""")
        enter()
        from LabD6 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('AY6D670'), \
            ['Meaningless notes about car with plate AY6D670'])
        exit()
Example #7
0
    def test_last(self):
        print("""
This happens when you do not correctly return the last item in the file.
""")
        enter()
        from LabD6 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('Y2C5NSM'), \
            ['Meaningless notes about car with plate Y2C5NSM'])
        exit()
Example #8
0
    def test_first(self):
        print("""
This happens when you do not correctly return the first item in the file.
""")
        enter()
        from LabD6 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('GPA1905'), ['Chevrolet', \
            'Corvette Coupe', '2008', 'pink', 'Sylvia Cheers'])
        exit()
Example #9
0
    def test_sortedlast(self):
        print("""
This happens when you do not correctly return the last licence plate
in sorted order.
""")
        enter()
        from LabD6 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('ZYD2067'),
                         ['Meaningless notes about car with plate ZYD2067'])
        exit()
Example #10
0
    def test_sortedfirst(self):
        print("""
This happens when you do not correctly return the first item in the file
by sorted order.
""")
        enter()
        from LabD6 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('0015V73'), \
            ['Meaningless notes about car with plate 0015V73'])
        exit()
Example #11
0
    def test_no_output(self):
        # Based on code from user1200039 http://stackoverflow.com/questions/5136611/capture-stdout-from-a-script-in-python
        import sys
        from io import StringIO
        from LabD6 import Plates
        print("""
Most commonly your program fails this test if you use a print statement
in your sort_hand function. You must not print anything in this function.
Instead, you should return the location so that the test code can access it.

Wrong:

def add(a, b):
    ""\" Add a and b.""\"
    print(a+b)

Right:

def add(a, b):
    ""\" Return the sum of a and b.""\"
    return a+b
""")
        enter()
        oldout = sys.stdout
        buf = StringIO()
        try:
            sys.stdout = buf
            Plates('sampleplates.txt').findByPlate('Test')
        finally:
            sys.stdout = oldout
        self.assertEqual(len(buf.getvalue()), 0)
        exit()
Example #12
0
 def test_timing(self):
     enter(1200)
     from random import shuffle
     import sys
     from time import process_time
     from LabD6 import Plates
     plates = Plates('huge.txt')
     targ = []
     with open('hugetargets.txt', 'r') as targets:
         for line in targets:
             targ.append(line.rstrip())
     start = process_time()
     for t in targ:
         plates.findByPlate(t)
     time = (process_time() - start) * 100
     print(time)
     for i in range(1, 100):
         with self.subTest(time=i):
             self.assertLessEqual(
                 time,
                 i,
                 msg="This tests the time required to process 10000 queries."
             )
     exit()