예제 #1
0
        public void SamplesGeneratorsFunctions_GetRestrictedPulseTest()
        {
            var len    = 10;
            var delta  = 1.0 / (5 * len);
            var values = new double[len];

            for (var i = 0; i < len; ++i)
            {
                values[i] = i * 1.0 / len;
            }

            var pusleFunc = SamplesGeneratorFunctions.GetRestrictedPulse(
                values,
                delta);

            var increase = delta / 10;
            var x        = 0.0;

            while (x < 1.0)
            {
                var actual   = pusleFunc.Invoke(x);
                var expected = 0.0;
                for (var i = 0; i < len; ++i)
                {
                    var val = values[i];
                    if (Math.Abs(x - val) <= delta)
                    {
                        expected = 1.0;
                        i        = len;
                    }
                }

                Assert.AreEqual(expected, actual);
                x += increase;
            }
        }
예제 #2
0
        public void SamplesProcessorFunctions_GetDelayTest()
        {
            var f          = SamplesGeneratorFunctions.GetSineFunc();
            var startValue = 2.0;
            var delay      = SamplesProcessorFunctions.GetDelay(
                f,
                startValue);

            // Testa o retardo simples.
            var t        = 0.0;
            var expected = startValue;

            while (t < 100)
            {
                var actual = delay.Invoke(t);
                Assert.AreEqual(expected, actual);

                expected = f.Invoke(t);
                t       += 1.0;
            }

            // Testa um retardo composto
            var startValue1 = 2.0;
            var startValue2 = 1.0;
            var startValue3 = 3.0;

            delay = SamplesProcessorFunctions.GetDelay(
                f,
                startValue);
            var delay1 = SamplesProcessorFunctions.GetDelay(
                delay,
                1.0);
            var delay2 = SamplesProcessorFunctions.GetDelay(
                delay1,
                3.0);

            t = 0.0;
            while (t < 100)
            {
                var actual = delay2.Invoke(t);
                Assert.AreEqual(startValue3, actual);

                startValue3 = startValue2;
                startValue2 = startValue1;
                startValue1 = f.Invoke(t);
                t          += 1.0;
            }

            // Testa um retardo complexo
            Func <double, double> func = x => x;

            delay1 = SamplesProcessorFunctions.GetDelay(
                func,
                1.0);
            delay2 = SamplesProcessorFunctions.GetDelay(
                func,
                1.0);
            Func <double, double> delay3 = SamplesProcessorFunctions.GetDelay(
                x => delay2.Invoke(x),
                2.0);
            Func <double, double> xMain = x => x + delay1.Invoke(x) + 0.5 * delay3.Invoke(x);

            var expectedItems = new double[] {
                2, 1.5, 3, 5.5, 8, 10.5, 13, 15.5,
                18, 20.5, 23, 25.5, 28, 30.5, 33, 35.5
            };

            t = 0.0;
            for (var i = 0; i < expectedItems.LongLength; ++i)
            {
                var innerExpected = expectedItems[i];
                var innerActual   = xMain.Invoke(t);
                Assert.AreEqual(innerExpected, innerActual);
                t += 1.0;
            }
        }