Ejemplo n.º 1
0
 def test_disjunction_of_line_matchers(self):
     eq_1 = IntSymbol('EQ_1')
     eq_2 = IntSymbol('EQ_2')
     arguments = tr.filter_lm__within_parens(
         arg_rend.disjunction([
             lm_arg.LineNum2(
                 im_args.comparison(
                     comparators.EQ,
                     SymbolReferenceWReferenceSyntax(eq_1.name))),
             lm_arg.LineNum2(
                 im_args.comparison(
                     comparators.EQ,
                     SymbolReferenceWReferenceSyntax(eq_2.name))),
         ]))
     m10 = ModelAndArguments(tr.model_lines(10), arguments)
     tr.check_cases__named(self, [
         m10.case__n(
             [eq_1.value(-10), eq_2.value(-5)],
             max_num_lines_from_iter=0,
             expected_output_lines=[],
         ),
         m10.case__n(
             [eq_1.value(-10), eq_2.value(5)],
             max_num_lines_from_iter=5,
             expected_output_lines=[5],
         ),
         m10.case__n(
             [eq_1.value(-10), eq_2.value(10 + 1)],
             max_num_lines_from_iter=10,
             expected_output_lines=[],
         ),
         m10.case__n(
             [eq_1.value(2), eq_2.value(5)],
             max_num_lines_from_iter=5,
             expected_output_lines=[2, 5],
         ),
         m10.case__n(
             [eq_1.value(2), eq_2.value(10 + 1)],
             max_num_lines_from_iter=10,
             expected_output_lines=[2],
         ),
         m10.case__n(
             [eq_1.value(10 + 1), eq_2.value(10 + 2)],
             max_num_lines_from_iter=10,
             expected_output_lines=[],
         ),
     ])
Ejemplo n.º 2
0
 def test_finite_w_conjunction_of_line_matchers(self):
     # ARRANGE #
     lower_limit = IntSymbol('lower_limit')
     upper_limit = IntSymbol('upper_limit')
     arguments = tr.filter_lm__within_parens(
         arg_rend.conjunction([
             lm_arg.LineNum2(
                 im_args.comparison(
                     comparators.GTE,
                     SymbolReferenceWReferenceSyntax(lower_limit.name))),
             lm_arg.LineNum2(
                 im_args.comparison(
                     comparators.LTE,
                     SymbolReferenceWReferenceSyntax(upper_limit.name))),
         ]))
     m10 = ModelAndArguments(tr.model_lines(10), arguments)
     cases = self._finite_w_conjunction__cases(m10, lower_limit,
                                               upper_limit)
     # ACT & ASSET #
     tr.check_cases__named(
         self,
         cases,
     )
Ejemplo n.º 3
0
 def test_negation_of_disjunction(self):
     # ARRANGE #
     model = [
         '1st\n',
         '2nd\n',
         '3rd\n',
     ]
     neg_open_lower_limit = IntSymbol('lower_limit')
     arguments = tr.filter_lm(
         arg_rend.negation(
             arg_rend.within_paren(
                 arg_rend.disjunction([
                     lm_arg.Contents(
                         sm_args.Equals(FileOrString.of_string('2nd'))),
                     lm_arg.LineNum2(
                         im_args.comparison(
                             comparators.GT,
                             SymbolReferenceWReferenceSyntax(
                                 neg_open_lower_limit.name))),
                 ]))))
     model_and_args = ModelAndArguments(model, arguments)
     # ACT & ASSET #
     tr.check_cases__named(
         self,
         [
             model_and_args.case__n(
                 [neg_open_lower_limit.value(1)],
                 max_num_lines_from_iter=3,
                 expected_output_lines=[1],
             ),
             model_and_args.case__n(
                 [neg_open_lower_limit.value(2)],
                 max_num_lines_from_iter=3,
                 expected_output_lines=[1],
             ),
             model_and_args.case__n(
                 [neg_open_lower_limit.value(3)],
                 max_num_lines_from_iter=3,
                 expected_output_lines=[1, 3],
             ),
         ],
     )
Ejemplo n.º 4
0
 def test_disjunction(self):
     # ARRANGE #
     model = [
         '1st\n',
         '2nd\n',
         '3rd\n',
     ]
     num_model_elements = len(model)
     upper_limit = IntSymbol('upper_limit')
     arguments = tr.filter_lm__within_parens(
         arg_rend.disjunction([
             lm_arg.Contents(sm_args.Equals(FileOrString.of_string('2nd'))),
             lm_arg.LineNum2(
                 im_args.comparison(
                     comparators.LTE,
                     SymbolReferenceWReferenceSyntax(upper_limit.name))),
         ]))
     model_and_args = ModelAndArguments(model, arguments)
     # ACT & ASSET #
     tr.check_cases__named(
         self,
         [
             model_and_args.case__n(
                 [upper_limit.value(-3)],
                 max_num_lines_from_iter=num_model_elements,
                 expected_output_lines=[2],
             ),
             model_and_args.case__n(
                 [upper_limit.value(2)],
                 max_num_lines_from_iter=num_model_elements,
                 expected_output_lines=_from_to(1, 2),
             ),
             model_and_args.case__n(
                 [upper_limit.value(10)],
                 max_num_lines_from_iter=num_model_elements,
                 expected_output_lines=_from_to(1, 3),
             ),
         ],
     )
Ejemplo n.º 5
0
 def runTest(self):
     self._check_cases([
         NArrEx(
             '! >= (within line-num-range)',
             arg_rend.negation(
                 args.LineNum2(im_args.comparison2(comparators.GTE, 4))),
             asrt_interval.matches_upper_limit(4 - 1)),
         NArrEx(
             '! >= (outside line-num-range)',
             arg_rend.negation(
                 args.LineNum2(
                     im_args.comparison2(comparators.LTE,
                                         FIRST_LINE_NUMBER - 1))),
             asrt_interval.matches_unlimited()),
         NArrEx('negation contents',
                arg_rend.negation(args.Contents(sm_args.Empty())),
                asrt_interval.matches_unlimited()),
         NArrEx('negation constant False',
                arg_rend.negation(arg_rend.constant(False)),
                asrt_interval.matches_unlimited()),
         NArrEx('negation constant True',
                arg_rend.negation(arg_rend.constant(True)),
                asrt_interval.matches_empty()),
         NArrEx(
             '> && <= (within line-num-range)',
             arg_rend.within_paren(
                 arg_rend.conjunction([
                     args.LineNum2(im_args.comparison2(comparators.GT, 7)),
                     args.LineNum2(im_args.comparison2(comparators.LTE,
                                                       12)),
                 ])), asrt_interval.matches_finite(7 + 1, 12)),
         NArrEx(
             '> && contents (within line-num-range)',
             arg_rend.within_paren(
                 arg_rend.conjunction([
                     args.LineNum2(im_args.comparison2(comparators.GT, 7)),
                     args.Contents(sm_args.Empty()),
                 ])), asrt_interval.matches_lower_limit(7 + 1)),
         NArrEx(
             'contents && contents',
             arg_rend.within_paren(
                 arg_rend.conjunction([
                     args.Contents(sm_args.Empty()),
                     args.Contents(sm_args.Empty()),
                 ])), asrt_interval.matches_unlimited()),
         NArrEx(
             '> && <= (partly outside line-num-range)',
             arg_rend.within_paren(
                 arg_rend.conjunction([
                     args.LineNum2(im_args.comparison2(comparators.GT, -7)),
                     args.LineNum2(im_args.comparison2(comparators.LTE,
                                                       12)),
                 ])), asrt_interval.matches_upper_limit(12)),
         NArrEx(
             '> && <= (completely outside line-num-range)',
             arg_rend.within_paren(
                 arg_rend.conjunction([
                     args.LineNum2(im_args.comparison2(comparators.GT, -7)),
                     args.LineNum2(im_args.comparison2(comparators.LTE,
                                                       -2)),
                 ])), asrt_interval.matches_empty()),
         NArrEx(
             '> && <= && <= (outside line-num-range)',
             arg_rend.within_paren(
                 arg_rend.conjunction([
                     args.LineNum2(im_args.comparison2(comparators.GT, -7)),
                     args.LineNum2(im_args.comparison2(comparators.LTE,
                                                       12)),
                     args.LineNum2(im_args.comparison2(comparators.LTE,
                                                       15)),
                 ])), asrt_interval.matches_upper_limit(12)),
         NArrEx(
             '== || <= (within line-num-range)',
             arg_rend.within_paren(
                 arg_rend.disjunction([
                     args.LineNum2(im_args.comparison2(comparators.EQ, 17)),
                     args.LineNum2(im_args.comparison2(comparators.LTE,
                                                       10)),
                 ])), asrt_interval.matches_upper_limit(17)),
         NArrEx(
             '== || contents (within line-num-range)',
             arg_rend.within_paren(
                 arg_rend.disjunction([
                     args.LineNum2(im_args.comparison2(comparators.EQ, 17)),
                     args.Contents(sm_args.Empty()),
                 ])), asrt_interval.matches_unlimited()),
         NArrEx(
             'contents || contents',
             arg_rend.within_paren(
                 arg_rend.disjunction([
                     args.Contents(sm_args.Empty()),
                     args.Contents(sm_args.Empty()),
                 ])), asrt_interval.matches_unlimited()),
         NArrEx(
             '> || == (outside line-num-range)',
             arg_rend.within_paren(
                 arg_rend.disjunction([
                     args.LineNum2(im_args.comparison2(comparators.GT, 5)),
                     args.LineNum2(im_args.comparison2(comparators.EQ,
                                                       -12)),
                 ])), asrt_interval.matches_lower_limit(5 + 1)),
         NArrEx(
             '< || <= (completely outside line-num-range)',
             arg_rend.within_paren(
                 arg_rend.disjunction([
                     args.LineNum2(im_args.comparison2(comparators.LT, -5)),
                     args.LineNum2(im_args.comparison2(comparators.LTE,
                                                       -3)),
                 ])), asrt_interval.matches_empty()),
         NArrEx(
             '<= || > || == (outside line-num-range)',
             arg_rend.within_paren(
                 arg_rend.disjunction([
                     args.LineNum2(im_args.comparison2(comparators.LTE, 0)),
                     args.LineNum2(im_args.comparison2(comparators.GT, 5)),
                     args.LineNum2(im_args.comparison2(comparators.EQ, 3)),
                 ])), asrt_interval.matches_lower_limit(3)),
         NArrEx(
             '<= || contents || == (within line-num-range)',
             arg_rend.within_paren(
                 arg_rend.disjunction([
                     args.LineNum2(im_args.comparison2(comparators.LTE,
                                                       12)),
                     args.Contents(sm_args.Empty()),
                     args.LineNum2(im_args.comparison2(comparators.EQ, 15)),
                 ])), asrt_interval.matches_unlimited()),
     ])
Ejemplo n.º 6
0
def filter_line_num(
        integer_matcher: ArgumentElementsRenderer) -> ArgumentElementsRenderer:
    return filter_lm(lm_arg.LineNum2(integer_matcher))