Exemplo n.º 1
0
        public void BoundsOk_CreatesOk()
        {
            var min = -1.4;
            var max = 2.5;
            var vbl = new VariableContinuous(min, max);

            var range = max - min;

            Assert.True(vbl.IsInBounds(min + range / 2));
            Assert.False(vbl.IsInBounds(max + range / 2));
            Assert.False(vbl.IsInBounds(min - range / 2));
        }
Exemplo n.º 2
0
        public void BoundsCheck_WithInvalidType_ThrowsError()
        {
            var vbl = new VariableContinuous(-1.2, 4.2);

            Assert.Throws <System.FormatException>(
                () => vbl.IsInBounds("bf"));
        }
Exemplo n.º 3
0
        public void BoundsCheckNonsense_ThrowsError()
        {
            var min = -1.4;
            var max = 2.5;
            var vbl = new VariableContinuous(min, max);

            Assert.Throws <System.FormatException>(
                () => vbl.IsInBounds("nonsense"));
        }
Exemplo n.º 4
0
        public void GetNearestLegalLocation_InputLocationIsLow_ReturnsLowerBound()
        {
            var min = -1.4;
            var max = 2.5;
            var vbl = new VariableContinuous(min, max);

            var testValue = -5.8;

            Assert.Equal(min, vbl.GetNearestLegalLocation(testValue));
            Assert.True(vbl.IsInBounds(vbl.GetNearestLegalLocation(testValue)));
        }
Exemplo n.º 5
0
        public void GetNearestLegalLocation_InputLocationIsHigh_ReturnsUpperBound()
        {
            var min = -1.4;
            var max = 2.5;
            var vbl = new VariableContinuous(min, max);

            var testValue = 3.1;

            Assert.True(max - (double)vbl.GetNearestLegalLocation(testValue) < 1e-9);
            Assert.True(vbl.IsInBounds(vbl.GetNearestLegalLocation(testValue)));
        }
Exemplo n.º 6
0
        public void CreatedWithMixedArray_ConstructsOk()
        {
            var vbl1 = new VariableContinuous(-2.5, 2.6);
            var vbl2 = new VariableDiscrete(-6, 1);
            var vbl3 = new VariableContinuous(2, 7.4);
            var vbl4 = new VariableDiscrete(4, 12);

            var space = new DecisionSpace(new List <IVariable> {
                vbl1, vbl2, vbl3, vbl4
            });

            Assert.Equal(4, space.Count);
            Assert.Equal(space.ElementAt(0).IsInBounds(0), vbl1.IsInBounds(0));
            Assert.Equal(space.ElementAt(1).IsInBounds(0), vbl2.IsInBounds(0));
            Assert.Equal(space.ElementAt(2).IsInBounds(0), vbl3.IsInBounds(0));
            Assert.Equal(space.ElementAt(3).IsInBounds(0), vbl4.IsInBounds(0));
        }