/// <summary>
                /// Tests that samplers
                /// in <see cref="RandomNumberGenerator"/>
                /// filling an array with a sample fail
                /// when parameter sampleSize is too big to
                /// fit in the destination array.
                /// </summary>
                /// <typeparam name="TSample">The type of a sample point.</typeparam>
                /// <typeparam name="TParameters">
                /// The type of the distribution parameters.</typeparam>
                /// <param name="sampleArrayFunc">
                /// A method returning a sample from a
                /// statistical distribution having the specified
                /// parameters.</param>
                /// <param name="distributionParameters">The parameters of the distribution
                /// from which the sample is drawn.</param>
                public static void SampleSizeIsTooBig <TSample, TParameters>(
                    SampleArrayFunc <TSample, TParameters> sampleArrayFunc,
                    TParameters[] distributionParameters)
                {
                    string STR_EXCEPT_PDF_SAMPLESIZE_ARRAYLENGTH_MISMATCH =
                        String.Format(
                            (string)Reflector.ExecuteStaticMember(
                                typeof(ImplementationServices),
                                "GetResourceString",
                                new string[] { "STR_EXCEPT_PDF_SAMPLESIZE_ARRAYLENGTH_MISMATCH" }),
                            "sampleSize",
                            "destinationArray",
                            "destinationIndex");


                    string parameterName = "sampleSize";

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        sampleArrayFunc(
                            sampleSize: 2,
                            destinationArray: new TSample[1],
                            destinationIndex: 0,
                            parameters: distributionParameters);
                    },
                        expectedType: typeof(ArgumentException),
                        expectedPartialMessage: STR_EXCEPT_PDF_SAMPLESIZE_ARRAYLENGTH_MISMATCH,
                        expectedParameterName: parameterName);
                }
                /// <summary>
                /// Tests that samplers
                /// in <see cref="RandomNumberGenerator"/>
                /// filling an array with a sample fail
                /// when parameter destinationIndex is negative.
                /// </summary>
                /// <typeparam name="TSample">The type of a sample point.</typeparam>
                /// <typeparam name="TParameters">
                /// The type of the distribution parameters.</typeparam>
                /// <param name="sampleArrayFunc">
                /// A method returning a sample from a
                /// statistical distribution having the specified
                /// parameters.</param>
                /// <param name="distributionParameters">The parameters of the distribution
                /// from which the sample is drawn.</param>
                public static void DestinationIndexIsNegative <TSample, TParameters>(
                    SampleArrayFunc <TSample, TParameters> sampleArrayFunc,
                    TParameters[] distributionParameters)
                {
                    string STR_EXCEPT_PAR_MUST_BE_NON_NEGATIVE =
                        (string)Reflector.ExecuteStaticMember(
                            typeof(ImplementationServices),
                            "GetResourceString",
                            new string[] { "STR_EXCEPT_PAR_MUST_BE_NON_NEGATIVE" });

                    string parameterName = "destinationIndex";

                    // distribution.Sample(sampleSize, destinationArray, destinationIndex)
                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        sampleArrayFunc(
                            sampleSize: 1,
                            destinationArray: new TSample[1],
                            destinationIndex: -1,
                            parameters: distributionParameters);
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_PAR_MUST_BE_NON_NEGATIVE,
                        expectedParameterName: parameterName);
                }
Exemple #3
0
                /// <summary>
                /// Tests that the
                /// <see cref="ProbabilityDistribution.
                /// Sample(int, double[], int)"/>
                /// method fails when parameter sampleSize is too big to
                /// fit in the destination array.
                /// </summary>
                /// <param name="testableDistribution">
                /// The testable probability distribution providing the instance
                /// on which to invoke the methods to test and their expected
                /// behaviors.
                /// </param>
                public static void SampleSizeIsTooBig(
                    TestableProbabilityDistribution testableDistribution)
                {
                    string STR_EXCEPT_PDF_SAMPLESIZE_ARRAYLENGTH_MISMATCH =
                        String.Format(
                            (string)Reflector.ExecuteStaticMember(
                                typeof(ImplementationServices),
                                "GetResourceString",
                                new string[] { "STR_EXCEPT_PDF_SAMPLESIZE_ARRAYLENGTH_MISMATCH" }),
                            "sampleSize",
                            "destinationArray",
                            "destinationIndex");


                    string parameterName = "sampleSize";

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        testableDistribution.Distribution.Sample(
                            sampleSize: 2,
                            destinationArray: new double[1],
                            destinationIndex: 0);
                    },
                        expectedType: typeof(ArgumentException),
                        expectedPartialMessage: STR_EXCEPT_PDF_SAMPLESIZE_ARRAYLENGTH_MISMATCH,
                        expectedParameterName: parameterName);
                }
Exemple #4
0
                /// <summary>
                /// Tests that the
                /// <see cref="O:Novacta.Analytics.ProbabilityDistribution.
                /// Sample"/>
                /// method fails when parameter sampleSize is not positive.
                /// </summary>
                /// <param name="testableDistribution">
                /// The testable probability distribution providing the instance
                /// on which to invoke the methods to test and their expected
                /// behaviors.
                /// </param>
                public static void SampleSizeIsNotPositive(
                    TestableProbabilityDistribution testableDistribution)
                {
                    string STR_EXCEPT_PAR_MUST_BE_POSITIVE =
                        (string)Reflector.ExecuteStaticMember(
                            typeof(ImplementationServices),
                            "GetResourceString",
                            new string[] { "STR_EXCEPT_PAR_MUST_BE_POSITIVE" });

                    string parameterName = "sampleSize";

                    // distribution.Sample(sampleSize)
                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var values = testableDistribution.Distribution.Sample(
                            sampleSize: 0);
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_PAR_MUST_BE_POSITIVE,
                        expectedParameterName: parameterName);

                    // distribution.Sample(sampleSize, destinationArray, destinationIndex)
                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        testableDistribution.Distribution.Sample(
                            sampleSize: 0,
                            destinationArray: new double[1],
                            destinationIndex: 0);
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_PAR_MUST_BE_POSITIVE,
                        expectedParameterName: parameterName);
                }
Exemple #5
0
                /// <summary>
                /// Provides methods to test that the
                /// <see cref="O:Novacta.Analytics.ProbabilityDistribution.
                /// InverseCdf"/>
                /// method fails when the CDF cannot be inverted.
                /// </summary>
                /// <param name="testableDistribution">
                /// The testable probability distribution providing the instance
                /// on which to invoke the methods to test and their expected
                /// behaviors.
                /// </param>
                public static void CdfCannotBeInverted(
                    TestableProbabilityDistribution testableDistribution)
                {
                    string STR_EXCEPT_PDF_INVERSE_CDF_NOT_SUPPORTED =
                        (string)Reflector.ExecuteStaticMember(
                            typeof(ImplementationServices),
                            "GetResourceString",
                            new string[] { "STR_EXCEPT_PDF_INVERSE_CDF_NOT_SUPPORTED" });

                    // DoubleMatrix
                    ExceptionAssert.Throw(
                        () =>
                    {
                        var values = testableDistribution.Distribution.InverseCdf(
                            arguments: DoubleMatrix.Identity(2));
                    },
                        expectedType: typeof(NotSupportedException),
                        expectedMessage: STR_EXCEPT_PDF_INVERSE_CDF_NOT_SUPPORTED);

                    // ReadOnlyDoubleMatrix
                    ExceptionAssert.Throw(
                        () =>
                    {
                        var values = testableDistribution.Distribution.InverseCdf(
                            arguments: DoubleMatrix.Identity(2).AsReadOnly());
                    },
                        expectedType: typeof(NotSupportedException),
                        expectedMessage: STR_EXCEPT_PDF_INVERSE_CDF_NOT_SUPPORTED);
                }
Exemple #6
0
                /// <summary>
                /// Tests getting property
                /// <see cref="O:IReadOnlyTabularCollection{TValue, TCollection}.this"/>
                /// when a row index is out of range.
                /// </summary>
                /// <typeparam name="TValue">The type of the items in the collection.</typeparam>
                /// <typeparam name="TCollection">The type of the collection.</typeparam>
                /// <param name="source">The source instance on which to invoke the property getter.</param>
                public static void AnyRowIndexIsOutOrRange <TValue, TCollection>(
                    IReadOnlyTabularCollection <TValue, TCollection> source)
                    where TCollection : IReadOnlyTabularCollection <TValue, TCollection>
                {
                    Assert.IsNotNull(source);

                    string STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS =
                        (string)Reflector.ExecuteStaticMember(
                            typeof(ImplementationServices),
                            "GetResourceString",
                            new string[] { "STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS" });

                    string parameterName = null;

                    #region Int32

                    parameterName = "rowIndex";

                    // Int32

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source[-1, 0];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS,
                        expectedParameterName: parameterName);

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source[source.NumberOfRows, 0];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS,
                        expectedParameterName: parameterName);

                    // IndexCollection

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source[-1, IndexCollection.Range(0, source.NumberOfColumns - 1)];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS,
                        expectedParameterName: parameterName);

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source[source.NumberOfRows, IndexCollection.Range(0, source.NumberOfColumns - 1)];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS,
                        expectedParameterName: parameterName);

                    // String

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source[-1, ":"];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS,
                        expectedParameterName: parameterName);

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source[source.NumberOfRows, ":"];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS,
                        expectedParameterName: parameterName);

                    #endregion

                    #region IndexCollection

                    parameterName = "rowIndexes";

                    // Int32

                    //          IndexCollection instances cannot contain negative elements

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source[IndexCollection.Range(0, source.NumberOfRows), 0];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS,
                        expectedParameterName: parameterName);

                    // IndexCollection

                    //          IndexCollection instances cannot contain negative elements

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source[IndexCollection.Range(0, source.NumberOfRows), IndexCollection.Range(0, source.NumberOfColumns - 1)];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS,
                        expectedParameterName: parameterName);

                    // String

                    //          IndexCollection instances cannot contain negative elements

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source[IndexCollection.Range(0, source.NumberOfRows), ":"];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_INDEX_EXCEEDS_DIMS,
                        expectedParameterName: parameterName);

                    #endregion

                    #region String

                    parameterName = "rowIndexes";

                    var STR_EXCEPT_TAB_UNSUPPORTED_SUBREF_SYNTAX =
                        (string)Reflector.ExecuteStaticMember(
                            typeof(ImplementationServices),
                            "GetResourceString",
                            new string[] { "STR_EXCEPT_TAB_UNSUPPORTED_SUBREF_SYNTAX" });

                    // Int32

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source["", 0];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_UNSUPPORTED_SUBREF_SYNTAX,
                        expectedParameterName: parameterName);

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source["end", 0];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_UNSUPPORTED_SUBREF_SYNTAX,
                        expectedParameterName: parameterName);

                    // IndexCollection

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source["", IndexCollection.Range(0, source.NumberOfColumns - 1)];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_UNSUPPORTED_SUBREF_SYNTAX,
                        expectedParameterName: parameterName);

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source["end", IndexCollection.Range(0, source.NumberOfColumns - 1)];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_UNSUPPORTED_SUBREF_SYNTAX,
                        expectedParameterName: parameterName);

                    // String

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source["", ":"];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_UNSUPPORTED_SUBREF_SYNTAX,
                        expectedParameterName: parameterName);

                    ArgumentExceptionAssert.Throw(
                        () =>
                    {
                        var sub =
                            source["end", ":"];
                    },
                        expectedType: typeof(ArgumentOutOfRangeException),
                        expectedPartialMessage: STR_EXCEPT_TAB_UNSUPPORTED_SUBREF_SYNTAX,
                        expectedParameterName: parameterName);

                    #endregion
                }