Esempio n. 1
0
def test_find_groups():
    group1 = [1, 2, 2, 2, 3, 4, 4, 5, 6, 6, 6, 6]
    group2 = list(range(12))

    assert find_groups(group1) == [(0, 0), (1, 3), (4, 4), (5, 6), (7, 7),
                                   (8, 11)]
    assert find_groups(group2) == [(i, i) for i in range(12)]
Esempio n. 2
0
def test_find_groups_models():
    person1 = type_and_instance_attr_eq('Person',
                                        'age',
                                        name="Name 1",
                                        nickname="Nickname 1",
                                        birthday=date(2011, 6, 22),
                                        age=99,
                                        memory=True)

    person2 = type_and_instance_attr_eq('Person',
                                        'age',
                                        name="Name 2",
                                        nickname="Nickname 2",
                                        birthday=date(2011, 6, 22),
                                        age=50,
                                        memory=True)

    person3 = type_and_instance_attr_eq('Person',
                                        'age',
                                        name="Name 3",
                                        nickname="Nickname 3",
                                        birthday=date(2011, 4, 20),
                                        age=50,
                                        memory=True)

    person4 = type_and_instance_attr_eq('Person',
                                        'age',
                                        name="Name 4",
                                        nickname="Nickname 4",
                                        birthday=date(2010, 6, 20),
                                        age=1,
                                        memory=True)

    from operator import attrgetter
    data = sorted([person1, person2, person3, person4], key=attrgetter('age'))

    assert find_groups([d.age for d in data]) == [(0, 0), (1, 2), (3, 3)]
    assert find_groups(data) == [(0, 0), (1, 2), (3, 3)]
    assert find_groups(data, attr='age') == [(0, 0), (1, 2), (3, 3)]

    data = sorted([person1, person2, person3, person4],
                  key=attrgetter('birthday'))
    assert find_groups(data, attr='birthday') == [(0, 0), (1, 1), (2, 3)]
Esempio n. 3
0
def test_find_groups_models():
    person1 = type_and_instance_attr_eq('Person',
                                        'age',
                                        name="Name 1",
                                        nickname="Nickname 1",
                                        birthday=date(2011, 6, 22),
                                        age=99,
                                        memory=True)

    person2 = type_and_instance_attr_eq('Person',
                                        'age',
                                        name="Name 2",
                                        nickname="Nickname 2",
                                        birthday=date(2011, 6, 22),
                                        age=50,
                                        memory=True)

    person3 = type_and_instance_attr_eq('Person',
                                        'age',
                                        name="Name 3",
                                        nickname="Nickname 3",
                                        birthday=date(2011, 4, 20),
                                        age=50,
                                        memory=True)

    person4 = type_and_instance_attr_eq('Person',
                                        'age',
                                        name="Name 4",
                                        nickname="Nickname 4",
                                        birthday=date(2010, 6, 20),
                                        age=1,
                                        memory=True)

    from operator import attrgetter
    data = sorted([person1, person2, person3, person4], key=attrgetter('age'))

    assert find_groups([d.age for d in data]) == [(0,0), (1,2), (3,3)]
    assert find_groups(data) == [(0,0), (1,2), (3,3)]
    assert find_groups(data, attr='age') == [(0,0), (1,2), (3,3)]

    data = sorted([person1, person2, person3, person4], key=attrgetter('birthday'))
    assert find_groups(data, attr='birthday') == [(0,0), (1,1), (2,3)]
Esempio n. 4
0
def test_find_groups():
    group1 = [1, 2, 2, 2, 3, 4, 4, 5, 6, 6, 6, 6]
    group2 = list(range(12))

    assert find_groups(group1) == [(0,0), (1,3), (4,4), (5,6), (7,7), (8,11)]
    assert find_groups(group2) == [(i, i) for i in range(12)]