Esempio n. 1
0
    def test_none(self):
        print("""
This happens when you do not correctly handle the license "None".
""")
        from LabB1 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('None'), ['None'])
Esempio n. 2
0
    def test_big(self):
        print("""
This happens when you do not correctly return None for something too big.
""")
        from LabB1 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('ZYD2068'), None)
Esempio n. 3
0
    def test_empty(self):
        print("""
This happens when you do not correctly handle a license with no other data.
""")
        from LabB1 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('MZZZ000'), [])
Esempio n. 4
0
    def test_missing(self):
        print("""
This happens when you do not correctly return None when not found.
""")
        from LabB1 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('NOVELPLATE'), None)
Esempio n. 5
0
    def test_first(self):
        print("""
This happens when you do not correctly return the first item in the file.
""")
        from LabB1 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('GPA1905'), ['Chevrolet', \
            'Corvette Coupe', '2008', 'pink', 'Sylvia Cheers'])
Esempio n. 6
0
    def test_altfile(self):
        print("""
This happens when you do not correctly read the specified filename.
""")
        from LabB1 import Plates
        plates = Plates('other.txt')
        self.assertEqual(plates.findByPlate('8LW1A4F'), \
            ['Meaningless notes about car with plate 8LW1A4F'])
Esempio n. 7
0
    def test_middle(self):
        print("""
This happens when you do not correctly return an arbitrary item in the list.
""")
        from LabB1 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('AY6D670'), \
            ['Meaningless notes about car with plate AY6D670'])
Esempio n. 8
0
    def test_last(self):
        print("""
This happens when you do not correctly return the last item in the file.
""")
        from LabB1 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('Y2C5NSM'), \
            ['Meaningless notes about car with plate Y2C5NSM'])
Esempio n. 9
0
    def test_sortedlast(self):
        print("""
This happens when you do not correctly return the last licence plate
in sorted order.
""")
        from LabB1 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('ZYD2067'),
                         ['Meaningless notes about car with plate ZYD2067'])
Esempio n. 10
0
    def test_sortedfirst(self):
        print("""
This happens when you do not correctly return the first item in the file
by sorted order.
""")
        from LabB1 import Plates
        plates = Plates('sampleplates.txt')
        self.assertEqual(plates.findByPlate('0015V73'), \
            ['Meaningless notes about car with plate 0015V73'])
Esempio n. 11
0
 def setUpClass(cls):
     from random import shuffle
     import sys
     from time import process_time
     from LabB1 import Plates
     plates = Plates('sampleplates.txt')
     targ = []
     with open('targets.txt', 'r') as targets:
         for line in targets:
             targ.append(line.rstrip())
     start = process_time()
     for t in targ:
         plates.findByPlate(t)
     cls.time = process_time() - start
Esempio n. 12
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 LabB1 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
""")
        oldout = sys.stdout
        buf = StringIO()
        try:
            sys.stdout = buf
            Plates('sampleplates.txt').findByPlate('Test')
        finally:
            sys.stdout = oldout
        self.assertEqual(len(buf.getvalue()), 0)