Ejemplo n.º 1
0
def searchData(unsortedList, sortedList):
    """
    This function runs the two searching algorithms and tracks there data.
    Input: Sorted and unsorted list
    Output: text file of data
    """
    # Begin by testing the binary search
    binarySearchData = []
    linearSearchData = []

    # the range of testing the list begins at zero
    testRange = 0

    # get a value that is known not to be in the list
    target = 0
    while target in sortedList:
        target += 1

    for i in range(len(sortedList) + 1):
        binarySearchCount = Searches.binarySearch(sortedList[:testRange],
                                                  target)
        binarySearchData.append(binarySearchCount[1])

        linearSearchCount = Searches.linearSearch(sortedList[:testRange],
                                                  target)
        linearSearchData.append(linearSearchCount[1])

        testRange += 1

    # Wrtie the search data to text file
    writeSearchDataToText(binarySearchData, linearSearchData)
Ejemplo n.º 2
0
    def move(self):
        Resources.display()
        node = Resources.Node((self.row, Resources.BOARD))

        highest_val, best_move = search.search(node, self.row)
        print "%s moves" % self.name, best_move
        return do_move(best_move, self.row, Resources.BOARD)
Ejemplo n.º 3
0
 def H(self, state):
     if (state == self.destination):
         return 0
     problem = RomanianRouting(state, self.destination)
     a, b, c, d, e = Searches.UCSGraph(problem)
     if (b > 211):
         b -= 211
     else:
         b = 0
     return b
Ejemplo n.º 4
0
    def move(self):
        b = Resources.BOARD
        s = Resources.BOARD_SIZE
        if not any(Resources.BOARD[self.row*s+1:(self.row+1)*s-1]):
            print "%s's row is empty. giving turn to next player" % self.name
            return (self.row+1)%Resources.NUM_PLAYERS, None
        
        Resources.display()
        node = Resources.Node((self.row, Resources.BOARD))

        highest_val, best_move = search.search(node, self)
        print '%s moves' % self.name, best_move
        return do_move(best_move, self.row, Resources.BOARD)
Ejemplo n.º 5
0
            res.append('MH  - %s' % (keyword))

    return '\n'.join(res)


def GetSearchURL(term, db="PubMed"):
    queryParams = {'CMD': 'search', 'DB': db, 'term': term}
    url = '%s?%s' % (QueryParams.queryBase, urllib.urlencode(queryParams))
    return url


#------------------------------------
#
#  doctest boilerplate
#
def _test():
    import doctest, sys
    return doctest.testmod(sys.modules["__main__"])


if __name__ == '__main__':
    import sys, os.path
    failed, tried = _test()
    sys.exit(failed)

    import Searches
    recs = Searches.GetRecords(['11960484', '10893315'],
                               conn=open('test_data/records.xml', 'r'))
    res = RecordsToPubmedText(recs)
    print(res)
Ejemplo n.º 6
0
#for cleared balance: get the list of the history of cleared balance calculations
objFile = open("ClearedBalanceRecord.dat", "rb")
ClearedBalLst = pickle.load(objFile)
ClearedBal = ClearedBalLst[-1][0]  #this is the most recent cleared balance
objFile.close()

#for transaction record, get stored data:
LstTrans = StoreData.RetrieveTransLst()

#Each separate transaction is a list.  Balance is the last item in the list.
#  The last item of the last transaction in LstTrans is the final balance.
Balance = LstTrans[-1][-1]

print("Welcome to the checking account register\n")
print("Ending balance:", Balance)
print("Today's balance:", Searches.GetTodaysBalance(LstTrans))
print("Cleared balance:", ClearedBal)
print("Last unique ID:", intUniqueId)
#Print the last 10 transactions on opening the script:
print(
    "\nLast 10 transactions--------------------------------------------------")
LstRecentTrans = LstTrans[-10:]
Presentation.PrintRegister(LstRecentTrans)

#----------------I/O-------------------------------------------------------

while True:
    print("""
    MENU of options:
    Enter a debit......................w
    Enter a deposit....................d
Ejemplo n.º 7
0
 def testLower(self):
     self.assertEqual(
         Searches.rangeBsearchLower(self.case1[0], self.case1[1],
                                    self.search_data), 0)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case2[0], self.case2[1],
                                    self.search_data), 0)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case3[0], self.case3[1],
                                    self.search_data), 0)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case4[0], self.case4[1],
                                    self.search_data), 0)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case5[0], self.case5[1],
                                    self.search_data), 0)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case6[0], self.case6[1],
                                    self.search_data), 2)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case7[0], self.case7[1],
                                    self.search_data), 3)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case8[0], self.case8[1],
                                    self.search_data), 3)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case9[0], self.case9[1],
                                    self.search_data), 3)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case10[0], self.case10[1],
                                    self.search_data), 3)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case11[0], self.case11[1],
                                    self.search_data), 4)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case12[0], self.case12[1],
                                    self.search_data), 6)
     self.assertEqual(
         Searches.rangeBsearchLower(self.case13[0], self.case13[1],
                                    self.search_data), 7)
Ejemplo n.º 8
0
    def testRangeAll(self):
        empty_data = []

        self.assertEqual(
            Searches.rangeBsearch(self.case1[0], self.case1[1], empty_data),
            [])

        self.assertEqual(
            Searches.rangeBsearch(self.case1[0], self.case1[1],
                                  self.search_data), [])
        self.assertEqual(
            Searches.rangeBsearch(self.case2[0], self.case2[1],
                                  self.search_data), [0, 1])
        self.assertEqual(
            Searches.rangeBsearch(self.case3[0], self.case3[1],
                                  self.search_data), [0, 1])
        self.assertEqual(
            Searches.rangeBsearch(self.case4[0], self.case4[1],
                                  self.search_data), [0, 3])
        self.assertEqual(
            Searches.rangeBsearch(self.case5[0], self.case5[1],
                                  self.search_data), [0, 3])
        self.assertEqual(
            Searches.rangeBsearch(self.case6[0], self.case6[1],
                                  self.search_data), [2, 3])
        self.assertEqual(
            Searches.rangeBsearch(self.case7[0], self.case7[1],
                                  self.search_data), [])
        self.assertEqual(
            Searches.rangeBsearch(self.case8[0], self.case8[1],
                                  self.search_data), [])
        self.assertEqual(
            Searches.rangeBsearch(self.case9[0], self.case9[1],
                                  self.search_data), [3, 4])
        self.assertEqual(
            Searches.rangeBsearch(self.case10[0], self.case10[1],
                                  self.search_data), [3, 4])
        self.assertEqual(
            Searches.rangeBsearch(self.case11[0], self.case11[1],
                                  self.search_data), [4, 6])
        self.assertEqual(
            Searches.rangeBsearch(self.case12[0], self.case12[1],
                                  self.search_data), [6, 7])
        self.assertEqual(
            Searches.rangeBsearch(self.case13[0], self.case13[1],
                                  self.search_data), [])