Exemplo n.º 1
0
def test_grocerylist_compare_with():
    superset = ['50-100g smør', 'salt', 'chili', '1 ts kanel', '10 ounces sukker']
    subset = ['0.05 kg smør', 'salt', 'chili', '3/4 teskje kanel']
    subset_mismatch = ['0.05 kg smør', 'salat', 'chilli', 'kanel']
    no_match = ['nisse', '1 kg troll', 'esel']

    superset_list = groceries.GroceryList(superset)

    groceries.Ingredient('1 ts kanel').contains(groceries.Ingredient('kanel'))

    assert superset_list.compare_with(groceries.GroceryList(subset)) == 1
    assert 0.4 <= superset_list.compare_with(groceries.GroceryList(subset_mismatch)) <= 0.6
    assert superset_list.compare_with(groceries.GroceryList(no_match)) == 0
Exemplo n.º 2
0
def test_ingredient_contains():
    superset = groceries.Ingredient('100 g rød chili')
    subset = groceries.Ingredient('50 g rød chili')
    too_much = groceries.Ingredient('150 g rød chili')
    close_match = groceries.Ingredient('50 g rød chilli')

    fuzzy_limit = 0.8

    assert superset.contains(subset, aprox_name_limit=1)
    assert superset.contains(superset, aprox_name_limit=1)
    assert not superset.contains(too_much, aprox_name_limit=1)
    assert superset.contains(too_much, amount=False, aprox_name_limit=1)  # Test amount flag for contains.

    assert not superset.contains(close_match, aprox_name_limit=1)
    assert superset.contains(close_match, aprox_name_limit=fuzzy_limit)

    no_amount_superset = groceries.Ingredient('paprikapotetgull')
    no_amount_subset_close_match = groceries.Ingredient('paprikepotetgull')
    no_amount_subset_not_close = groceries.Ingredient('poprika pottegul')
    no_amount_subset_mismatch = groceries.Ingredient('nisse')

    assert no_amount_superset.contains(no_amount_superset)
    assert no_amount_superset.contains(no_amount_subset_close_match, aprox_name_limit=fuzzy_limit)
    assert not no_amount_superset.contains(no_amount_subset_close_match, aprox_name_limit=100)
    assert no_amount_superset.contains(no_amount_subset_not_close, aprox_name_limit=fuzzy_limit)
    assert not no_amount_superset.contains(no_amount_subset_not_close, aprox_name_limit=90)
    assert not no_amount_superset.contains(no_amount_subset_mismatch, aprox_name_limit=fuzzy_limit)
Exemplo n.º 3
0
def test_grocerylist_contains():
    superset = ['50-100g smør', 'salt', 'chili', '1 ts kanel', '10 ounces sukker']
    superset_list = groceries.GroceryList(superset)

    for item in superset:
        assert superset_list.contains(groceries.Ingredient(item))

    not_contains = ['salat', 'senep', 'brød', 'suketter']

    for item in not_contains:
        assert not superset_list.contains(groceries.Ingredient(item))

    contains_without_amount = ['200 g smør', '1 oz kanel', '100 tonn sukker']

    for item in contains_without_amount:
        assert not superset_list.contains(groceries.Ingredient(item))
        assert superset_list.contains(groceries.Ingredient(item), amount=False)
Exemplo n.º 4
0
def test_ingredient():
    candidate_list = [
        u'ca. 1/2 rød chili,  finhakket',
        u'1 rød chili (uten frø)',
        u'2/3 løk',
        u'ca. 1 1/2 teskjeer soyasaus',
        u'10 ts soyasaus',
        u'4 bananer',
        u'olivenolje'
    ]

    expected_list = [
        u'2/3 l\xf8k',
        u'1 1/2 rød chili',
        u'0.57 dl soyasaus',
        u'4 bananer',
        u'olivenolje'
    ]

    # Which of the above ingredienst should combine with each other.
    combination_true_indexes = [(0, 1), (0, 1), (2,), (3, 4), (3, 4)]

    ingredients = []
    for example in candidate_list:
        ingredients += [groceries.Ingredient(example)]

    # Check ability to compare objects.
    for indexes in combination_true_indexes:
        if len(indexes) > 1:
            assert ingredients[indexes[0]] == ingredients[indexes[1]]

    # Check ability to combine objects.
    combine_list = {}
    for ing, m in zip(ingredients, range(len(ingredients))):
        if not ing.id in combine_list:
            combine_list[ing.id] = ing
        else:
            combine_list[ing.id].combine_with_ingredient(ing)

    # Check output from component dictionary return:
    for ing in combine_list.values():
        assert ing.ingredient_formatted() in expected_list
Exemplo n.º 5
0
def test_ingredient_contains_simple_string_mismatch():
    assert not groceries.Ingredient('salt').contains(groceries.Ingredient('salat'))