def test_upper_limit(self): upper_limit = IntSymbol('UPPER_LIMIT') arguments = tr.filter_line_num( im_args.comparison( comparators.LTE, SymbolReferenceWReferenceSyntax(upper_limit.name))) m10 = ModelAndArguments(tr.model_lines(10), arguments) tr.check_cases__named(self, [ m10.case__n( [upper_limit.value(-3)], max_num_lines_from_iter=0, expected_output_lines=[], ), m10.case__n( [upper_limit.value(1)], max_num_lines_from_iter=1, expected_output_lines=[1], ), m10.case__n( [upper_limit.value(5)], max_num_lines_from_iter=5, expected_output_lines=_from_to(1, 5), ), ] + m10.equivalent_cases__n( [ [upper_limit.value(10)], [upper_limit.value(10 + 1)], ], max_num_lines_from_iter=10, expected_output_lines=_from_to(1, 10), ))
def test_point(self): int_sym = IntSymbol('eq_value') arguments = tr.filter_line_num( im_args.comparison(comparators.EQ, SymbolReferenceWReferenceSyntax(int_sym.name))) m10 = ModelAndArguments(tr.model_lines(10), arguments) tr.check_cases__named(self, [ m10.case__n( [int_sym.value(1)], max_num_lines_from_iter=1, expected_output_lines=[1], ), m10.case__n( [int_sym.value(5)], max_num_lines_from_iter=5, expected_output_lines=[5], ), m10.case__n( [int_sym.value(10)], max_num_lines_from_iter=10, expected_output_lines=[10], ), m10.case__n( [int_sym.value(11)], max_num_lines_from_iter=10, expected_output_lines=[], ), ] + m10.equivalent_cases__n( [ [int_sym.value(0)], [int_sym.value(-1)], ], max_num_lines_from_iter=0, expected_output_lines=[], ))
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=[], ), ])
def test_lower_limit(self): lower_limit = IntSymbol('LOWER_LIMIT') arguments = tr.filter_line_num( im_args.comparison( comparators.GTE, SymbolReferenceWReferenceSyntax(lower_limit.name))) m10 = ModelAndArguments(tr.model_lines(10), arguments) cases = _cases_for_lower_limit(m10, lower_limit) tr.check_cases__named( self, cases, )
def test_negation_of_line_matcher(self): lower_limit = IntSymbol('NEGATED_UPPER_LIMIT__OPEN') arguments = tr.filter_line_num( arg_rend.negation( im_args.comparison( comparators.LT, SymbolReferenceWReferenceSyntax(lower_limit.name)))) m10 = ModelAndArguments(tr.model_lines(10), arguments) cases = _cases_for_lower_limit(m10, lower_limit) tr.check_cases__named( self, cases, )
def test_finite_w_conjunction_of_integer_matchers(self): # ARRANGE # lower_limit = IntSymbol('lower_limit') upper_limit = IntSymbol('upper_limit') arguments = tr.filter_lm( lm_arg.LineNum2( arg_rend.within_paren( arg_rend.conjunction([ im_args.comparison( comparators.GTE, SymbolReferenceWReferenceSyntax(lower_limit.name)), 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, )
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], ), ], )
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), ), ], )
def test_symbols_from_comparison_SHOULD_be_reported(self): # ARRANGE # checked_dir_contents = DirContents([File.empty('1'), File.empty('2')]) checked_path = rel_opts.conf_rel_sds(RelSdsOptionType.REL_ACT) operand_sym_ref = StringIntConstantSymbolContext( 'operand_symbol_name', len(checked_dir_contents.file_system_elements), default_restrictions=symbol_reference. is_reference_restrictions__integer_expression(), ) matcher_arguments = im_args.comparison(comparators.EQ, operand_sym_ref.argument) # ACT & ASSERT # integration_check.CHECKER__PARSE_SIMPLE.check( self, args.NumFiles( matcher_arguments.as_str, int_expr_on_new_line=True, ).as_remaining_source, model.model_with_rel_root_as_source_path(checked_path), arrangement_w_tcds( symbols=operand_sym_ref.symbol_table, tcds_contents=checked_path. populator_for_relativity_option_root(checked_dir_contents), ), Expectation( ParseExpectation( source=asrt_source.is_at_end_of_line(2), symbol_references=operand_sym_ref.references_assertion, ), ExecutionExpectation( main_result=asrt_matching_result.matches_value(True)), ))