Exemplo n.º 1
0
        public void AddBound_SingleValue <T>(T value)
        {
            // arrange
            ConstraintSet <T> set = this.CreateAndAssertSet <T>();

            // act
            bool added   = set.AddBound(value);
            bool reAdded = set.AddBound(value);

            // assert
            this.AssertBounds(set, new[] { value }, Array.Empty <T>());
            added.Should().BeTrue();
            reAdded.Should().BeFalse();
        }
Exemplo n.º 2
0
        public void AddBound_MultipleValues(params int[] values)
        {
            // arrange
            ConstraintSet <int> set = this.CreateAndAssertSet <int>();

            // act
            bool added   = set.AddBound(values);
            bool reAdded = set.AddBound(values);

            // assert
            this.AssertBounds(set, values, Array.Empty <int>());
            added.Should().BeTrue();
            reAdded.Should().BeFalse();
        }
Exemplo n.º 3
0
        public void AddBound_MultipleValues_WithCaseSensitiveComparer(string[] input, string[] expected)
        {
            // arrange
            ConstraintSet <string> set = this.CreateAndAssertSet <string>();

            // act
            bool added   = set.AddBound(input);
            bool reAdded = set.AddBound(input);

            // assert
            this.AssertBounds(set, expected, Array.Empty <string>());
            added.Should().BeTrue();
            reAdded.Should().BeFalse();
        }
        public void AddBound_MultipleValues_WithCaseInsensitiveComparer(string[] input, string[] expected)
        {
            // arrange
            ConstraintSet <string> set = this.CreateAndAssertSet(StringComparer.OrdinalIgnoreCase);

            // act
            bool added   = set.AddBound(input);
            bool reAdded = set.AddBound(input);

            // assert
            this.AssertBounds(set, expected, new string[0]);
            added.Should().BeTrue();
            reAdded.Should().BeFalse();
        }
Exemplo n.º 5
0
        public void AddBound_SingleValue_WithCaseSensitiveComparer()
        {
            // arrange
            const string           value = "boop";
            ConstraintSet <string> set   = this.CreateAndAssertSet <string>();

            // act
            bool added   = set.AddBound(value);
            bool reAdded = set.AddBound(value.ToUpper());

            // assert
            this.AssertBounds(set, new[] { value, value.ToUpper() }, Array.Empty <string>());
            added.Should().BeTrue();
            reAdded.Should().BeTrue();
        }
        public void AddBound_SingleValue_WithCaseInsensitiveComparer()
        {
            // arrange
            const string           value = "boop";
            ConstraintSet <string> set   = this.CreateAndAssertSet(StringComparer.OrdinalIgnoreCase);

            // act
            bool added   = set.AddBound(value);
            bool reAdded = set.AddBound(value.ToUpper());

            // assert
            this.AssertBounds(set, new[] { value }, new string[0]);
            added.Should().BeTrue();
            reAdded.Should().BeFalse();
        }
Exemplo n.º 7
0
        public void Allows_WithCaseSensitiveComparer(string[] restrict, string[] exclude, string?[] test, bool expectedResult)
        {
            // arrange
            ConstraintSet <string?> set = this.CreateAndAssertSet <string?>();

            set.AddBound(restrict);
            set.Exclude(exclude);
            this.AssertBounds(set, restrict, exclude);

            // act/assert
            foreach (string?value in test)
            {
                set.Allows(value).Should().Be(expectedResult, $"expected '{value}' to {(expectedResult ? "be allowed" : "be excluded")}");
            }
        }
Exemplo n.º 8
0
        public void Allows_WithFloats(float[] restrict, float[] exclude, float[] test, bool expectedResult)
        {
            // arrange
            ConstraintSet <float> set = this.CreateAndAssertSet <float>();

            set.AddBound(restrict);
            set.Exclude(exclude);
            this.AssertBounds(set, restrict, exclude);

            // act/assert
            foreach (float value in test)
            {
                set.Allows(value).Should().Be(expectedResult, $"expected '{value}' to {(expectedResult ? "be allowed" : "be excluded")}");
            }
        }
Exemplo n.º 9
0
        public void Intersects_OneInfinite_NonIntersection()
        {
            // arrange
            ConstraintSet <string> left  = this.CreateAndAssertSet(StringComparer.OrdinalIgnoreCase);
            ConstraintSet <string> right = this.CreateAndAssertSet(StringComparer.OrdinalIgnoreCase);

            left.Exclude(new[] { "A", "B", "C" });
            right.AddBound(new[] { "A", "B", "C" });

            // act
            bool leftIntersects  = left.Intersects(right);
            bool rightIntersects = right.Intersects(left);

            // assert
            leftIntersects.Should().BeFalse();
            rightIntersects.Should().BeFalse();
        }
Exemplo n.º 10
0
        public void Allows_WithCaseInsensitiveComparer(string[] restrict, string[] exclude, string[] test, bool expectedResult)
        {
            // arrange
            ConstraintSet <string> set = this.CreateAndAssertSet(StringComparer.OrdinalIgnoreCase);

            set.AddBound(restrict);
            set.Exclude(exclude);
            this.AssertBounds(
                set,
                new HashSet <string>(restrict, StringComparer.OrdinalIgnoreCase).ToArray(),
                new HashSet <string>(exclude, StringComparer.OrdinalIgnoreCase).ToArray()
                );

            // act/assert
            foreach (string value in test)
            {
                set.Allows(value).Should().Be(expectedResult, $"expected '{value}' to {(expectedResult ? "be allowed" : "be excluded")}");
            }
        }
Exemplo n.º 11
0
        public void Intersects_Bounded_Intersection()
        {
            // arrange
            ConstraintSet <string> left  = this.CreateAndAssertSet(StringComparer.InvariantCultureIgnoreCase);
            ConstraintSet <string> right = this.CreateAndAssertSet(StringComparer.InvariantCultureIgnoreCase);

            left.AddBound(new[] { "A", "B", "C", "D" });
            right.AddBound(new[] { "C", "D" });
            left.Exclude("C");
            right.Exclude("C");

            // act
            bool leftIntersects  = left.Intersects(right);
            bool rightIntersects = right.Intersects(left);

            // assert
            leftIntersects.Should().BeTrue();
            rightIntersects.Should().BeTrue();
        }