Beispiel #1
0
        public void When_Initialize()
        {
            var sut = new PercentFormatter();

            Assert.AreEqual(0, sut.SignificantDigits);
            Assert.AreEqual(1, sut.IntegerDigits);
            Assert.AreEqual(2, sut.FractionDigits);
            Assert.AreEqual(false, sut.IsGrouped);
            Assert.AreEqual(false, sut.IsZeroSigned);
            Assert.AreEqual(false, sut.IsDecimalPointAlwaysDisplayed);
            Assert.AreEqual("en-US", sut.ResolvedLanguage);
            Assert.IsNull(sut.NumberRounder);

            /*
             *      FractionDigits	2	int
             *      GeographicRegion	"US"	string
             *      IntegerDigits	1	int
             *      IsDecimalPointAlwaysDisplayed	false	bool
             *      IsGrouped	false	bool
             *      IsZeroSigned	false	bool
             *      NumberRounder	null	WindoGlobalization.NumberFormatting.INumberRounder
             *      NumeralSystem	"Latn"	string
             *      ResolvedGeographicRegion	"ZZ"	string
             *      ResolvedLanguage	"en-US"	string
             *      SignificantDigits	0	int
             *
             */
        }
Beispiel #2
0
        public void When_FormatSpecialDouble(double value, string expected)
        {
            var sut    = new PercentFormatter();
            var actual = sut.FormatDouble(value);

            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // 百分比格式化
            PercentFormatter percentFormatter = new PercentFormatter();

            // PercentFormatter percentFormatter = new PercentFormatter(new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text  = percentFormatter.Format(3.1415926);
            lblMsg.Text += Environment.NewLine;

            // 千分比格式化
            PermilleFormatter permilleFormatter = new PermilleFormatter();

            //  PermilleFormatter permilleFormatter = new PermilleFormatter(new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text += permilleFormatter.Format(3.1415926);
            lblMsg.Text += Environment.NewLine;

            // 数字格式化
            DecimalFormatter decimalFormatter = new DecimalFormatter();

            // DecimalFormatter decimalFormatter = new DecimalFormatter(new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text += decimalFormatter.Format(3.1415926);
            lblMsg.Text += Environment.NewLine;

            // 货币格式化
            CurrencyFormatter currencyFormatter = new CurrencyFormatter("CNY");

            // CurrencyFormatter currencyFormatter = new CurrencyFormatter("CNY", new[] { "zh-Hans-CN" }, "CN");
            lblMsg.Text += currencyFormatter.Format(3.1415926);
        }
    public void FinishTesting()
    {
        int total_word_count     = 0; // всего обработано слов
        int total_C_count        = 0;
        int error_count          = 0;
        int B_instead_of_C_count = 0;
        int C_instead_of_B_count = 0;

        FinishTesting(out total_word_count, out total_C_count, out error_count, out B_instead_of_C_count, out C_instead_of_B_count);


        Console.WriteLine("CONTEXT_SPAN={0}", CONTEXT_SPAN);
        Console.WriteLine("SUFFIX_LEN={0}", SUFFIX_LEN);
        Console.WriteLine("total_word_count={0}", total_word_count);
        Console.WriteLine("Segmentation error count={0}, i.e. {1}%", error_count, PercentFormatter.Percent(error_count, total_word_count));
        Console.WriteLine("B_instead_of_C_errors={0}%", PercentFormatter.Percent(B_instead_of_C_count, total_C_count));

        using (System.IO.StreamWriter wrt = new System.IO.StreamWriter("model-training.txt", true))
        {
            wrt.WriteLine("{0} TOKENIZER n_learn_samples={1} n_train_patterns={2} total_recognition_error={3} B_instead_of_C_errors={4}",
                          DateTime.Now.ToString("dd.MM.yyyy"), n_learn_samples, n_train_patterns, PercentFormatter.Percent(error_count, total_word_count),
                          PercentFormatter.Percent(B_instead_of_C_count, total_C_count)
                          );
        }

        return;
    }
Beispiel #5
0
        public void When_ParseNotValidDouble()
        {
            var sut = new PercentFormatter();

            var actual = sut.ParseDouble("a12%");

            Assert.AreEqual(null, actual);
        }
        /// <summary>
        /// This is the click handler for the 'Display' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Display_Click(object sender, RoutedEventArgs e)
        {
            // This scenario uses the Windows.Globalization.NumberFormatting.PercentFormatter and
            // the Windows.Globalization.NumberFormatting.PermilleFormatter classes to format numbers
            // as a percent or a permille.

            // Keep results of the scenario in a StringBuilder
            StringBuilder results = new StringBuilder();

            // Create numbers to format.
            double randomNumber = new Random().NextDouble();
            ulong  fixedNumber  = 500;

            // Create percent formatters.
            PercentFormatter defaultPercentFormatter = new PercentFormatter();
            PercentFormatter frPercentFormatter      = new PercentFormatter(new[] { "fr-FR" }, "ZZ");
            PercentFormatter arPercentFormatter      = new PercentFormatter(new[] { "ar" }, "ZZ");

            // Create permille formatters.
            PermilleFormatter defaultPermilleFormatter = new PermilleFormatter();
            PermilleFormatter arPermilleFormatter      = new PermilleFormatter(new[] { "ar" }, "ZZ");

            // Format random numbers as percent or permille.
            results.AppendLine("Random number (" + randomNumber + ")");
            results.AppendLine("Percent formatted: " + defaultPercentFormatter.Format(randomNumber));
            results.AppendLine("Permille formatted: " + defaultPermilleFormatter.Format(randomNumber));
            results.AppendLine();
            results.AppendLine("Language-specific percent formatted: " + frPercentFormatter.Format(randomNumber));
            results.AppendLine("Language-specific permille formatted: " + arPermilleFormatter.Format(randomNumber));
            results.AppendLine();
            results.AppendLine("Fixed number (" + fixedNumber + ")");

            // Format fixed number with grouping.
            defaultPercentFormatter.IsGrouped = true;
            results.AppendLine("Percent formatted (grouped): " + defaultPercentFormatter.Format(fixedNumber));

            //Format with grouping using French language.
            frPercentFormatter.IsGrouped = true;
            results.AppendLine("Percent formatted (grouped as fr-FR): " + frPercentFormatter.Format(fixedNumber));

            // Format with grouping using Arabic.
            results.AppendLine("Percent formatted (grouped w/digits as ar): " + arPercentFormatter.Format(fixedNumber));

            // Format with no fraction digits.
            defaultPercentFormatter.FractionDigits = 0;
            defaultPercentFormatter.IsGrouped      = false;
            results.AppendLine("Percent formatted (no fractional digits): " + defaultPercentFormatter.Format(fixedNumber));

            // Format always with a decimal point.
            defaultPercentFormatter.IsDecimalPointAlwaysDisplayed = true;
            defaultPercentFormatter.IsGrouped = false;
            results.AppendLine("Percent formatted (always with a decimal point): " + defaultPercentFormatter.Format(fixedNumber));

            // Display the results
            OutputTextBlock.Text = results.ToString();
        }
Beispiel #7
0
        public void When_ParseDouble(string value, double?expected)
        {
            var sut = new PercentFormatter();

            sut.FractionDigits = 2;

            var actual = sut.ParseDouble(value);

            Assert.AreEqual(expected, actual);
        }
Beispiel #8
0
        public void When_ParseDoubleAndIsDecimalPointAlwaysDisplayedSetTrue(string value, double?expected)
        {
            var sut = new PercentFormatter();

            sut.FractionDigits = 2;
            sut.IsDecimalPointAlwaysDisplayed = true;

            var actual = sut.ParseDouble(value);

            Assert.AreEqual(expected, actual);
        }
Beispiel #9
0
        public void When_FormatDoubleUsingSignificantDigitsNumberRounder()
        {
            var sut = new PercentFormatter();
            SignificantDigitsNumberRounder rounder = new SignificantDigitsNumberRounder();

            rounder.SignificantDigits = 1;
            sut.NumberRounder         = rounder;
            var formatted = sut.FormatDouble(1.8);

            Assert.AreEqual("200.00%", formatted);
        }
Beispiel #10
0
        public void When_FormatDoubleUsingIncrementNumberRounder()
        {
            var sut = new PercentFormatter();
            IncrementNumberRounder rounder = new IncrementNumberRounder();

            rounder.Increment = 0.5;
            sut.NumberRounder = rounder;
            var formatted = sut.FormatDouble(1.8);

            Assert.AreEqual("200.00%", formatted);
        }
Beispiel #11
0
        public void When_FormatDouble(double value, int integerDigits, int fractionDigits, string expected)
        {
            var sut = new PercentFormatter();

            sut.IntegerDigits  = integerDigits;
            sut.FractionDigits = fractionDigits;

            var formatted = sut.FormatDouble(value);

            Assert.AreEqual(expected, formatted);
        }
Beispiel #12
0
        public void When_FormatDoubleZeroWithIsZeroSignedSetTrue(int integerDigits, int fractionDigits, string expected)
        {
            var sut = new PercentFormatter();

            sut.IntegerDigits  = integerDigits;
            sut.FractionDigits = fractionDigits;
            sut.IsZeroSigned   = true;

            var formatted = sut.FormatDouble(0d);

            Assert.AreEqual(expected, formatted);
        }
Beispiel #13
0
        public void When_FormatDoubleWithIsDecimalPointerAlwaysDisplayedSetTrue(double value, string expected)
        {
            var sut = new PercentFormatter();

            sut.IsDecimalPointAlwaysDisplayed = true;
            sut.FractionDigits = 0;
            sut.IntegerDigits  = 0;

            var formatted = sut.FormatDouble(value);

            Assert.AreEqual(expected, formatted);
        }
Beispiel #14
0
        public void When_ParseDoubleMinusZero()
        {
            var  sut        = new PercentFormatter();
            var  actual     = sut.ParseDouble("-0%");
            bool isNegative = false;

            if (actual.HasValue)
            {
                isNegative = BitConverter.DoubleToInt64Bits(actual.Value) < 0;
            }

            Assert.AreEqual(true, isNegative);
        }
Beispiel #15
0
        public void When_ParseDoubleUsingSpeceficNumeralSystem(string numeralSystem)
        {
            var sut = new PercentFormatter();

            sut.NumeralSystem = numeralSystem;

            var translator = new NumeralSystemTranslator {
                NumeralSystem = numeralSystem
            };
            var translated = translator.TranslateNumerals("123456.789%");

            var actual = sut.ParseDouble(translated);

            Assert.AreEqual(1234.56789, actual);
        }
        /// <summary>
        /// This is the click handler for the 'Display' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Display_Click(object sender, RoutedEventArgs e)
        {
            // This scenario uses the Windows.Globalization.NumberFormatting.DecimalFormatter,
            // Windows.Globalization.NumberFormatting.CurrencyFormatter and
            // Windows.Globalization.NumberFormatting.PercentFormatter classes to format and parse a number
            // percentage or currency.

            // Keep results of the scenario in a StringBuilder
            StringBuilder results = new StringBuilder();

            // Define percent formatters.
            PercentFormatter percentFormat   = new PercentFormatter();
            PercentFormatter percentFormatJP = new PercentFormatter(new string[] { "ja" }, "ZZ");
            PercentFormatter percentFormatFR = new PercentFormatter(new string[] { "fr-FR" }, "ZZ");

            // Define decimal formatters.
            DecimalFormatter decimalFormat = new DecimalFormatter();

            decimalFormat.IsGrouped = true;
            DecimalFormatter decimalFormatJP = new DecimalFormatter(new string[] { "ja" }, "ZZ");

            decimalFormatJP.IsGrouped = true;
            DecimalFormatter decimalFormatFR = new DecimalFormatter(new string[] { "fr-FR" }, "ZZ");

            decimalFormatFR.IsGrouped = true;

            // Define currency formatters
            string            userCurrency     = GlobalizationPreferences.Currencies[0];
            CurrencyFormatter currencyFormat   = new CurrencyFormatter(userCurrency);
            CurrencyFormatter currencyFormatJP = new CurrencyFormatter("JPY", new string[] { "ja" }, "ZZ");
            CurrencyFormatter currencyFormatFR = new CurrencyFormatter("EUR", new string[] { "fr-FR" }, "ZZ");

            // Generate numbers for parsing.
            double percentNumber  = 0.523;
            double decimalNumber  = 12345.67;
            double currencyNumber = 1234.56;

            // Roundtrip the percent numbers by formatting and parsing.
            String percent1       = percentFormat.Format(percentNumber);
            double percent1Parsed = percentFormat.ParseDouble(percent1).Value;

            String percent1JP       = percentFormatJP.Format(percentNumber);
            double percent1JPParsed = percentFormatJP.ParseDouble(percent1JP).Value;

            String percent1FR       = percentFormatFR.Format(percentNumber);
            double percent1FRParsed = percentFormatFR.ParseDouble(percent1FR).Value;

            // Generate the results for percent parsing.
            results.AppendLine("Percent parsing of " + percentNumber);
            results.AppendLine("Formatted for current user: "******" Parsed as current user: "******"Formatted for ja-JP: " + percent1JP + " Parsed for ja-JP: " + percent1JPParsed);
            results.AppendLine("Formatted for fr-FR: " + percent1FR + " Parsed for fr-FR: " + percent1FRParsed);
            results.AppendLine();

            // Roundtrip the decimal numbers for formatting and parsing.
            String decimal1       = decimalFormat.Format(decimalNumber);
            double decimal1Parsed = decimalFormat.ParseDouble(decimal1).Value;

            String decimal1JP       = decimalFormatJP.Format(decimalNumber);
            double decimal1JPParsed = decimalFormatJP.ParseDouble(decimal1JP).Value;

            String decimal1FR       = decimalFormatFR.Format(decimalNumber);
            double decimal1FRParsed = decimalFormatFR.ParseDouble(decimal1FR).Value;

            // Generate the results for decimal parsing.
            results.AppendLine("Decimal parsing of " + decimalNumber);
            results.AppendLine("Formatted for current user: "******" Parsed as current user: "******"Formatted for ja-JP: " + decimal1JP + " Parsed for ja-JP: " + decimal1JPParsed);
            results.AppendLine("Formatted for fr-FR: " + decimal1FR + " Parsed for fr-FR: " + decimal1FRParsed);
            results.AppendLine();

            // Roundtrip the currency numbers for formatting and parsing.
            String currency1       = currencyFormat.Format(currencyNumber);
            double currency1Parsed = currencyFormat.ParseDouble(currency1).Value;

            String currency1JP       = currencyFormatJP.Format(currencyNumber);
            double currency1JPParsed = currencyFormatJP.ParseDouble(currency1JP).Value;

            String currency1FR       = currencyFormatFR.Format(currencyNumber);
            double currency1FRParsed = currencyFormatFR.ParseDouble(currency1FR).Value;

            // Generate the results for decimal parsing.
            results.AppendLine("Currency parsing of " + currencyNumber);
            results.AppendLine("Formatted for current user: "******" Parsed as current user: "******"Formatted for ja-JP: " + currency1JP + " Parsed for ja-JP: " + currency1JPParsed);
            results.AppendLine("Formatted for fr-FR: " + currency1FR + " Parsed for fr-FR: " + currency1FRParsed);
            results.AppendLine();

            // Display the results.
            OutputTextBlock.Text = results.ToString();
        }
Beispiel #17
0
 protected IndividualMoleculeTEXBuilder(ITeXBuilderRepository builderRepository, IRepresentationInfoRepository representationInfoRepository)
 {
     _builderRepository            = builderRepository;
     _representationInfoRepository = representationInfoRepository;
     _formatter = new PercentFormatter();
 }
        /// <summary>
        /// This is the click handler for the 'Display' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Display_Click(object sender, RoutedEventArgs e)
        {
            // This scenario uses language tags with unicode extensions to construct and use the various
            // formatters and NumeralSystemTranslator in Windows.Globalization.NumberFormatting to format numbers

            // Keep results of the scenario in a StringBuilder
            StringBuilder results = new StringBuilder();

            // Create number to format.
            double randomNumber = (new Random().NextDouble() * 100000);

            results.AppendLine("Random number used by formatters: " + randomNumber);
            // Create a string to translate
            String stringToTranslate = "These are the 10 digits of a numeral system: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9";

            results.AppendLine("String used by NumeralSystemTranslater: " + stringToTranslate);
            // Create the rounder and set its increment to 0.01
            IncrementNumberRounder rounder = new Windows.Globalization.NumberFormatting.IncrementNumberRounder();

            rounder.Increment = 0.001;
            results.AppendLine("CurrencyFormatter will be using Euro symbol and all formatters rounding to 0.001 increments");
            results.AppendLine();

            // The list of language tags with unicode extensions we want to test
            String[] languages = new[] { "de-DE-u-nu-telu-ca-buddist-co-phonebk-cu-usd", "ja-jp-u-nu-arab" };

            // Create the various formatters, now using the language list with unicode extensions
            results.AppendLine("Creating formatters using following languages in the language list:");
            foreach (String language in languages)
            {
                results.AppendLine("\t" + language);
            }
            results.AppendLine();

            // Create the various formatters.
            DecimalFormatter decimalFormatter = new DecimalFormatter(languages, "ZZ");

            decimalFormatter.NumberRounder = rounder; decimalFormatter.FractionDigits = 2;
            CurrencyFormatter currencyFormatter = new CurrencyFormatter(CurrencyIdentifiers.EUR, languages, "ZZ");

            currencyFormatter.NumberRounder = rounder; currencyFormatter.FractionDigits = 2;
            PercentFormatter percentFormatter = new PercentFormatter(languages, "ZZ");

            percentFormatter.NumberRounder = rounder; percentFormatter.FractionDigits = 2;
            PermilleFormatter permilleFormatter = new PermilleFormatter(languages, "ZZ");

            permilleFormatter.NumberRounder = rounder; permilleFormatter.FractionDigits = 2;
            NumeralSystemTranslator numeralTranslator = new NumeralSystemTranslator(languages);

            results.AppendLine("Using resolved language  " + decimalFormatter.ResolvedLanguage + "  : (note that all extension tags other than nu are ignored)");
            // Format using formatters and translate using NumeralSystemTranslator.
            results.AppendLine("Decimal Formatted:   " + decimalFormatter.Format(randomNumber));
            results.AppendLine("Currency formatted:   " + currencyFormatter.Format(randomNumber));
            results.AppendLine("Percent formatted:   " + percentFormatter.Format(randomNumber));
            results.AppendLine("Permille formatted:   " + permilleFormatter.Format(randomNumber));
            results.AppendLine("NumeralTranslator translated:   " + numeralTranslator.TranslateNumerals(stringToTranslate));
            results.AppendLine();

            // Display the results
            rootPage.NotifyUser(results.ToString(), NotifyType.StatusMessage);
        }
Beispiel #19
0
    public void PrintTestResults()
    {
        System.Console.WriteLine("total_check_word_count={0}", total_word_count);
        System.Console.WriteLine("raw_model_error_count={0}, i.e. {1}%", raw_model_error_count, PercentFormatter.Percent(raw_model_error_count, total_word_count));
        System.Console.WriteLine("error_count_no_filter={0}, i.e. {1}%", error_count_no_filter, PercentFormatter.Percent(error_count_no_filter, total_word_count));
        System.Console.WriteLine("error_count_with_ngram={0}, i.e. {1}%", error_count_with_ngram, PercentFormatter.Percent(error_count_with_ngram, total_word_count));

        using (System.IO.StreamWriter wr = new System.IO.StreamWriter("report.txt"))
        {
            wr.WriteLine("total_check_word_count={0}", total_word_count);
            wr.WriteLine("raw_model_error_count={0}, i.e. {1}%", raw_model_error_count, PercentFormatter.Percent(raw_model_error_count, total_word_count));
            wr.WriteLine("error_count_no_filter={0}, i.e. {1}%", error_count_no_filter, PercentFormatter.Percent(error_count_no_filter, total_word_count));
            wr.WriteLine("error_count_with_ngram={0}, i.e. {1}%", error_count_with_ngram, PercentFormatter.Percent(error_count_with_ngram, total_word_count));
        }

        return;
    }
 public void PrintTestResults()
 {
     System.Console.WriteLine("total_check_word_count={0}", total_word_count);
     System.Console.WriteLine("error_count_no_filter={0}, i.e. {1}%", error_count_no_filter, PercentFormatter.Percent(error_count_no_filter, total_word_count));
     System.Console.WriteLine("error_count_with_ngram={0}, i.e. {1}%", error_count_with_ngram, PercentFormatter.Percent(error_count_with_ngram, total_word_count));
     return;
 }