Beispiel #1
0
 def test_long_slowlygeneratedarray(self): #Verify that the "compare_all_despite_starvation" works even when being forced to wait
     testarray = [x for x in range(50)]
     total = 0 #We will test that all pairs are summed by getting the total of all pair additions
     paircount = 0
     for i, n1 in enumerate(testarray):
         for j, n2 in enumerate(testarray):
             if i < j:
                 paircount = paircount +1
                 total = total + n1 + n2
     testarray2 = [-1 for unused in range(50)]
     l = threading.Lock()
     t = threading.Thread(target=slowarray, args=((testarray2,),l,0.04))
     t.start()
     result = [0,]
     Utility.compare_all_despite_starvation(testarray2, len(testarray2), testfunc, 0.02, (result,l))
     self.assertEqual(total, result.pop())
Beispiel #2
0
 def test_short_starved_compare_quick(self): #Verify that the "compare_all_despite_starvation" method works identical to a simple double loop
     testarray = [x for x in range(12)]
     total = 0 #We will test that all pairs are summed by getting the total of all pair additions
     paircount = 0
     for i, n1 in enumerate(testarray):
         for j, n2 in enumerate(testarray):
             if i < j:
                 paircount = paircount +1
                 total = total + n1 + n2
     testarray2 = [-1 for unused in range(12)]
     l = threading.Lock()
     t = threading.Thread(target=slowarray, args=((testarray2,),l,0))
     t.start()
     result = [0,]
     Utility.compare_all_despite_starvation(testarray2, len(testarray2), testfunc, 0, (result,l))
     self.assertEqual(total, result.pop())
Beispiel #3
0
def book_comparator(library, bookids):
    Utility.compare_all_despite_starvation(bookids, len(bookids), book_compare_helper, 0, library)