'Ensure that item frequencies are properly generated from lists.'

def test_item_frequencies_on_embedded(self):

    class Phone(EmbeddedDocument, ):
        number = StringField()
    class Person(Document, ):
        name = StringField()
        phone = EmbeddedDocumentField(Phone)
    Person.drop_collection()
    doc = Person(name='Guido')
    doc.phone = Phone(number='62-3331-1656')
    doc.save()
    doc = Person(name='Marr')
    doc.phone = Phone(number='62-3331-1656')
    doc.save()
    doc = Person(name='WP    Junior')
    doc.phone = Phone(number='62-3332-1656')
    doc.save()
    def test_assertions(f):
        f = {key: int(val) for (key, val) in f.items()}
        self.assertEqual(set(['62-3331-1656', '62-3332-1656']), set(f.keys()))
        self.assertEqual(f['62-3331-1656'], 2)
        self.assertEqual(f['62-3332-1656'], 1)
    exec_js = Person.objects.item_frequencies('phone.number')
    map_reduce = Person.objects.item_frequencies('phone.number', map_reduce=True)
    test_assertions(exec_js)
    test_assertions(map_reduce)
    def test_assertions(f):
        f = {key: int(val) for (key, val) in f.items()}
        self.assertEqual(set(['62-3331-1656']), set(f.keys()))
        self.assertEqual(f['62-3331-1656'], 2)
    exec_js = Person.objects(phone__number='62-3331-1656').item_frequencies('phone.number')
    map_reduce = Person.objects(phone__number='62-3331-1656').item_frequencies('phone.number', map_reduce=True)
    test_assertions(exec_js)
    test_assertions(map_reduce)
    def test_assertions(f):
        self.assertEqual(f['62-3331-1656'], (2.0 / 3.0))
        self.assertEqual(f['62-3332-1656'], (1.0 / 3.0))
    exec_js = Person.objects.item_frequencies('phone.number', normalize=True)
    map_reduce = Person.objects.item_frequencies('phone.number', normalize=True, map_reduce=True)
    test_assertions(exec_js)
    test_assertions(map_reduce)
