public static void Test_InclusiveValue_CountConstraint(long value, bool valid)
        {
            // [0, 10]
            var range = new CountConstraint(3, 10);

            Assert.True(range.IsValid(value) == valid);
            Assert.NotEqual(0, range.GetHashCode());
        }
        public static void Test_Infinity_InclusiveValue_CountConstraint(long value, bool valid)
        {
            // (-∞, 11]
            var range = new CountConstraint(null, 11);

            Assert.True(range.IsValid(value) == valid);
            Assert.NotEqual(0, range.GetHashCode());
        }
        public static void Test_Empty_CountConstraint(long value, bool valid)
        {
            // (0, ∞)
            var range = new CountConstraint(null, null);

            Assert.True(range.IsValid(value) == valid);
            Assert.NotEqual(0, range.GetHashCode());
        }
        public static void Test_Exact_CountConstraint(long value, bool valid)
        {
            // [10, 10]
            var range = new CountConstraint(10, 10);
            var exact = CountConstraint.Exact(10);

            Assert.Equal(range, exact);
            Assert.True(exact.IsValid(value) == valid);
            Assert.NotEqual(0, range.GetHashCode());
        }
Exemple #5
0
        public void WriteTo_FailingAssertionForBetween_TextContainsFewKeyInfo()
        {
            var cmd = new DiscoveryRequestFactory().Build(
                "connectionString",
                "member-caption",
                "perspective-name",
                "dimension-caption",
                "hierarchy-caption",
                null);

            var memberStub = new Mock <NBi.Core.Analysis.Member.Member>();
            var member1    = memberStub.Object;
            var member2    = memberStub.Object;
            var members    = new MemberResult();

            members.Add(member1);
            members.Add(member2);

            var meStub = new Mock <MembersAdomdEngine>();

            meStub.Setup(engine => engine.GetMembers(cmd))
            .Returns(members);
            var me = meStub.Object;

            var countConstraint = new CountConstraint()
            {
                MembersEngine = me
            };

            countConstraint = countConstraint.MoreThan(8);
            countConstraint = countConstraint.LessThan(12);

            //Method under test
            string assertionText = null;

            try
            {
                Assert.That(cmd, countConstraint);
            }
            catch (AssertionException ex)
            {
                assertionText = ex.Message;
            }

            //Test conclusion
            Assert.That(assertionText, Is.StringContaining("perspective-name").And
                        .StringContaining("dimension-caption").And
                        .StringContaining("hierarchy-caption").And
                        .StringContaining("member-caption").And
                        .StringContaining("children").And
                        .StringContaining("between").And
                        .StringContaining("8").And
                        .StringContaining("12"));
        }
Exemple #6
0
        public void Matches_LessThanCorrectlySpecified_Validated()
        {
            var members = new MemberResult();

            members.Add("First member");
            members.Add("Second member");

            var countConstraint = new CountConstraint();

            countConstraint.LessThan(3);

            //Method under test
            var res = countConstraint.Matches(members);

            //Test conclusion
            Assert.That(res, Is.True);
        }
Exemple #7
0
        public void Matches_MoreThanWronglySpecified_Validated()
        {
            var members = new MemberResult();

            members.Add("First member");
            members.Add("Second member");

            var countConstraint = new CountConstraint();

            countConstraint.MoreThan(2);

            //Method under test
            var res = countConstraint.Matches(members);

            //Test conclusion
            Assert.That(res, Is.False);
        }
Exemple #8
0
        public void TestSeparationConstraint()
        {
            var model = new AdjacentModel(DirectionSet.Cartesian2d);
            var tile1 = new Tile(1);
            var tile2 = new Tile(2);
            var tiles = new[] { tile1, tile2 };

            model.AddAdjacency(tiles, tiles, Direction.XPlus);
            model.AddAdjacency(tiles, tiles, Direction.YPlus);
            model.SetUniformFrequency();

            var separationConstraint = new SeparationConstraint
            {
                Tiles = new[] { tile1 }.ToHashSet(),
                MinDistance = 3,
            };

            var countConstraint = new CountConstraint
            {
                Tiles = new[] { tile1 }.ToHashSet(),
                Count      = 2,
                Comparison = CountComparison.Exactly,
            };

            var topology = new GridTopology(4, 1, false);

            var options = new TilePropagatorOptions
            {
                Constraints   = new ITileConstraint[] { separationConstraint, countConstraint },
                BacktrackType = BacktrackType.Backtrack,
            };
            var propagator = new TilePropagator(model, topology, options);

            propagator.Run();

            Assert.AreEqual(Resolution.Decided, propagator.Status);

            var r = propagator.ToArray();

            // Only possible solution given the constraints
            Assert.AreEqual(tile1, r.Get(0));
            Assert.AreEqual(tile2, r.Get(1));
            Assert.AreEqual(tile2, r.Get(2));
            Assert.AreEqual(tile1, r.Get(3));
        }
Exemple #9
0
 /// <summary>
 /// Creates a new <see cref="OasSchema"/> value.
 /// </summary>
 /// <param name="type">The general type of the schema.</param>
 /// <param name="format">The specific type of the schema/</param>
 /// <param name="title">The title of the schema.</param>
 /// <param name="description">The description of the schema.</param>
 /// <param name="numberRange">The range of valid numbers.</param>
 /// <param name="itemsRange">The range of valid item counts.</param>
 /// <param name="lengthRange">The range of valid lengths.</param>
 /// <param name="propertiesRange">The range of valid property counts.</param>
 /// <param name="options">The schema options.</param>
 /// <param name="pattern">The regex validation for string values.</param>
 /// <param name="enum">The valid enum values.</param>
 /// <param name="allOf">The list of schemas that this schema must conform to.</param>
 /// <param name="oneOf">The list of schemas that, from which exactly one, this schema must conform to.</param>
 /// <param name="anyOf">The list of schemas that, from which one or more, this schema must conform to.</param>
 /// <param name="not">The list of schemas that this schema must not conform to.</param>
 /// <param name="items">The list of schemas that represent the array items that this schema must contain.</param>
 /// <param name="properties">The list of valid properties.</param>
 /// <param name="additionalProperties">The list of valid properties for children.</param>
 /// <param name="externalDocumentation">The external documentation.</param>
 public OasSchema(
     OasSchemaType type = default,
     string format = null,
     string title = null,
     string description = null,
     NumberConstraint numberRange = default,
     CountConstraint itemsRange = default,
     CountConstraint lengthRange = default,
     CountConstraint propertiesRange = default,
     OasSchemaOptions options = default,
     string pattern = default,
     IReadOnlyList<OasScalarValue> @enum = default,
     IReadOnlyList<OasReferable<OasSchema>> allOf = default,
     IReadOnlyList<OasReferable<OasSchema>> oneOf = default,
     IReadOnlyList<OasReferable<OasSchema>> anyOf = default,
     IReadOnlyList<OasReferable<OasSchema>> not = default,
     OasReferable<OasSchema> items = default,
     IReadOnlyDictionary<string, OasReferable<OasSchema>> properties = default,
     IReadOnlyDictionary<string, OasReferable<OasSchema>> additionalProperties = default,
     OasExternalDocumentation externalDocumentation = default)
 {
     JsonType = type;
     Title = title;
     Format = format;
     Description = description;
     NumberRange = numberRange;
     ItemsRange = itemsRange;
     LengthRange = lengthRange;
     PropertiesRange = propertiesRange;
     Options = options;
     Pattern = pattern;
     Enum = @enum ?? Array.Empty<OasScalarValue>();
     AllOf = allOf ?? Array.Empty<OasReferable<OasSchema>>();
     OneOf = oneOf ?? Array.Empty<OasReferable<OasSchema>>();
     AnyOf = anyOf ?? Array.Empty<OasReferable<OasSchema>>();
     Not = not ?? Array.Empty<OasReferable<OasSchema>>();
     Items = items;
     Properties = properties ?? ImmutableDictionary<string, OasReferable<OasSchema>>.Empty;
     AdditionalProperties = additionalProperties ?? ImmutableDictionary<string, OasReferable<OasSchema>>.Empty;
     ExternalDocumentation = externalDocumentation;
 }