public void GetInverse_ReturnsIntersectExpressionWithTwoSubexpressionsOfLength3_WhenOriginalExpressionContains3SubExpressionsWithMiddleExpressionOfRepeatIntervalFrom1To2()
        {
            var repeatInterval = new IntegerInterval();

            repeatInterval.TrySetValue(1, 2);
            var inverseSubExpression = Substitute.For <IExpression>();

            inverseSubExpression.GetInverse().Returns(Substitute.For <IExpression>());
            var subExpression = Substitute.For <IExpression>();

            subExpression.GetInverse().Returns(inverseSubExpression);
            subExpression.RepeatRange.Returns(repeatInterval);
            subExpression.ExpansionLength.Returns(2);
            var concatExpression = new ConcatenationExpression(_randomGenerator);

            concatExpression.Append(inverseSubExpression).Append(subExpression).Append(inverseSubExpression);

            var result = concatExpression.GetInverse();

            Assert.IsInstanceOf <IntersectionExpression>(result);

            var resultAsList = ((IntersectionExpression)result).ToConcatExpressionList();

            Assert.AreEqual(2, resultAsList.Count);
            Assert.AreEqual(3, ((UnionExpression)resultAsList[0]).ToIntersectionExpressionList().Count);
            Assert.AreEqual(4, ((UnionExpression)resultAsList[1]).ToIntersectionExpressionList().Count);
        }
        public void GetInverse_ReturnsIntersectExpressionWithTwoSubexpressionsEachHavingRepeatIntervalNull_WhenOriginalExpressionContainsSingleSubExpressionWithRepeatIntervalFrom1To2()
        {
            var repeatInterval = new IntegerInterval();

            repeatInterval.TrySetValue(1, 2);
            var inverseSubExpression = Substitute.For <IExpression>();
            var subExpression        = Substitute.For <IExpression>();

            subExpression.GetInverse().Returns(inverseSubExpression);
            subExpression.RepeatRange.Returns(repeatInterval);
            subExpression.ExpansionLength.Returns(2);
            var concatExpression = new ConcatenationExpression(_randomGenerator);

            concatExpression.Append(subExpression);

            var result = concatExpression.GetInverse();

            Assert.IsInstanceOf <IntersectionExpression>(result);

            var resultAsList = ((IntersectionExpression)result).ToConcatExpressionList();

            Assert.AreEqual(2, resultAsList.Count);
            Assert.IsNull(resultAsList[0].RepeatRange);
            Assert.IsNull(resultAsList[1].RepeatRange);
        }
        public void Expand_ReturnsListContaining3ElementsOfLength4_WhenOneExpandableExpressionWith3PossibleSubexpressionsIsContained()
        {
            var mockA = new StringBuilderMock(ToCharacterClassList("a"));
            var mock1 = new StringBuilderMock(ToCharacterClassList("1"));
            var mock2 = new StringBuilderMock(ToCharacterClassList("2"));
            var mock3 = new StringBuilderMock(ToCharacterClassList("3"));

            var simpleExpression = Substitute.For <IExpression>();

            simpleExpression.RepeatRange = new IntegerInterval(1);

            simpleExpression.Expand().Returns(new List <IStringBuilder> {
                mockA
            });

            var expandableExpression = Substitute.For <IExpression>();

            expandableExpression.RepeatRange = new IntegerInterval(1);
            expandableExpression.Expand().Returns(new List <IStringBuilder> {
                mock1, mock2, mock3
            });

            var concat = new ConcatenationExpression(_random);

            concat.SetExpansionLength(4);
            concat.Append(simpleExpression).Append(expandableExpression).Append(simpleExpression).Append(simpleExpression);

            var result = concat.Expand();

            Assert.AreEqual(3, result.Count);
            Assert.AreEqual("a1aa", result[0].GenerateString());
            Assert.AreEqual("a2aa", result[1].GenerateString());
            Assert.AreEqual("a3aa", result[2].GenerateString());
        }
示例#4
0
        public void GetInverse_ReturnsStringBuilderReturningComplementOfSingleCharacterClass_WhenIntersectionExpressionContainsSingleElementWithCharactersRA()
        {
            var concat1 = new ConcatenationExpression(_randomGenerator);

            concat1.Append(ToCharacterClass("r", "a"));
            var expression = new IntersectionExpressionTest(new List <IExpression> {
                concat1
            }, _randomGenerator);

            var result = expression.GetInverse().ToStringBuilder().GenerateString();

            Assert.IsNotNull(result);
            Assert.AreEqual("F", result);
        }
示例#5
0
        public void ToSingleStringBuilder_ReturnedStringBuilderReturnsIntersection_WhenTwoConcatExpressionsContainedInIntersectionExpression()
        {
            var concat1 = new ConcatenationExpression(_randomGenerator);

            concat1.Append(ToCharacterClass("F", "f")).Append(ToCharacterClass("R", "r"));
            var concat2 = new ConcatenationExpression(_randomGenerator);

            concat2.Append(ToCharacterClass("F")).Append(ToCharacterClass("r"));
            var expression = new IntersectionExpressionTest(new List <IExpression> {
                concat1, concat2
            }, _randomGenerator);

            var result = expression.ToSingleStringBuilder().GenerateString();

            Assert.IsNotNull(result);
            Assert.AreEqual("Fr", result);
        }
        public void Clone_ReturnsNewConcatenationInstanceWithSameValues()
        {
            var expression = Substitute.For <IExpression>();
            var concat     = new ConcatenationExpression(_random)
            {
                RepeatRange = new IntegerInterval()
            };

            concat.RepeatRange.TrySetValue(1, 3);
            concat.Append(expression);

            var result = concat.Clone();

            Assert.AreNotEqual(concat, result);
            Assert.AreEqual(concat.RepeatRange.Start, result.RepeatRange.Start);
            Assert.AreEqual(concat.RepeatRange.End, result.RepeatRange.End);
            expression.Received(1).Clone();
        }
        public void Expand_DoesNotChangeRepeatRangeValue_WhenCalled()
        {
            var clone = Substitute.For <IExpression>();

            clone.Expand().Returns(new List <IStringBuilder> {
                new StringBuilderMock(new List <CharacterClassExpression>())
            });
            var expression = Substitute.For <IExpression>();

            expression.Clone().Returns(clone);
            expression.RepeatRange = new IntegerInterval();
            expression.RepeatRange.TrySetValue(1, 3);
            var concat = new ConcatenationExpression(_random);

            concat.Append(expression);

            concat.Expand();

            Assert.AreEqual(1, expression.RepeatRange.Start);
            Assert.AreEqual(3, expression.RepeatRange.End);
        }
        public void Expand_ReturnsListContainingTwoElements_WhenSingleNotExpandableExpressionWithRepeatRangeFrom1To3IsContainedAndMaxExpansionLengthIs2()
        {
            var clone = Substitute.For <IExpression>();

            clone.Expand().Returns(new List <IStringBuilder> {
                new StringBuilderMock(new List <CharacterClassExpression>())
            });
            clone.ExpansionLength.Returns(2);
            var expression = Substitute.For <IExpression>();

            expression.Clone().Returns(clone);
            expression.RepeatRange = new IntegerInterval();
            expression.RepeatRange.TrySetValue(1, 3);
            expression.ExpansionLength.Returns(2);
            var concat = new ConcatenationExpression(_random);

            concat.Append(expression);
            concat.SetExpansionLength(2);

            var result = concat.Expand();

            Assert.AreEqual(2, result.Count);
        }