Example #1
0
        internal void FuzzyPointArray_WithEmptyArray_Throws()
        {
            // Arrange
            var points = new FuzzyPoint[] { };

            // Act
            // Assert
            Assert.Throws <ArgumentException>(() => Validate.FuzzyPointArray(points, nameof(points)));
        }
Example #2
0
        internal void InequalityOperator(double x1, double y1, double x2, double y2, bool areNotEqual)
        {
            // Arrange
            // Act
            var point1 = new FuzzyPoint(x1, y1);
            var point2 = new FuzzyPoint(x2, y2);

            // Assert
            Assert.Equal(point1 != point2, areNotEqual);
        }
Example #3
0
        internal void ToStringTest()
        {
            // Arrange
            var point1 = new FuzzyPoint(1, 1);

            // Act
            var result = point1.ToString();

            // Assert
            Assert.Equal("FuzzyPoint: 1, 1", result);
        }
Example #4
0
        internal void EuclideanNorm(double x, double y, double expectedNorm)
        {
            // Arrange
            var point = new FuzzyPoint(x, y);

            // Act
            var result = point.EuclideanNorm();

            // Assert
            Assert.Equal(expectedNorm, result);
        }
Example #5
0
        public U Get(float point)
        {
            FuzzyPoint p     = new FuzzyPoint(point, percision);
            int        index = points.BinarySearch(p);

            if (index >= 0)
            {
                return(mapping[index]);
            }
            return(default(U));
        }
Example #6
0
        internal void SquaredDistanceTo()
        {
            // Arrange
            var point1 = new FuzzyPoint(1, 0);
            var point2 = new FuzzyPoint(0, 0);

            // Act
            var result = point1.SquaredDistanceTo(point2);

            // Assert
            Assert.Equal(1, result);
        }
Example #7
0
        public bool TryGet(float point, out U output)
        {
            FuzzyPoint p     = new FuzzyPoint(point, percision);
            int        index = points.BinarySearch(p);

            if (index >= 0)
            {
                output = mapping[index];
                return(true);
            }
            output = default(U);
            return(false);
        }
Example #8
0
        public U GetOrInit(float point, Func <U> constructor)
        {
            FuzzyPoint p     = new FuzzyPoint(point, percision);
            int        index = points.BinarySearch(p);

            if (index < 0)
            {
                index = ~index;
                points.Insert(index, p);
                mapping.Insert(index, constructor());
            }
            return(mapping[index]);
        }
Example #9
0
        public (U, U, U) GetOrInitLanes(float point, Func <U> constructor)
        {
            FuzzyPoint p     = new FuzzyPoint(point, percision);
            int        index = points.BinarySearch(p);

            if (index < 0)
            {
                index = ~index;
                points.Insert(index, p);
                mapping.Insert(index, constructor());
            }
            return(GetTuple(index));
        }
Example #10
0
        public (U, U, U) GetLanes(float point)
        {
            FuzzyPoint p     = new FuzzyPoint(point, percision);
            int        index = points.BinarySearch(p);

            if (index >= 0)
            {
                return(GetTuple(index));
            }
            else
            {
                return(default(U), default(U), default(U));
            }
        }
Example #11
0
        internal void GetHashCodeTest()
        {
            // Arrange
            var point1 = new FuzzyPoint(0, 0);
            var point2 = new FuzzyPoint(1, 1);

            // Act
            var result1 = point1.GetHashCode();
            var result2 = point2.GetHashCode();

            // Assert
            Assert.Equal(9, result1);
            Assert.Equal(2145386505, result2);
        }
Example #12
0
        internal void FuzzyPointArray_WithMinYAboveMaxY_Throws()
        {
            // Arrange
            var points = new FuzzyPoint[]
            {
                new FuzzyPoint(2, 0.5),
                new FuzzyPoint(4, 0.5),                  // X out of sequence
                new FuzzyPoint(3, 1)
            };

            // Act
            // Assert
            Assert.Throws <ArgumentException>(() => Validate.FuzzyPointArray(points, nameof(points)));
        }
Example #13
0
        internal void DistanceTo(
            double point1x,
            double point1y,
            double point2x,
            double point2y)
        {
            // Arrange
            var point1 = new FuzzyPoint(point1x, point1y);
            var point2 = new FuzzyPoint(point2x, point2y);

            // Act
            var result = point1.DistanceTo(point2);

            // Assert
            Assert.Equal(0, result);
        }
Example #14
0
        public void Set(float point, U value)
        {
            FuzzyPoint p     = new FuzzyPoint(point, percision);
            int        index = points.BinarySearch(p);

            if (index >= 0)
            {
                mapping[index] = value;
            }
            else
            {
                index = ~index;
                points.Insert(index, p);
                mapping.Insert(index, value);
            }
        }
Example #15
0
        internal void GetMembership_WithVariousInputs_ReturnsExpectedResult(double x, double expected)
        {
            // Arrange
            var points = new FuzzyPoint[]
            {
                new FuzzyPoint(2, 0.5),
                new FuzzyPoint(3, 1)
            };

            var function = new PiecewiseLinearFunction(points);

            // Act
            var result = function.GetMembership(x);

            // Assert
            Assert.Equal(UnitInterval.Create(expected), result);
        }
Example #16
0
        internal void MaxY_ReturnsExpectedResult()
        {
            // Arrange
            // Arrange
            var points = new FuzzyPoint[]
            {
                new FuzzyPoint(2, 0),
                new FuzzyPoint(3, 1)
            };

            var function = new PiecewiseLinearFunction(points);

            // Act
            var result = function.MaxY;

            // Assert
            Assert.Equal(UnitInterval.One(), result);
        }
Example #17
0
        internal void LowerBound_ReturnsExpectedResult()
        {
            // Arrange
            // Arrange
            var points = new FuzzyPoint[]
            {
                new FuzzyPoint(2, 0.5),
                new FuzzyPoint(3, 1)
            };

            var function = new PiecewiseLinearFunction(points);

            // Act
            var result = function.LowerBound;

            // Assert
            Assert.Equal(2, result);
        }
Example #18
0
        internal void Divide(
            double point1x,
            double point1y,
            double factor,
            double point2x,
            double point2y)
        {
            // Arrange
            var point = new FuzzyPoint(point1x, point1y);

            // Act
            var result1 = point.Divide(factor);
            var result2 = point / factor;

            // Assert
            Assert.Equal(new FuzzyPoint(point2x, point2y), result1);
            Assert.Equal(new FuzzyPoint(point2x, point2y), result2);
        }
Example #19
0
        internal void Subtract(
            double point1x,
            double point1y,
            double point2x,
            double point2y,
            double point3x,
            double point3y)
        {
            // Arrange
            var point1 = new FuzzyPoint(point1x, point1y);
            var point2 = new FuzzyPoint(point2x, point2y);

            // Act
            var result1 = point1.Subtract(point2);
            var result2 = point1 - point2;

            // Assert
            Assert.Equal(new FuzzyPoint(point3x, point3y), result1);
            Assert.Equal(new FuzzyPoint(point3x, point3y), result2);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SingletonFunction"/> class.
        /// </summary>
        /// <param name="point">
        /// The point.
        /// </param>
        private SingletonFunction(FuzzyPoint point)
        {
            Validate.NotNull(point, nameof(point));

            this.points = new FuzzyPoint[] { point };
        }
Example #21
0
 public PlanarKey(XYZ norm, XYZ origin)
 {
     m_Norm = new FuzzyPoint(norm);
     m_Origin = new FuzzyPoint(origin);
 }