protected virtual NUnitCtr.Constraint BuildChildConstraint(AbstractComparerXml xml)
        {
            NUnitCtr.Constraint ctr = null;
            if (xml is LessThanXml)
            {
                if (((LessThanXml)xml).OrEqual)
                    ctr = new NUnitCtr.LessThanOrEqualConstraint(xml.Value);
                else
                    ctr = new NUnitCtr.LessThanConstraint(xml.Value);
            }
            else if (xml is MoreThanXml)
            {
                if (((MoreThanXml)xml).OrEqual)
                    ctr = new NUnitCtr.GreaterThanOrEqualConstraint(xml.Value);
                else
                    ctr = new NUnitCtr.GreaterThanConstraint(xml.Value);
            }
            else if (xml is EqualXml)
            {
                ctr = new NUnitCtr.EqualConstraint(xml.Value);
            }

            if (ctr == null)
                throw new ArgumentException();

            return ctr;
        }
Пример #2
0
 public void ErrorWithPercentAndUlpsToleranceModes()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         var shouldFail = new EqualConstraint(100.0f).Within(10.0f).Percent.Ulps;
     });
 }
Пример #3
0
 public void ErrorWithUlpsAndPercentToleranceModes()
 {
     Assert.Throws <InvalidOperationException>(() =>
     {
         EqualConstraint shouldFail = new EqualConstraint(100.0f).Within(10.0f).Ulps.Percent;
     });
 }
Пример #4
0
        public void DoesntRespectCultureWhenCasingMatters()
        {
            var constraint = new EqualConstraint("r\u00E9sum\u00E9");

            var result = constraint.ApplyTo("re\u0301sume\u0301");

            Assert.That(result.IsSuccess, Is.False);
        }
Пример #5
0
        public void RespectsCultureWhenCaseIgnored()
        {
            var constraint = new EqualConstraint("r\u00E9sum\u00E9").IgnoreCase;

            var result = constraint.ApplyTo("re\u0301sume\u0301");

            Assert.That(result.IsSuccess, Is.True);
        }
Пример #6
0
        public void PropertyEqualToValueWithTolerance()
        {
            Constraint c = new EqualConstraint(105m).Within(0.1m);
            Assert.That(c.Description, Is.EqualTo("105m +/- 0.1m"));

            c = new PropertyConstraint("D", new EqualConstraint(105m).Within(0.1m));
            Assert.That(c.Description, Is.EqualTo("property D equal to 105m +/- 0.1m"));
        }
Пример #7
0
        public void PropertyEqualToValueWithTolerance()
        {
            Constraint c = new EqualConstraint(105m).Within(0.1m);

            Assert.That(c.Description, Is.EqualTo("105m +/- 0.1m"));

            c = new PropertyConstraint("D", new EqualConstraint(105m).Within(0.1m));
            Assert.That(c.Description, Is.EqualTo("property D equal to 105m +/- 0.1m"));
        }
Пример #8
0
 /// <summary>
 /// Construct an EqualConstraintResult
 /// </summary>
 public EqualConstraintResult(EqualConstraint constraint, object actual, bool hasSucceeded)
     : base(constraint, actual, hasSucceeded) 
 {
     this.expectedValue = constraint.Arguments[0];
     this.tolerance = constraint.Tolerance;
     this.caseInsensitive = constraint.CaseInsensitive;
     this.clipStrings = constraint.ClipStrings;
     this.failurePoints = constraint.FailurePoints;
 }
Пример #9
0
 /// <summary>
 /// Construct an EqualConstraintResult
 /// </summary>
 public EqualConstraintResult(EqualConstraint constraint, object actual, bool hasSucceeded)
     : base(constraint, actual, hasSucceeded)
 {
     this.expectedValue   = constraint.Arguments[0];
     this.tolerance       = constraint.Tolerance;
     this.caseInsensitive = constraint.CaseInsensitive;
     this.clipStrings     = constraint.ClipStrings;
     this.failurePoints   = constraint.FailurePoints;
 }
Пример #10
0
        public void PropertyEqualToValueWithTolerance()
        {
            Constraint c = new EqualConstraint(105m).Within(0.1m);
            TextMessageWriter w = new TextMessageWriter();
            c.WriteDescriptionTo(w);
            Assert.That(w.ToString(), Is.EqualTo("105m +/- 0.1m"));

            c = new PropertyConstraint("D", new EqualConstraint(105m).Within(0.1m));
            w = new TextMessageWriter();
            c.WriteDescriptionTo(w);
            Assert.That(w.ToString(), Is.EqualTo("property D equal to 105m +/- 0.1m"));
        }
Пример #11
0
        public void PropertyEqualToValueWithTolerance()
        {
            Constraint        c = new EqualConstraint(105m).Within(0.1m);
            TextMessageWriter w = new TextMessageWriter();

            c.WriteDescriptionTo(w);
            Assert.That(w.ToString(), Is.EqualTo("105m +/- 0.1m"));

            c = new PropertyConstraint("D", new EqualConstraint(105m).Within(0.1m));
            w = new TextMessageWriter();
            c.WriteDescriptionTo(w);
            Assert.That(w.ToString(), Is.EqualTo("property D equal to 105m +/- 0.1m"));
        }
Пример #12
0
        protected override NUnitCtr.Constraint BuildInternalConstraint()
        {
            NUnitCtr.Constraint ctr = null;

            if (exactly.HasValue)
            {
                if (ctr != null)
                {
                    ctr = ctr.And.EqualTo(exactly.Value);
                }
                else
                {
                    ctr = new NUnitCtr.EqualConstraint(exactly.Value);
                }
            }

            if (moreThan.HasValue)
            {
                if (ctr != null)
                {
                    ctr = ctr.And.GreaterThan(moreThan.Value);
                }
                else
                {
                    ctr = new NUnitCtr.GreaterThanConstraint(moreThan.Value);
                }
            }

            if (lessThan.HasValue)
            {
                if (ctr != null)
                {
                    ctr = ctr.And.LessThan(lessThan.Value);
                }
                else
                {
                    ctr = new NUnitCtr.LessThanConstraint(lessThan.Value);
                }
            }

            return(ctr);
        }
Пример #13
0
        protected virtual NUnitCtr.Constraint BuildChildConstraint(AbstractComparerXml xml)
        {
            NUnitCtr.Constraint ctr = null;
            if (xml is LessThanXml)
            {
                if (((LessThanXml)xml).OrEqual)
                {
                    ctr = new NUnitCtr.LessThanOrEqualConstraint(xml.Value);
                }
                else
                {
                    ctr = new NUnitCtr.LessThanConstraint(xml.Value);
                }
            }
            else if (xml is MoreThanXml)
            {
                if (((MoreThanXml)xml).OrEqual)
                {
                    ctr = new NUnitCtr.GreaterThanOrEqualConstraint(xml.Value);
                }
                else
                {
                    ctr = new NUnitCtr.GreaterThanConstraint(xml.Value);
                }
            }
            else if (xml is EqualXml)
            {
                ctr = new NUnitCtr.EqualConstraint(xml.Value);
            }

            if (ctr == null)
            {
                throw new ArgumentException();
            }

            return(ctr);
        }
 public void SetUp()
 {
     theConstraint        = new EqualConstraint(4);
     expectedDescription  = "4";
     stringRepresentation = "<equal 4>";
 }
Пример #15
0
        protected virtual NUnitCtr.Constraint BuildChildConstraint(AbstractComparerXml xml)
        {
            var value = xml.Value.Replace(" ", "");

            object numericValue;

            try
            {
                if (value.EndsWith("%"))
                {
                    numericValue = Decimal.Parse(xml.Value.Substring(0, xml.Value.Length - 1)) / new Decimal(100);
                }
                else
                {
                    numericValue = Int32.Parse(xml.Value);
                }
            }
            catch (Exception ex)
            {
                var exception = new ArgumentException
                                (
                    String.Format("The assertion row-count is expecting an integer or percentage value for comparison. The provided value '{0}' is not a integer or percentage value.", value)
                    , ex
                                );
                throw exception;
            }


            NUnitCtr.Constraint ctr = null;
            if (xml is LessThanXml)
            {
                if (((LessThanXml)xml).OrEqual)
                {
                    ctr = new NUnitCtr.LessThanOrEqualConstraint(numericValue);
                }
                else
                {
                    ctr = new NUnitCtr.LessThanConstraint(numericValue);
                }
            }
            else if (xml is MoreThanXml)
            {
                if (((MoreThanXml)xml).OrEqual)
                {
                    ctr = new NUnitCtr.GreaterThanOrEqualConstraint(numericValue);
                }
                else
                {
                    ctr = new NUnitCtr.GreaterThanConstraint(numericValue);
                }
            }
            else if (xml is EqualXml)
            {
                ctr = new NUnitCtr.EqualConstraint(numericValue);
            }

            if (ctr == null)
            {
                throw new ArgumentException();
            }

            return(ctr);
        }
Пример #16
0
 public void ErrorWithPercentAndUlpsToleranceModes()
 {
     EqualConstraint shouldFail = new EqualConstraint(100.0f).Within(10.0f).Percent.Ulps;
 }
Пример #17
0
 public void ErrorWithUlpsAndPercentToleranceModes()
 {
     EqualConstraint shouldFail = new EqualConstraint(100.0f).Within(10.0f).Ulps.Percent;
 }
Пример #18
0
        protected override NUnitCtr.Constraint BuildInternalConstraint()
        {
            NUnitCtr.Constraint ctr = null;

            if (exactly.HasValue)
            {
                if (ctr != null)
                    ctr = ctr.And.EqualTo(exactly.Value);
                else
                    ctr = new NUnitCtr.EqualConstraint(exactly.Value);
            }

            if (moreThan.HasValue)
            {
                if (ctr != null)
                    ctr = ctr.And.GreaterThan(moreThan.Value);
                else
                    ctr = new NUnitCtr.GreaterThanConstraint(moreThan.Value);
            }

            if (lessThan.HasValue)
            {
                if (ctr != null)
                    ctr = ctr.And.LessThan(lessThan.Value);
                else
                    ctr = new NUnitCtr.LessThanConstraint(lessThan.Value);
            }

            return ctr;
        }
Пример #19
0
 /// <summary>
 /// Construct a SomeItemsConstraint on top of an existing constraint
 /// </summary>
 /// <param name="itemConstraint"></param>
 public SomeItemsConstraint(IConstraint itemConstraint)
     : base(itemConstraint)
 {
     _equalConstraint  = itemConstraint as EqualConstraint;
     DescriptionPrefix = "some item";
 }