Example #1
0
                /// <summary>
                /// Provides methods to test that the
                /// <see cref="NumericalBin.
                /// GetNumericalBins(DoubleMatrix, DoubleMatrix)"/>
                /// method fails when numerical and target data
                /// have different lengths.
                public static void NumericalAndTargetDataHaveDifferentLengths()
                {
                    var numericalData = DoubleMatrix.Dense(5, 1,
                                                           new double[5] {
                        -1, -1, -1, 1, 1
                    });
                    var targetData = DoubleMatrix.Dense(4, 1,
                                                        new double[4] {
                        20, 10, 10, 10
                    });

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var bins = NumericalBin.GetNumericalBins(
                            numericalData,
                            targetData);
                    },
                        expectedType: typeof(ArgumentException),
                        expectedPartialMessage: string.Format(
                            ImplementationServices.GetResourceString(
                                "STR_EXCEPT_PAR_MUST_HAVE_SAME_COUNT"),
                            nameof(numericalData)),
                        expectedParameterName: "targetData");
                }
Example #2
0
        public void ToStringTest()
        {
            var numericalData = DoubleMatrix.Dense(5, 1,
                                                   new double[5] {
                -1, -1, -1, 1, 1
            });
            var targetData = DoubleMatrix.Dense(5, 1,
                                                new double[5] {
                10, 20, 10, 10, 10
            });
            var bins = NumericalBin.GetNumericalBins(numericalData, targetData);

            // Two bins expected
            string expected, actual;

            // bins[0]

            expected = "Values: [-1, -1]. Positions: [0, 2]. " +
                       "Target Distribution: [ " +
                       "(10, 2) " +
                       "(20, 1) ]";
            actual = bins[0].ToString();

            Assert.AreEqual(expected, actual);

            // bins[1]

            expected = "Values: [1, 1]. Positions: [3, 4]. " +
                       "Target Distribution: [ " +
                       "(10, 2) " +
                       "(20, 0) ]";
            actual = bins[1].ToString();

            Assert.AreEqual(expected, actual);
        }
Example #3
0
                /// Tests that the
                /// <see cref="NumericalBin.
                /// GetNumericalBins(DoubleMatrix, DoubleMatrix)"/>
                /// method terminates successfully as expected when
                /// its parameters are valid and a final cut point exists.
                /// </summary>
                public static void FinalCutPointExists()
                {
                    var numericalData = DoubleMatrix.Dense(5, 1,
                                                           new double[5] {
                        -1, -1, 1, 1, 2
                    });
                    var targetData = DoubleMatrix.Dense(5, 1,
                                                        new double[5] {
                        10, 20, 10, 10, 10
                    });
                    var bins = NumericalBin.GetNumericalBins(
                        numericalData,
                        targetData);

                    NumericalBinAssert.IsStateAsExpected(
                        target: bins[0],
                        expectedFirstPosition: 0,
                        expectedLastPosition: 1,
                        expectedFirstValue: -1,
                        expectedLastValue: -1,
                        expectedTargetFrequencyDistribution:
                        new Dictionary <double, int>(2)
                    {
                        { 10, 1 }, { 20, 1 }
                    });

                    NumericalBinAssert.IsStateAsExpected(
                        target: bins[1],
                        expectedFirstPosition: 2,
                        expectedLastPosition: 3,
                        expectedFirstValue: 1,
                        expectedLastValue: 1,
                        expectedTargetFrequencyDistribution:
                        new Dictionary <double, int>(1)
                    {
                        { 10, 2 }, { 20, 0 }
                    });

                    NumericalBinAssert.IsStateAsExpected(
                        target: bins[2],
                        expectedFirstPosition: 4,
                        expectedLastPosition: 4,
                        expectedFirstValue: 2,
                        expectedLastValue: 2,
                        expectedTargetFrequencyDistribution:
                        new Dictionary <double, int>(1)
                    {
                        { 10, 1 }, { 20, 0 }
                    });
                }
Example #4
0
                /// <summary>
                /// Provides methods to test that the
                /// <see cref="NumericalBin.
                /// GetNumericalBins(DoubleMatrix, DoubleMatrix)"/>
                /// method fails when the numerical data is <b>null</b>.
                public static void NumericalDataIsNull()
                {
                    DoubleMatrix numericalData = null;
                    var          targetData    = DoubleMatrix.Dense(5, 1,
                                                                    new double[5] {
                        10, 20, 10, 10, 10
                    });

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var bins = NumericalBin.GetNumericalBins(
                            numericalData,
                            targetData);
                    },
                        expectedType: typeof(ArgumentNullException),
                        expectedPartialMessage: ArgumentExceptionAssert.NullPartialMessage,
                        expectedParameterName: "numericalData");
                }
Example #5
0
                /// Tests that the
                /// <see cref="NumericalBin.
                /// GetNumericalBins(DoubleMatrix, DoubleMatrix)"/>
                /// method terminates successfully as expected when
                /// its parameters are valid and the data length is 1.
                /// </summary>
                public static void DataLengthIsOne()
                {
                    var numericalData = DoubleMatrix.Dense(1, 1, -1);
                    var targetData    = DoubleMatrix.Dense(1, 1, 10);
                    var bins          = NumericalBin.GetNumericalBins(
                        numericalData,
                        targetData);

                    NumericalBinAssert.IsStateAsExpected(
                        target: bins[0],
                        expectedFirstPosition: 0,
                        expectedLastPosition: 0,
                        expectedFirstValue: -1,
                        expectedLastValue: -1,
                        expectedTargetFrequencyDistribution:
                        new Dictionary <double, int>(1)
                    {
                        { 10, 1 }
                    });
                }