NUnit.Framework.Constraints.EqualConstraint.Within(object)

Here are the examples of the csharp api NUnit.Framework.Constraints.EqualConstraint.Within(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

141 Examples 7

19 Source : TestFeatureExtractors.cs
with MIT License
from ar1st0crat

[Test]
        public void TestOnlineFeatureExtractor()
        {
            var mfccOptions = new MfccOptions
            {
                SamplingRate = 8000,
                FeatureCount = 5,
                FrameSize = 256,
                HopSize = 50,
                FilterBankSize = 8
            };

            var signal = new WhiteNoiseBuilder().OfLength(1000).Build();

            var mfccExtractor = new MfccExtractor(mfccOptions);
            var mfccVectors = mfccExtractor.ComputeFrom(signal);

            var onlineMfccExtractor = new OnlineFeatureExtractor(new MfccExtractor(mfccOptions));
            var onlineMfccVectors = new List<float[]>();

            var i = 0;
            while (i < signal.Length)
            {
                // emulating online blocks with different sizes:
                var size = (i + 1) * 15;
                var block = signal.Samples.Skip(i).Take(size).ToArray();

                var newVectors = onlineMfccExtractor.ComputeFrom(block);

                onlineMfccVectors.AddRange(newVectors);
                
                i += size;
            }

            var diff = mfccVectors.Zip(onlineMfccVectors, (e, o) => e.Zip(o, (f1, f2) => f1 - f2).Sum());

            replacedert.That(diff, Is.All.EqualTo(0).Within(1e-7f));
        }

19 Source : TestFeaturePostProcessing.cs
with MIT License
from ar1st0crat

[Test]
        public void TestMeanNormalization()
        {
            FeaturePostProcessing.NormalizeMean(_feats);

            replacedert.Multiple(() =>
            {
                replacedert.That(_feats[0], Is.EqualTo(new float[] {  0.8f, 0, -1,  1.6f,  2 }).Within(1e-5));
                replacedert.That(_feats[1], Is.EqualTo(new float[] { -0.2f, 0,  0, -2.4f,  1 }).Within(1e-5));
                replacedert.That(_feats[2], Is.EqualTo(new float[] { -0.2f, 0,  2,  1.6f,  0 }).Within(1e-5));
                replacedert.That(_feats[3], Is.EqualTo(new float[] { -0.2f, 0,  0, -2.4f, -1 }).Within(1e-5));
                replacedert.That(_feats[4], Is.EqualTo(new float[] { -0.2f, 0, -1,  1.6f, -2 }).Within(1e-5));
            });
        }

19 Source : TestFeaturePostProcessing.cs
with MIT License
from ar1st0crat

[Test]
        public void TestDeltas()
        {
            FeaturePostProcessing.AddDeltas(_feats);

            replacedert.That(_feats[0], Is.EqualTo(
                            new float[] {    1,   2,     3,    4,     5,        // main features
                                          -.3f,   0,   .7f, -.4f,  -.5f,        // delta
                                          .02f,   0, -.16f, .04f, -.13f  })     // delta-delta
                                 .Within(1e-5));

            //FeaturePostProcessing.AddDeltas(_feats, includeDeltaDelta: false);

            //replacedert.That(_feats[1], Is.EqualTo(
            //                               new float[] {    0,   2,   4,    0,    4,
            //                                             -.3f,   0, .5f, -.8f, -.8f  }).Within(1e-5));
            //replacedert.That(_feats[2], Is.EqualTo(
            //                               new float[] {    0,   2,   6,    4,    3,
            //                                             -.2f,   0,   0,    0,   -1  }).Within(1e-5));
        }

19 Source : TestIirFilter.cs
with MIT License
from ar1st0crat

[Test]
        public void TestFilterCombinations()
        {
            var pre = new PreEmphasisFilter();
            var de = new DeEmphasisFilter();

            var filter = pre * de;

            var samples = new[] { 1.0f, 0.1f, -0.4f, 0.2f };
            var signal = new DiscreteSignal(1, samples);
            var filtered = filter.ApplyTo(signal);

            replacedert.That(filtered.Samples, Is.EqualTo(signal.Samples).Within(1e-7));
        }

19 Source : TestIirFilter.cs
with MIT License
from ar1st0crat

private static void replacedertFilterOutput(DiscreteSignal output)
        {
            replacedert.Multiple(() =>
            {
                replacedert.That(output[0], Is.EqualTo(1.0).Within(1e-7));
                replacedert.That(output[1], Is.EqualTo(1.0).Within(1e-7));
                replacedert.That(output[2], Is.EqualTo(0.4).Within(1e-7));
                replacedert.That(output[3], Is.EqualTo(0.04).Within(1e-7));
            });
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestParallelFirIir()
        {
            var f1 = new FirFilter(new[] { 1, -0.1 });
            var f2 = new IirFilter(new[] { 1, 0.4 }, new[] { 1, -0.6 });

            var f = f1 + f2;

            replacedert.Multiple(() =>
            {
                replacedert.That(f.Tf.Numerator, Is.EqualTo(new[] { 2, -0.3, 0.06 }).Within(1e-7));
                replacedert.That(f.Tf.Denominator, Is.EqualTo(new[] { 1, -0.6 }).Within(1e-7));
                replacedert.That(f, Is.TypeOf<IirFilter>());
            });
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestParallelFirFir()
        {
            var f1 = new FirFilter(new[] { 1, -0.1 });
            var f2 = new FirFilter(new[] { 1, -0.6 });

            var f = f1 + f2;

            replacedert.Multiple(() =>
            {
                replacedert.That(f.Tf.Numerator, Is.EqualTo(new[] { 2, -0.7 }).Within(1e-7));
                replacedert.That(f, Is.TypeOf<FirFilter>());
            });
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestSequentialIirFir()
        {
            var f1 = new IirFilter(new[] { 1, -0.1 }, new[] { 1, 0.2 });
            var f2 = new FirFilter(new[] { 1, 0.4 });

            var f = f1 * f2;

            replacedert.Multiple(() =>
            {
                replacedert.That(f.Tf.Numerator, Is.EqualTo(new[] { 1, 0.3, -0.04 }).Within(1e-7));
                replacedert.That(f.Tf.Denominator, Is.EqualTo(new[] { 1, 0.2 }).Within(1e-7));
                replacedert.That(f, Is.TypeOf<IirFilter>());
            });
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestSequentialFirIir()
        {
            var f1 = new FirFilter(new[] { 1, 0.4 });
            var f2 = new IirFilter(new[] { 1, -0.1 }, new[] { 1, 0.2 });

            var f = f1 * f2;

            replacedert.Multiple(() =>
            {
                replacedert.That(f.Tf.Numerator, Is.EqualTo(new[] { 1, 0.3, -0.04 }).Within(1e-7));
                replacedert.That(f.Tf.Denominator, Is.EqualTo(new[] { 1, 0.2 }).Within(1e-7));
                replacedert.That(f, Is.TypeOf<IirFilter>());
            });
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestGroupDelay()
        {
            var f = new MovingAverageFilter(5);
            
            replacedert.That(f.Tf.GroupDelay(), Is.All.EqualTo(2.0).Within(1e-10));
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestTfToStateSpace()
        {
            var tf = new TransferFunction(new[] { 2, 0.7, -0.2 }, new[] { 1, 0.5, 0.9, 0.6 });
            var ss = tf.StateSpace;

            replacedert.Multiple(() =>
            {
                replacedert.That(ss.A[0], Is.EqualTo(new[] { -0.5, -0.9, -0.6 }).Within(1e-10));
                replacedert.That(ss.A[1], Is.EqualTo(new[] { 1.0, 0.0, 0.0 }).Within(1e-10));
                replacedert.That(ss.A[2], Is.EqualTo(new[] { 0.0, 1.0, 0.0 }).Within(1e-10));
                replacedert.That(ss.B, Is.EqualTo(new[] { 1.0, 0.0, 0.0 }).Within(1e-10));
                replacedert.That(ss.C, Is.EqualTo(new[] { 2.0, 0.7, -0.2 }).Within(1e-10));
                replacedert.That(ss.D, Is.EqualTo(new[] { 0.0 }).Within(1e-10));
            });
        }

19 Source : TestSignalBuilders.cs
with MIT License
from ar1st0crat

[Test]
        public void TestBuilderRepeat()
        {
            var sinusoid = new SineBuilder()
                                    .SetParameter("freq", 0.05f)
                                    .OfLength(20)
                                    .RepeatedTimes(3)
                                    .Build();

            replacedert.Multiple(() =>
            {
                replacedert.That(sinusoid[0], Is.EqualTo(0.0).Within(1e-7));
                replacedert.That(sinusoid[5], Is.EqualTo(1.0).Within(1e-7));
                replacedert.That(sinusoid[25], Is.EqualTo(1.0).Within(1e-7));
                replacedert.That(sinusoid.Length, Is.EqualTo(60));
            });
        }

19 Source : TestFeaturePostProcessing.cs
with MIT License
from ar1st0crat

[Test]
        public void TestVarianceNormalization()
        {
            FeaturePostProcessing.NormalizeVariance(_feats, bias: 0);

            replacedert.Multiple(() =>
            {
                replacedert.That(_feats[0], Is.EqualTo(new float[] { 2.5f, 2, 2.74f,  2.04f,  3.536f }).Within(1e-2));
                replacedert.That(_feats[1], Is.EqualTo(new float[] {    0, 2, 3.65f,      0,  2.83f  }).Within(1e-2));
                replacedert.That(_feats[2], Is.EqualTo(new float[] {    0, 2, 5.48f,  2.04f,  2.12f  }).Within(1e-2));
                replacedert.That(_feats[3], Is.EqualTo(new float[] {    0, 2, 3.65f,      0,  1.41f  }).Within(1e-2));
                replacedert.That(_feats[4], Is.EqualTo(new float[] {    0, 2, 2.74f,  2.04f,  0.71f  }).Within(1e-2));
            });
        }

19 Source : TestMedianFilter.cs
with MIT License
from ar1st0crat

[Test]
        public void TestMedianFilteringDefault()
        {
            var filter1 = new MedianFilter();    // 9-point median filter (faster implementation for sizes > 10)
            var filter2 = new MedianFilter2();   // 9-point median filter

            var input =    new[] { 1, 6, 5, 2, 8, 1, 9, 5, 4, 2, 3, 4, 6, 7, 4f };
            var expected = new[] { 1, 1, 2, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 3, 3f };

            var filtered1 = filter1.ApplyTo(new DiscreteSignal(1, input));
            var filtered2 = filter2.ApplyTo(new DiscreteSignal(1, input));

            replacedert.Multiple(() =>
            {
                replacedert.That(filtered1.Samples, Is.EqualTo(expected).Within(1e-10));
                replacedert.That(filtered2.Samples, Is.EqualTo(expected).Within(1e-10));
            });
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestParallelIirIir()
        {
            var f1 = new IirFilter(new[] { 1, -0.1 }, new[] { 1, 0.2 });
            var f2 = new IirFilter(new[] { 1, 0.4 }, new[] { 1, -0.6 });

            var f = f1 + f2;

            replacedert.Multiple(() =>
            {
                replacedert.That(f.Tf.Numerator, Is.EqualTo(new[] { 2, -0.1, 0.14 }).Within(1e-7));
                replacedert.That(f.Tf.Denominator, Is.EqualTo(new[] { 1, -0.4, -0.12 }).Within(1e-7));
            });
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestParallelIirFir()
        {
            var f1 = new IirFilter(new[] { 1,  0.4 }, new[] { 1, -0.6 });
            var f2 = new FirFilter(new[] { 1, -0.1 });

            var f = f1 + f2;

            replacedert.Multiple(() =>
            {
                replacedert.That(f.Tf.Numerator, Is.EqualTo(new[] { 2, -0.3, 0.06 }).Within(1e-7));
                replacedert.That(f.Tf.Denominator, Is.EqualTo(new[] { 1, -0.6 }).Within(1e-7));
                replacedert.That(f, Is.TypeOf<IirFilter>());
            });
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestTfToSos()
        {
            var zeros = new Complex[6]
            {
                new Complex(1,    0),
                new Complex(0.5,  0.2),
                new Complex(-0.3, 0),
                new Complex(0.2, -0.9),
                new Complex(0.5, -0.2),
                new Complex(0.2,  0.9)
            };
            var poles = new Complex[7]
            {
                new Complex(1,    0),
                new Complex(0.2,  0),
                new Complex(0.5,  0),
                new Complex(-0.9, 0.2),
                new Complex(0.6,  0),
                new Complex(0.1,  0),
                new Complex(-0.9, -0.2)
            };

            var sos = DesignFilter.TfToSos(new TransferFunction(zeros, poles));

            replacedert.Multiple(() =>
            {
                replacedert.That(sos[0].Numerator,   Is.EqualTo(new[] { 1, -0.4, 0.85 }).Within(1e-10));
                replacedert.That(sos[0].Denominator, Is.EqualTo(new[] { 1, -0.1,    0 }).Within(1e-10));
                replacedert.That(sos[1].Numerator,   Is.EqualTo(new[] { 1,   -1, 0.29 }).Within(1e-10));
                replacedert.That(sos[1].Denominator, Is.EqualTo(new[] { 1, -0.7,  0.1 }).Within(1e-10));
                replacedert.That(sos[2].Numerator,   Is.EqualTo(new[] { 1,  0.3,    0 }).Within(1e-10));
                replacedert.That(sos[2].Denominator, Is.EqualTo(new[] { 1,  1.8, 0.85 }).Within(1e-10));
                replacedert.That(sos[3].Numerator,   Is.EqualTo(new[] { 1,   -1,    0 }).Within(1e-10));
                replacedert.That(sos[3].Denominator, Is.EqualTo(new[] { 1, -1.6,  0.6 }).Within(1e-10));
                replacedert.That(sos.Length, Is.EqualTo(4));
            });
        }

19 Source : TestTransferFunction.cs
with MIT License
from ar1st0crat

[Test]
        public void TestStateSpaceToTf()
        {
            var tf = new TransferFunction(new[] { 1, 0.7, -0.2, 0.1 }, new[] { 1, 0.5, 0.9, 0.6 });
            var ss = tf.StateSpace;

            var tfs = new TransferFunction(ss);

            replacedert.Multiple(() =>
            {
                replacedert.That(tf.Numerator, Is.EqualTo(tf.Numerator).Within(1e-10));
                replacedert.That(tf.Denominator, Is.EqualTo(tf.Denominator).Within(1e-10));
            });
        }

19 Source : TestWienerFilter.cs
with MIT License
from ar1st0crat

[Test]
        public void TestWienerFilteringBigNoise()
        {
            var filter = new WienerFilter(3, 1000);

            var input = new[] { 5, 4, 6, 2, 1f };
            var expected = new[] { 3, 5, 4, 3, 1f };

            var filtered = filter.ApplyTo(new DiscreteSignal(1, input));

            replacedert.That(filtered.Samples, Is.EqualTo(expected).Within(1e-10));
        }

19 Source : TestWienerFilter.cs
with MIT License
from ar1st0crat

[Test]
        public void TestWienerFilteringNoNoise()
        {
            var filter = new WienerFilter(3, 0.1);

            var input = new[] { 5, 4, 6, 2, 1f };
            var expected = new[] { 4.95714286f, 4.15f, 5.925f, 2.02142857f, 1 };

            var filtered = filter.ApplyTo(new DiscreteSignal(1, input));

            replacedert.That(filtered.Samples, Is.EqualTo(expected).Within(1e-5));
        }

19 Source : TestConvolution.cs
with MIT License
from ar1st0crat

[Test]
        public void TestFftConvolution()
        {
            var conv = Operation.Convolve(_input, _kernel);

            replacedert.That(conv.Samples, Is.EqualTo(_output.Samples).Within(1e-5));
        }

19 Source : TestConvolution.cs
with MIT License
from ar1st0crat

[Test]
        public void TestFftCrossCorrelation()
        {
            var conv = Operation.CrossCorrelate(_input, _kernel);

            replacedert.That(conv.Samples, Is.EqualTo(new[] { 1, 8, 20, 21, 18, 24, 19, 7, 2.0f }).Within(1e-5));
        }

19 Source : TestConvolution.cs
with MIT License
from ar1st0crat

[Test]
        public void TestInPlaceCrossCorrelation()
        {
            float[] res = new float[16];

            new Convolver(16).CrossCorrelate(_input.Samples, _kernel.Samples, res);

            replacedert.That(res, Is.EqualTo(new[] { 1, 8, 20, 21, 18, 24, 19, 7, 2.0f, 0, 0, 0, 0, 0, 0, 0 }).Within(1e-5));
        }

19 Source : TestConvolution.cs
with MIT License
from ar1st0crat

[Test]
        public void TestImaginaryParts()
        {
            var s1 = new ComplexDiscreteSignal(1, new[] { 1, 0.5 }, new[] { 0, -1.5 });
            var s2 = new ComplexDiscreteSignal(1, new[] { 1, 0.5 }, new[] { 0, 1.5 });

            var conv = Operation.Convolve(s1, s2);

            replacedert.Multiple(() =>
            {
                replacedert.That(conv.Real, Is.EquivalentTo(new[] {1, 1, 2.5}));
                replacedert.That(conv.Imag, Is.EqualTo(new[] {0, 0, 0}).Within(1e-6));
            });
        }

19 Source : TestResampling.cs
with MIT License
from ar1st0crat

[Test]
        public void TestSameSamplingRate()
        {
            var signal = new DiscreteSignal(16000, new [] {1.0f, -2, 3, 1, 4, -2, 1, -5, 3});

            var resampled = Operation.Resample(signal, 16000);

            replacedert.Multiple(() =>
            {
                replacedert.That(resampled.Samples, Is.EqualTo(resampled.Samples).Within(1e-10));
                replacedert.That(resampled, Is.Not.SameAs(signal));
            });
        }

19 Source : TestSignalBuilders.cs
with MIT License
from ar1st0crat

[Test]
        public void TestBuilderSuperimpose()
        {
            var constants = new DiscreteSignal(1, length: 6, value: 2.0f);

            var sinusoid = new SineBuilder()
                                    .SetParameter("freq", 0.05f)
                                    .SuperimposedWith(constants)
                                    .OfLength(20)
                                    .SuperimposedWith(constants)    // twice
                                    .Build();

            replacedert.Multiple(() =>
            {
                replacedert.That(sinusoid[0], Is.EqualTo(4.0).Within(1e-7));
                replacedert.That(sinusoid[5], Is.EqualTo(5.0).Within(1e-7));
                replacedert.That(sinusoid[10], Is.EqualTo(0.0).Within(1e-7));
                replacedert.That(sinusoid[15], Is.EqualTo(-1.0).Within(1e-7));
                replacedert.That(sinusoid.Length, Is.EqualTo(20));
            });
        }

19 Source : TestSignalBuilders.cs
with MIT License
from ar1st0crat

[Test]
        public void TestBuilderDelay()
        {
            var sinusoid = new SineBuilder()
                                    .SetParameter("freq", 0.05f)
                                    .OfLength(20)
                                    .DelayedBy(1)
                                    .Build();

            replacedert.Multiple(() =>
            {
                replacedert.That(sinusoid[1], Is.EqualTo(0.0).Within(1e-7));
                replacedert.That(sinusoid[6], Is.EqualTo(1.0).Within(1e-7));
                replacedert.That(sinusoid[16], Is.EqualTo(-1.0).Within(1e-7));
                replacedert.That(sinusoid.Length, Is.EqualTo(21));
            });
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestDct2Norm()
        {
            float[] res = new float[6];
            float[] resDct2 = { 0.91923882f, -0.11214018f,  0.35370055f, -0.30289775f, 0.49497475f,  0.18332565f };

            var dct2 = new Dct2(8);
            dct2.DirectNorm(_test, res);

            replacedert.That(res, Is.EqualTo(resDct2).Within(1e-5));
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestDct3()
        {
            float[] input = { 5.2f,       -0.44856072f,  1.41480218f, -1.21159099f,
                              1.97989899f, 0.73330259f, -0.27988351f, -0.8204315f };
            float[] res = new float[6];
            float[] resDct3 = { 8, 3.2f, 1.6f, 9.6f, 1.6f, 0 };

            var dct3 = new Dct3(8);
            dct3.Direct(input, res);

            replacedert.That(res, Is.EqualTo(resDct3).Within(1e-5));
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestDct3Norm()
        {
            float[] res = new float[6];
            float[] resDct3 = { 0.74128407f, -0.17563463f,  0.3547784f , -0.43094061f,  0.64801169f, 0.16695983f };

            var dct3 = new Dct3(8);
            dct3.DirectNorm(_test, res);

            replacedert.That(res, Is.EqualTo(resDct3).Within(1e-5));
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestDct4()
        {
            float[] res = new float[6];
            float[] resDct4 = { 2.93983455f, -0.44002102f,  0.91148631f, -0.83446081f,  2.91784085f, -0.99510869f };

            var dct4 = new Dct4(8);
            dct4.Direct(_test, res);

            replacedert.That(res, Is.EqualTo(resDct4).Within(1e-5));
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestDct4Norm()
        {
            float[] res = new float[6];
            float[] resDct4 = { 0.73495864f, -0.11000525f, 0.22787158f, -0.2086152f, 0.72946021f, -0.24877717f };

            var dct4 = new Dct4(8);
            dct4.DirectNorm(_test, res);

            replacedert.That(res, Is.EqualTo(resDct4).Within(1e-5));
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestIdct1()
        {
            float[] res = new float[6];
            float[] resDct1 = { 3.9f, -0.13297488f, 0.6176292f, -1.14818776f, 1.77017102f, 0.68116264f };

            var dct1 = new Dct1(8);
            dct1.Inverse(_test, res);

            replacedert.That(res, Is.EqualTo(resDct1).Within(1e-5));
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestIdct2()
        {
            float[] output = new float[8];
            float[] input = { 5.2f, -0.44856072f, 1.41480218f, -1.21159099f, 1.97989899f, 0.73330259f };
            float[] expected =  { 8.53433006f,  1.77122807f,  3.48148502f,  7.77645215f,
                                   2.99512072f, -0.84717044f,  5.19445736f, 12.69409707f };

            var invdct = new Dct2(8);
            invdct.Inverse(input, output);

            replacedert.That(output, Is.EqualTo(expected).Within(1e-5));
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestIdct3()
        {
            float[] res = new float[8];
            float[] resDct3 = { 5.2f,       -0.44856072f,  1.41480218f, -1.21159099f,
                                1.97989899f, 0.73330259f, -0.27988351f, -0.8204315f };

            var invdct = new Dct3(8);
            invdct.Inverse(_test, res);

            replacedert.That(res, Is.EqualTo(resDct3).Within(1e-5));
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestIdct4()
        {
            float[] res = new float[6];
            float[] resDct4 = { 2.93983455f, -0.44002102f, 0.91148631f, -0.83446081f, 2.91784085f, -0.99510869f };

            var dct4 = new Dct4(8);
            dct4.Inverse(_test, res);

            replacedert.That(res, Is.EqualTo(resDct4).Within(1e-5));
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestMdct()
        {
            float[] res = new float[4];
            float[] fres = new float[4];
            float[] resMdct = { -0.38134489f, -0.01107969f, 0.27565625f, 0.09201603f };

            var mdct = new Mdct(4);
            var fmdct = new FastMdct(4);
            mdct.DirectNorm(_test, res);
            fmdct.DirectNorm(_test, fres);

            replacedert.Multiple(() =>
            {
                replacedert.That(res, Is.EqualTo(resMdct).Within(1e-5));
                replacedert.That(fres, Is.EqualTo(resMdct).Within(1e-5));
            });
        }

19 Source : TestDct.cs
with MIT License
from ar1st0crat

[Test]
        public void TestImdct()
        {
            float[] res = new float[8];
            float[] fres = new float[8];
            float[] resMdct = { -0.38134489f, -0.01107969f, 0.27565625f, 0.09201603f };

            var mdct = new Mdct(4);
            var fmdct = new FastMdct(4);
            mdct.InverseNorm(resMdct, res);
            fmdct.InverseNorm(resMdct, fres);

            replacedert.Multiple(() =>
            {
                replacedert.That(res, Is.EqualTo(new[] { -0.05f, 0.05f, -0.05f, 0.05f, 0.45f, 0.15f, 0.15f, 0.45f }).Within(1e-5));
                replacedert.That(fres, Is.EqualTo(res).Within(1e-5));
            });
        }

19 Source : TestFft.cs
with MIT License
from ar1st0crat

[Test]
        public void TestRealFft()
        {
            float[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; // Enumerable.Range(0, 16);

            float[] re = new float[9];
            float[] im = new float[9];

            var realFft = new RealFft(16);

            realFft.Direct(array, re, im);

            replacedert.That(re, Is.EqualTo(new float[] { 120, -8, -8, -8, -8, -8, -8, -8, -8 }).Within(1e-5));
            replacedert.That(im, Is.EqualTo(new float[] { 0, 40.21872f, 19.31371f, 11.97285f, 8, 5.34543f, 3.31371f, 1.591299f, 0 }).Within(1e-5));
        }

19 Source : TestFft.cs
with MIT License
from ar1st0crat

[Test]
        public void TestInverseRealFft()
        {
            float[] array = { 1, 5, 3, 7, 2, 3, 0, 7 };
            float[] output = new float[array.Length];
            float[] outputNorm = new float[array.Length];

            float[] re = new float[5];
            float[] im = new float[5];

            var realFft = new RealFft(8);

            realFft.Direct(array, re, im);
            realFft.Inverse(re, im, output);
            realFft.InverseNorm(re, im, outputNorm);

            replacedert.Multiple(() =>
            {
                replacedert.That(output, Is.EqualTo(array.Select(a => a * 8)).Within(1e-5));
                replacedert.That(outputNorm, Is.EqualTo(array).Within(1e-5));
            });
        }

19 Source : TestFft.cs
with MIT License
from ar1st0crat

[Test]
        public void TestComplexFft()
        {
            float[] re = { 0, 1, 2, 3, 4, 5, 6, 7 };
            float[] im = new float[8];

            var fft = new Fft(8);

            fft.Direct(re, im);

            replacedert.That(re, Is.EqualTo(new float[] { 28, -4, -4, -4, -4, -4, -4, -4 }).Within(1e-5));
            replacedert.That(im, Is.EqualTo(new float[] { 0, 9.65685f, 4, 1.65685f, 0, -1.65685f, -4, -9.65685f }).Within(1e-5));
        }

19 Source : TestFft.cs
with MIT License
from ar1st0crat

[Test]
        public void TestInverseFft()
        {
            float[] re = { 1, 5, 3, 7, 2, 3, 0, 7 };
            float[] im = new float[re.Length];

            var fft = new Fft(8);

            fft.Direct(re, im);
            fft.Inverse(re, im);

            replacedert.That(re, Is.EqualTo(new[] { 8, 40, 24, 56, 16, 24, 0, 56 }).Within(1e-5)); 
            // re[i] * 8,  i = 0..7
        }

19 Source : TestFft.cs
with MIT License
from ar1st0crat

[Test]
        public void TestInverseFftNormalized()
        {
            float[] re = { 1, 5, 3, 7, 2, 3, 0, 7 };
            float[] im = new float[re.Length];

            var fft = new Fft(8);

            fft.Direct(re, im);
            fft.InverseNorm(re, im);

            replacedert.That(re, Is.EqualTo(new[] { 1, 5, 3, 7, 2, 3, 0, 7 }).Within(1e-5));
        }

19 Source : TestFft.cs
with MIT License
from ar1st0crat

[Test]
        public void TestGoertzel()
        {
            float[] array = { 1, 2, 3, 4, 5, 6, 7, 8 };

            var cmpx = new Goertzel(8).Direct(array, 2);

            replacedert.Multiple(() =>
            {
                replacedert.That(cmpx.Real, Is.EqualTo(-4).Within(1e-6));
                replacedert.That(cmpx.Imaginary, Is.EqualTo(4).Within(1e-6));
            });
        }

19 Source : TestFft.cs
with MIT License
from ar1st0crat

[Test]
        public void TestHartley()
        {
            float[] re = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };

            var dht = new HartleyTransform(16);

            dht.Direct(re);
            dht.InverseNorm(re);

            replacedert.That(re, Is.EqualTo(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16f }).Within(1e-4));
        }

19 Source : TestMathFunctions.cs
with MIT License
from ar1st0crat

[Test]
        public void TestLinearInterpolationBigStep()
        {
            var x = new[] { 0, 1.4f, 2.8f, 4.2f, 5.6f, 7.0f, 8.4f };
            var y = new[] { 5, 15, 6, 2, 8, 4, 10.0f };
            var arg = new[] { 0, 1, 2, 3, 4.0f };
            var interp = new float[arg.Length];

            MathUtils.InterpolateLinear(x, y, arg, interp);

            replacedert.That(interp, Is.EqualTo(new[] { 5, 12.142857f, 11.142857f, 5.428571f, 2.571429f }).Within(1e-4));
        }

19 Source : TestMathFunctions.cs
with MIT License
from ar1st0crat

[Test]
        public void TestLinearInterpolationSmallStep()
        {
            var x = new[] { 0, 0.4f, 0.8f, 1.2f, 1.6f, 2.0f, 2.4f, 2.8f, 3.2f };
            var y = new[] { 5, 15, 6, 2, 8, 4, 10, 6, 2.0f };
            var arg = new[] { 0, 1, 2, 3.0f };
            var interp = new float[arg.Length];

            MathUtils.InterpolateLinear(x, y, arg, interp);

            replacedert.That(interp, Is.EqualTo(new[] { 5.0f, 4, 4, 4 }).Within(1e-4));
        }

19 Source : TestMathFunctions.cs
with MIT License
from ar1st0crat

[Test]
        public void TestRealPolynomialRoots()
        {
            double[] re = { 1, 2, -5, -6 };
            
            var roots = MathUtils.PolynomialRoots(re);

            double[] expected = {-3, -1, 2};
            replacedert.That(roots.Select(r => r.Real).OrderBy(r => r), Is.EqualTo(expected).Within(1e-7));
        }

19 Source : TestMathFunctions.cs
with MIT License
from ar1st0crat

[Test]
        public void TestComplexPolynomialRoots()
        {
            double[] re = { 1, 1, 2.5 };
            
            var roots = MathUtils.PolynomialRoots(re);

            double[] expectedReal = { -0.5, -0.5 };
            double[] expectedImag = { -1.5, 1.5 };

            replacedert.Multiple(() =>
            {
                replacedert.That(roots.Select(r => r.Real).OrderBy(r => r), Is.EqualTo(expectedReal).Within(1e-7));
                replacedert.That(roots.Select(r => r.Imaginary).OrderBy(r => r), Is.EqualTo(expectedImag).Within(1e-7));
            });
        }

19 Source : TestMathFunctions.cs
with MIT License
from ar1st0crat

[Test]
        public void TestPolynomialDivision()
        {
            Complex[] num = { 2, 4, 6, 1, 2, 3 };
            Complex[] den = { 1, 2, 3 };

            var div = MathUtils.DividePolynomial(num, den);

            replacedert.Multiple(() =>
            {
                replacedert.That(div[0].Select(d => d.Real), Is.EqualTo(new[] {2.0, 0, 0, 1}).Within(1e-10));
                replacedert.That(div[0].Select(d => d.Imaginary), Is.EqualTo(new[] { 0.0, 0, 0, 0 }).Within(1e-10));
                replacedert.That(div[1].Select(d => d.Real), Is.All.EqualTo(0.0).Within(1e-10));
            });
        }

See More Examples