Beispiel #1
0
 def test_top_prefixes(self):
     with TestPipeline() as p:
         words = p | beam.Create(self.WORDS)
         result = words | autocomplete.TopPerPrefix(5)
         # values must be hashable for now
         result = result | beam.Map(lambda k_vs: (k_vs[0], tuple(k_vs[1])))
         assert_that(result, equal_to(self.EXPECTED_PREFIXES))
Beispiel #2
0
    def test_autocomplete_it(self):
        with TestPipeline(is_integration_test=True) as p:
            words = p | beam.io.ReadFromText(self.KINGLEAR_INPUT)
            result = words | autocomplete.TopPerPrefix(10)
            # values must be hashable for now
            result = result | beam.Map(lambda k_vs: (k_vs[0], tuple(k_vs[1])))
            checksum = result | beam.Map(hash) | beam.CombineGlobally(sum)

            assert_that(checksum, equal_to([self.KINGLEAR_HASH_SUM]))
Beispiel #3
0
 def test_top_prefixes(self):
     with TestPipeline() as p:
         words = p | beam.Create(self.WORDS)
         result = words | autocomplete.TopPerPrefix(5)
         # values must be hashable for now
         result = result | beam.Map(lambda k_vs: (k_vs[0], tuple(k_vs[1])))
         assert_that(
             result,
             equal_to([
                 ('t', ((3, 'to'), (2, 'this'), (1, 'that'))),
                 ('to', ((3, 'to'), )),
                 ('th', ((2, 'this'), (1, 'that'))),
                 ('thi', ((2, 'this'), )),
                 ('this', ((2, 'this'), )),
                 ('tha', ((1, 'that'), )),
                 ('that', ((1, 'that'), )),
             ]))