def test_sample_2(self): self.assertEqual( [ AssignedJob(0, 0), AssignedJob(1, 0), AssignedJob(2, 0), AssignedJob(3, 0), AssignedJob(0, 1), AssignedJob(1, 1), AssignedJob(2, 1), AssignedJob(3, 1), AssignedJob(0, 2), AssignedJob(1, 2), AssignedJob(2, 2), AssignedJob(3, 2), AssignedJob(0, 3), AssignedJob(1, 3), AssignedJob(2, 3), AssignedJob(3, 3), AssignedJob(0, 4), AssignedJob(1, 4), AssignedJob(2, 4), AssignedJob(3, 4), ], assign_jobs( 4, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]))
def test_sample_1(self): self.assertEqual([ AssignedJob(0, 0), AssignedJob(1, 0), AssignedJob(0, 1), AssignedJob(1, 2), AssignedJob(0, 4) ], assign_jobs(2, [1, 2, 3, 4, 5]))
def test_stress(self): for i in range(5000): n_workers = random.randint(1, 10**2) jobs = [ random.randint(0, 10**3) for _ in range(random.randint(1, 10**3)) ] assigned_jobs_naive = assign_jobs_naive(n_workers, jobs) assigned_jobs = assign_jobs(n_workers, jobs) print('test', i, n_workers, jobs) self.assertCountEqual(assigned_jobs, assigned_jobs_naive)
def test_main(self): test_data = test_runner('./tests') for test in test_data: data, result, file = test if result is not None: n_workers, _ = list(map(int, data[0].split())) jobs = list(map(int, data[1].split())) result = list( map(lambda item: tuple(map(int, item.split())), result)) assigned_jobs = assign_jobs(n_workers, jobs) print('file', file) self.assertCountEqual(result, assigned_jobs)
def test_naive(self): test_data = test_runner('./tests') for test in test_data: data, result, file = test if '08' not in file: n_workers, _ = list(map(int, data[0].split())) jobs = list(map(int, data[1].split())) assigned_jobs = assign_jobs(n_workers, jobs) assigned_jobs_naive = assign_jobs_naive(n_workers, jobs) print('file', file) self.assertCountEqual(assigned_jobs, assigned_jobs_naive)
def test_assign_jobs_cases(): all_files = glob.glob('tests/') q_names = sorted([f for f in all_files if 'a' not in f]) a_names = sorted([f for f in all_files if 'a' in f]) for q, a in zip(q_names, a_names): with open(q) as f: n_workers, n_jobs = map(int, f.readline().split()) jobs = list(map(int, f.readline().split())) truth = [] with open(a) as f: for line in f.readlines(): worker, start_at = map(int, line.split()) truth.append(AssignedJob(worker=worker, start_at=start_at)) assert assign_jobs(n_workers, jobs) == truth
def test_something(self): self.assertEqual(assign_jobs(2, [2]), assign_jobs_fast(2, [2]))
from job_queue import assign_jobs, assign_jobs_slow n_workers = 2 jobs = [1, 2, 3, 4, 5] res = assign_jobs_slow(n_workers, jobs) for r in res: print(r.worker, r.started_at) res = assign_jobs(n_workers, jobs) for r in res: print(r.worker, r.started_at)
def test_assign_jobs_random(jobs, n_workers): assume(len(jobs) >= 1) assert assign_jobs(n_workers, jobs) == assign_jobs_naive(n_workers, jobs)