예제 #1
0
        public static string StringFormat(string format, string[] args)
        {
            StringDistribution result = StringFormatOp_RequireEveryPlaceholder_NoArgumentNames.StrAverageConditional(
                StringDistribution.String(format), args);

            if (result.IsZero())
            {
                throw new ConstraintViolatedException(string.Format(
                                                          "The format string \"{0}\" was ill-formatted or not consistent with the argument list.",
                                                          format));
            }

            Debug.Assert(result.IsPointMass, "Must be a point mass.");
            return(result.Point);
        }
예제 #2
0
 /// <summary>
 /// A helper function for testing messages to <c>format</c>.
 /// </summary>
 /// <param name="str">The message from <c>str</c>.</param>
 /// <param name="args">The message from <c>args</c>.</param>
 /// <param name="expectedFormatRequireEveryPlaceholder">
 /// The expected message to <c>format</c> if the format string is required to contain placeholders for all arguments.
 /// </param>
 /// <param name="expectedFormatAllowMissingPlaceholders">
 /// The expected message to <c>format</c> if the format string may not contain placeholders for some arguments.
 /// </param>
 private static void TestMessageToFormat(
     StringDistribution str,
     StringDistribution[] args,
     StringDistribution expectedFormatRequireEveryPlaceholder,
     StringDistribution expectedFormatAllowMissingPlaceholders)
 {
     string[] argNames = GetDefaultArgumentNames(args.Length);
     Assert.Equal(
         expectedFormatRequireEveryPlaceholder,
         StringFormatOp_RequireEveryPlaceholder_NoArgumentNames.FormatAverageConditional(str, args));
     Assert.Equal(
         expectedFormatRequireEveryPlaceholder,
         StringFormatOp_RequireEveryPlaceholder.FormatAverageConditional(str, args, argNames));
     Assert.Equal(
         expectedFormatAllowMissingPlaceholders,
         StringFormatOp_AllowMissingPlaceholders_NoArgumentNames.FormatAverageConditional(str, args));
     Assert.Equal(
         expectedFormatAllowMissingPlaceholders,
         StringFormatOp_AllowMissingPlaceholders.FormatAverageConditional(str, args, argNames));
 }
예제 #3
0
        /// <summary>
        /// A helper function for testing messages to <c>args</c>.
        /// </summary>
        /// <param name="str">The message from <c>str</c>.</param>
        /// <param name="format">The message from <c>format</c>.</param>
        /// <param name="args">The message from <c>args</c>.</param>
        /// <param name="expectedArgsRequireEveryPlaceholder">
        /// The expected message to <c>args</c> if the format string is required to contain placeholders for all arguments.
        /// </param>
        /// <param name="expectedArgsAllowMissingPlaceholders">
        /// The expected message to <c>args</c> if the format string may not contain placeholders for some arguments.
        /// </param>
        private static void TestMessageToArgs(
            StringDistribution str,
            StringDistribution format,
            StringDistribution[] args,
            StringDistribution[] expectedArgsRequireEveryPlaceholder,
            StringDistribution[] expectedArgsAllowMissingPlaceholders)
        {
            string[] argNames = GetDefaultArgumentNames(args.Length);
            var      result   = new StringDistribution[args.Length];

            Assert.Equal(
                expectedArgsRequireEveryPlaceholder,
                StringFormatOp_RequireEveryPlaceholder_NoArgumentNames.ArgsAverageConditional(str, format, args, result));
            Assert.Equal(
                expectedArgsRequireEveryPlaceholder,
                StringFormatOp_RequireEveryPlaceholder.ArgsAverageConditional(str, format, args, argNames, result));
            Assert.Equal(
                expectedArgsAllowMissingPlaceholders,
                StringFormatOp_AllowMissingPlaceholders_NoArgumentNames.ArgsAverageConditional(str, format, args, result));
            var actualArgs = StringFormatOp_AllowMissingPlaceholders.ArgsAverageConditional(str, format, args, argNames, result);

            Assert.Equal(expectedArgsAllowMissingPlaceholders, actualArgs);
        }