Example #1
0
def distance_test():
    word1 = "*ucking"
    word2 = "f*****g"
    assert distance(word1, word2) == 1
    word1 = "fcking"
    word2 = "f*****g"
    assert distance(word1, word2) == 1
    word1 = "ffucking"
    word2 = "f*****g"
    assert distance(word1, word2) == 1
Example #2
0
def invite(customers):
    """Return an array

    This function filters out customers that are farther than 100 km from the Dublin office
    """

    # Init variable to store invites
    invitees = []

    for customer in customers: # For each customer
        customer_location = Point(float(customer['latitude']), float(customer['longitude']))
        customer_distance_to_office = distance(customer_location, DUBLIN_OFFICE_LOCATION) # Calc distance to Dublin office
        if customer_distance_to_office <= 100.0: # If within 100 km invite customer to Dublin office
            invitees.append(customer)

    return invitees
Example #3
0
def detect_close_tweets(text):
    global insults
    global dictionary
    text = TextBlob(text)
    insulting = False
    offensive_words = []
    insult_words = []
    for word in text.words:
        for insult_word in insults:
            if distance(word.casefold(), insult_word.casefold()) < 2 and not (
                    word.casefold() in dictionary):
                insulting = True
                offensive_words.append(word)
                insult_words.append(insult_word.casefold())
        # if insulting == True:
        #     print("It looks like an insult.")
        # else:
        #     print("It doesn't look like an insult.")
    return (insulting, offensive_words, insult_words)
Example #4
0
 def test_sydney_to_seattle(self):
     dist = distance(47.60621, -122.33207, -33.86785, 151.20732)
     self.assertEqual(dist, 12470)
Example #5
0
 def test_sydney_to_hobart(self):
     dist = distance(-42.87936, 147.32941, -33.86785, 151.20732)
     self.assertEqual(dist, 1057)
Example #6
0
 def test_dublin_to_frankfurt(self):
     dist = distance(53.33306, -6.24889, 50.11552, 8.68417)
     self.assertEqual(dist, 1086)
Example #7
0
def test_distance_to_London():
    London = Point(51.5074, -0.1278)
    dist = distance(London, DUBLIN_OFFICE_LOCATION)
    assert dist == pytest.approx(463, 1)
Example #8
0
def test_distance_order_insensitive():
    London = Point(51.5074, -0.1278)
    dist1 = distance(DUBLIN_OFFICE_LOCATION, London)
    dist2 = distance(London, DUBLIN_OFFICE_LOCATION)
    assert dist1 == pytest.approx(dist2, 0.001)
Example #9
0
def test_distance_to_Dublin():
    dist = distance(DUBLIN_OFFICE_LOCATION, DUBLIN_OFFICE_LOCATION)
    assert dist == pytest.approx(0, 0.001)