コード例 #1
0
  def test_cardinality_bounds_2_indirect(self):
    predicate = jp.CardinalityPredicate(_AorB,
                                        min=lambda x: x['min'],
                                        max=lambda x: x['max'])
    for min in range(0, 3):
      for max in range(0, 3):
        if min > max:
          continue

        context = ExecutionContext(min=min, max=max)
        expect_ok = min <= 2 and max >= 2

        source = _CAB
        result = predicate(context, source)

        all_results = [
            jp.SequencedPredicateResult(
                False, _AorB,
                [jp.PathValueResult(_CAB, '', PathValue('[0]', 'C'),
                                    valid=False, pred=_eq_A),
                 jp.PathValueResult(_CAB, '', PathValue('[0]', 'C'),
                                    valid=False, pred=_eq_B)]),
            jp.SequencedPredicateResult(
                True, _AorB,
                [jp.PathValueResult(_CAB, '', PathValue('[1]', 'A'),
                                    valid=True, pred=_eq_A)]),
            jp.SequencedPredicateResult(
                True, _AorB,
                [jp.PathValueResult(_CAB, '', PathValue('[2]', 'B'),
                                    valid=False, pred=_eq_A),
                 jp.PathValueResult(_CAB, '', PathValue('[2]', 'B'),
                                    valid=True, pred=_eq_B)])]

        builder = jp.PathPredicateResultBuilder(
            pred=jp.PathPredicate('', _AorB), source=_CAB)
        builder.add_result_candidate(PathValue('[0]', 'C'), all_results[0])
        builder.add_result_candidate(PathValue('[1]', 'A'), all_results[1])
        builder.add_result_candidate(PathValue('[2]', 'B'), all_results[2])
        expect_path_result = builder.build(True)

        if expect_ok:
          self.assertEqual(
              jp.ConfirmedCardinalityResult(predicate, expect_path_result),
              result)
        elif max == 0:
          self.assertEqual(
              jp.UnexpectedValueCardinalityResult(
                  predicate, expect_path_result),
              result)
        else:
          self.assertEqual(
              jp.FailedCardinalityRangeResult(
                  predicate, expect_path_result),
              result)
コード例 #2
0
    def test_cardinality_bounds_1(self):
        for min in range(0, 3):
            for max in range(0, 3):
                if min > max:
                    continue

                predicate = jp.CardinalityPredicate(_AorX, min=min, max=max)
                expect_ok = min <= 1 and max >= 1

                source = _CAB
                result = predicate(source)

                all_results = [
                    jp.CompositePredicateResult(False, _AorX, [
                        jp.PathValueResult(_CAB,
                                           '',
                                           PathValue('[0]', 'C'),
                                           valid=False,
                                           pred=_eq_A),
                        jp.PathValueResult(_CAB,
                                           '',
                                           PathValue('[0]', 'C'),
                                           valid=False,
                                           pred=_eq_X)
                    ]),
                    jp.CompositePredicateResult(True, _AorX, [
                        jp.PathValueResult(_CAB,
                                           '',
                                           PathValue('[1]', 'A'),
                                           valid=True,
                                           pred=_eq_A)
                    ]),
                    jp.CompositePredicateResult(False, _AorX, [
                        jp.PathValueResult(_CAB,
                                           '',
                                           PathValue('[2]', 'B'),
                                           valid=False,
                                           pred=_eq_A),
                        jp.PathValueResult(_CAB,
                                           '',
                                           PathValue('[2]', 'B'),
                                           valid=False,
                                           pred=_eq_X)
                    ])
                ]

                builder = jp.PathPredicateResultBuilder(pred=jp.PathPredicate(
                    '', _AorX),
                                                        source=_CAB)
                builder.add_result_candidate(PathValue('[0]', 'C'),
                                             all_results[0])
                builder.add_result_candidate(PathValue('[1]', 'A'),
                                             all_results[1])
                builder.add_result_candidate(PathValue('[2]', 'B'),
                                             all_results[2])

                expect_path_result = builder.build(True)
                if expect_ok:
                    self.assertEqual(
                        jp.ConfirmedCardinalityResult(predicate,
                                                      expect_path_result),
                        result)
                elif max == 0:
                    self.assertEqual(
                        jp.UnexpectedValueCardinalityResult(
                            predicate, expect_path_result), result)
                else:
                    self.assertEqual(
                        jp.FailedCardinalityRangeResult(
                            predicate, expect_path_result), result)