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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()
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()