Пример #1
0
 def test_unique_one_d_to_mult_d(self) -> None:
     pattern = ((0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
                (10, 11, 12, 13, 14, 15, 16, 17, 18, 19),
                (20, 21, 22, 23, 24, 25, 26, 27, 28, 29))
     num_unique_combinations = 1000
     # Subtract 1 from num_unique_combinations because if max_sample_size == num_unique_combinations,
     # the sampling will fall back to joining without sampling. This leads to a 0.1% chance that
     # there is an error, given that num_unique_combinations is 1000.
     combo_options = ComboOptions(max_sample_size=num_unique_combinations - 1, with_replacement=False)
     actual_output = list(join_combo(pattern, combo_options=combo_options))
     self.assertEqual(len(set(actual_output)), len(actual_output))
Пример #2
0
 def _test_join_combo(self,
                      pattern: Sequence[Sequence],
                      expected_output: Iterable[Sequence],
                      *,
                      all_options: Optional[List[ComboOptions]] = None
                      ) -> None:
     expected_output = tuple(expected_output)
     if not all_options:
         all_options = [ComboOptions(max_sample_size=len(expected_output),
                                     with_replacement=False),
                        ComboOptions(max_sample_size=len(expected_output),
                                     with_replacement=True)]
     for combo_options in all_options:
         actual_output = list(join_combo(pattern, combo_options=combo_options))
         if combo_options.with_replacement:
             self.assertEqual(len(actual_output), combo_options.max_sample_size)
         else:
             self.assertEqual(len(actual_output), len(set(actual_output)))
             self.assertEqual(len(actual_output), min(len(expected_output), combo_options.max_sample_size))
         for actual in actual_output:
             self.assertIn(actual, expected_output)
Пример #3
0
 def test_combo_options_with_replacement(self) -> None:
     utterance_combo = (('he will want', 'she will want'), ('to play',
                                                            'to listen'))
     tokens = ('START', 'PLAY')
     groups = (('None', 1), ('None', 1))
     combo_options = ComboOptions(max_sample_size=6, with_replacement=True)
     _, generator = combine(utterance_combo,
                            tokens,
                            groups,
                            combo_options=combo_options)
     actual_utterances, actual_handled_tokens, actual_handled_groups = zip(
         *generator)
     expected_utterances = ('she will want to listen',
                            'she will want to listen',
                            'he will want to play', 'she will want to play',
                            'she will want to listen',
                            'she will want to listen')
     expected_handled_tokens = (('[START(she will want)]',
                                 '[PLAY(to listen)]'),
                                ('[START(she will want)]',
                                 '[PLAY(to listen)]'),
                                ('[START(he will want)]',
                                 '[PLAY(to play)]'),
                                ('[START(she will want)]',
                                 '[PLAY(to play)]'),
                                ('[START(she will want)]',
                                 '[PLAY(to listen)]'),
                                ('[START(she will want)]',
                                 '[PLAY(to listen)]'))
     expected_handled_groups = (('{None([START(she will want)])}',
                                 '{None([PLAY(to listen)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to listen)])}'),
                                ('{None([START(he will want)])}',
                                 '{None([PLAY(to play)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to play)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to listen)])}'),
                                ('{None([START(she will want)])}',
                                 '{None([PLAY(to listen)])}'))
     pairs = [(actual_utterances, expected_utterances),
              (actual_handled_tokens, expected_handled_tokens),
              (actual_handled_groups, expected_handled_groups)]
     compare_all_pairs(self, pairs)
Пример #4
0
 def test_invalid_combo_options(self) -> None:
     with self.assertRaises(ValueError):
         ComboOptions(max_sample_size=0, with_replacement=False)