Пример #1
0
        public void Test_formatDLjava_lang_StringBufferLjava_text_FieldPosition()
        {
            // Test for method java.lang.StringBuffer
            // java.text.ChoiceFormat.format(double, java.lang.StringBuffer,
            // java.text.FieldPosition)
            FieldPosition field = new FieldPosition(0);
            StringBuilder buf   = new StringBuilder();
            String        r     = f1.Format(-1, buf, field).ToString();

            NUnit.Framework.Assert.AreEqual("Less than one", r, "Wrong choice for -1");
            buf.Length = 0;
            r          = f1.Format(0, buf, field).ToString();
            NUnit.Framework.Assert.AreEqual("Less than one", r, "Wrong choice for 0");
            buf.Length = 0;
            r          = f1.Format(1, buf, field).ToString();
            NUnit.Framework.Assert.AreEqual("one", r, "Wrong choice for 1");
            buf.Length = 0;
            r          = f1.Format(2, buf, field).ToString();
            NUnit.Framework.Assert.AreEqual("Between one and two", r, "Wrong choice for 2");
            buf.Length = 0;
            r          = f1.Format(3, buf, field).ToString();
            NUnit.Framework.Assert.AreEqual("Greater than two", r, "Wrong choice for 3");

            // Regression test for HARMONY-1081
            NUnit.Framework.Assert.AreEqual(0, new ChoiceFormat("|").Format(System.Double.NaN, new StringBuilder(),
                                                                            new FieldPosition(6)).Length);
            NUnit.Framework.Assert.AreEqual(0, new ChoiceFormat("|").Format(1, new StringBuilder(),
                                                                            new FieldPosition(6)).Length);
            NUnit.Framework.Assert.AreEqual("Less than one", f1.Format(System.Double.NaN, new StringBuilder(), field).ToString());
        }
Пример #2
0
        public void Test_formatL()
        {
            ChoiceFormat fmt = new ChoiceFormat(
                "-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE");

            NUnit.Framework.Assert.AreEqual("NEGATIVE_ONE", fmt.Format(Int64.MinValue));
            NUnit.Framework.Assert.AreEqual("NEGATIVE_ONE", fmt.Format(-1));
            NUnit.Framework.Assert.AreEqual("ZERO", fmt.Format(0));
            NUnit.Framework.Assert.AreEqual("ONE", fmt.Format(1));
            NUnit.Framework.Assert.AreEqual("GREATER_THAN_ONE", fmt.Format(Int64.MaxValue));
        }
Пример #3
0
        public void Test4106660()
        {
            double[]     limits  = { 3, 1, 2 };
            String[]     formats = { "Three", "One", "Two" };
            ChoiceFormat cf      = new ChoiceFormat(limits, formats);
            double       d       = 5.0;
            String       str     = cf.Format(d);

            if (!str.Equals("Two"))
            {
                Errln("format(" + d + ") = " + cf.Format(d));
            }
        }
Пример #4
0
        public void Test4106661()
        {
            ChoiceFormat fmt = new ChoiceFormat(
                "-1#are negative| 0#are no or fraction | 1#is one |1.0<is 1+ |2#are two |2<are more than 2.");

            Logln("Formatter Pattern : " + fmt.ToPattern());

            Logln("Format with -INF : " + fmt.Format(double.NegativeInfinity));
            Logln("Format with -1.0 : " + fmt.Format(-1.0));
            Logln("Format with 0 : " + fmt.Format(0));
            Logln("Format with 0.9 : " + fmt.Format(0.9));
            Logln("Format with 1.0 : " + fmt.Format(1));
            Logln("Format with 1.5 : " + fmt.Format(1.5));
            Logln("Format with 2 : " + fmt.Format(2));
            Logln("Format with 2.1 : " + fmt.Format(2.1));
            Logln("Format with NaN : " + fmt.Format(Double.NaN));
            Logln("Format with +INF : " + fmt.Format(double.PositiveInfinity));
        }
Пример #5
0
        public void Test4094906()
        {
            ChoiceFormat fmt = new ChoiceFormat(
                "-\u221E<are negative|0<are no or fraction|1#is one|1.0<is 1+|\u221E<are many.");

            if (!fmt.ToPattern().StartsWith("-\u221E<are negative|0.0<are no or fraction|1.0#is one|1.0<is 1+|\u221E<are many.", StringComparison.Ordinal))
            {
                Errln("Formatter Pattern : " + fmt.ToPattern());
            }
            Logln("Format with -INF : " + fmt.Format(double.NegativeInfinity));
            Logln("Format with -1.0 : " + fmt.Format(-1.0));
            Logln("Format with 0 : " + fmt.Format(0));
            Logln("Format with 0.9 : " + fmt.Format(0.9));
            Logln("Format with 1.0 : " + fmt.Format(1));
            Logln("Format with 1.5 : " + fmt.Format(1.5));
            Logln("Format with 2 : " + fmt.Format(2));
            Logln("Format with +INF : " + fmt.Format(double.PositiveInfinity));
        }
Пример #6
0
        public void Test4106659()
        {
            double[]     limits  = { 1, 2, 3 };
            String[]     formats = { "one", "two" };
            ChoiceFormat cf      = null;

            try
            {
                cf = new ChoiceFormat(limits, formats);
            }
            catch (Exception foo)
            {
                Logln("ChoiceFormat constructor should check for the array lengths");
                cf = null;
            }
            if (cf != null)
            {
                Errln(cf.Format(5));
            }
        }
Пример #7
0
 public void TestChoicePatternQuote()
 {
     String[] DATA =
     {
         // Pattern                  0 value           1 value
         "0#can''t|1#can",           "can't",          "can",
         "0#'pound(#)=''#'''|1#xyz", "pound(#)='#'",   "xyz",
         "0#'1<2 | 1\u22641'|1#''",  "1<2 | 1\u22641", "'",
     };
     for (int i = 0; i < DATA.Length; i += 3)
     {
         try
         {
             ChoiceFormat cf = new ChoiceFormat(DATA[i]);
             for (int j = 0; j <= 1; ++j)
             {
                 String @out = cf.Format(j);
                 if ([email protected](DATA[i + 1 + j]))
                 {
                     Errln("Fail: Pattern \"" + DATA[i] + "\" x " + j + " -> " +
                           @out + "; want \"" + DATA[i + 1 + j] + '"');
                 }
             }
             String pat  = cf.ToPattern();
             String pat2 = new ChoiceFormat(pat).ToPattern();
             if (!pat.Equals(pat2))
             {
                 Errln("Fail: Pattern \"" + DATA[i] + "\" x toPattern -> \"" + pat + '"');
             }
             else
             {
                 Logln("Ok: Pattern \"" + DATA[i] + "\" x toPattern -> \"" + pat + '"');
             }
         }
         catch (ArgumentException e)
         {
             Errln("Fail: Pattern \"" + DATA[i] + "\" -> " + e);
         }
     }
 }
Пример #8
0
        public void Test_ConstructorLjava_lang_String()
        {
            // Test for method java.text.ChoiceFormat(java.lang.String)
            String       formattedString;
            String       patternString = "-2#Inverted Orange| 0#No Orange| 0<Almost No Orange| 1#Normal Orange| 2#Expensive Orange";
            ChoiceFormat cf            = new ChoiceFormat(patternString);

            formattedString = cf.Format(System.Double.NegativeInfinity);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Inverted Orange"), "a) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(-3);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Inverted Orange"), "b) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(-2);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Inverted Orange"), "c) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(-1);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Inverted Orange"), "d) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(-0);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("No Orange"), "e) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(0);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("No Orange"), "f) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(0.1d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Almost No Orange"), "g) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(1);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Normal Orange"), "h) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(1.5d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Normal Orange"), "i) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(2);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Expensive Orange"), "j) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(3);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Expensive Orange"), "k) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(System.Double.PositiveInfinity);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Expensive Orange"), "l) Incorrect format returned: " + formattedString);
        }
Пример #9
0
        public void Test_Constructor_D_Ljava_lang_String()
        {
            // Test for method java.text.ChoiceFormat(double [], java.lang.String
            // [])
            String formattedString;

            double[]     appleLimits  = { 1, 2, 3, 4, 5 };
            String[]     appleFormats = { "Tiny Apple", "Small Apple", "Medium Apple",
                                          "Large Apple",    "Huge Apple" };
            ChoiceFormat cf = new ChoiceFormat(appleLimits, appleFormats);

            formattedString = cf.Format(System.Double.NegativeInfinity);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Tiny Apple"), "a) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(0.5d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Tiny Apple"), "b) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(1d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Tiny Apple"), "c) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(1.5d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Tiny Apple"), "d) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(2d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Small Apple"), "e) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(2.5d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Small Apple"), "f) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(3d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Medium Apple"), "g) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(4d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Large Apple"), "h) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(5d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Huge Apple"), "i) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(5.5d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Huge Apple"), "j) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(6.0d);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Huge Apple"), "k) Incorrect format returned: " + formattedString);
            formattedString = cf.Format(System.Double.PositiveInfinity);
            NUnit.Framework.Assert.IsTrue(formattedString.Equals("Huge Apple"), "l) Incorrect format returned: " + formattedString);
        }
Пример #10
0
        public void Test_formatD()
        {
            ChoiceFormat fmt = new ChoiceFormat(
                "-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE");

            NUnit.Framework.Assert.AreEqual("NEGATIVE_ONE", fmt.Format(System.Double.NegativeInfinity));
            NUnit.Framework.Assert.AreEqual("NEGATIVE_ONE", fmt.Format(-999999999D));
            NUnit.Framework.Assert.AreEqual("NEGATIVE_ONE", fmt.Format(-1.1d));
            NUnit.Framework.Assert.AreEqual("NEGATIVE_ONE", fmt.Format(-1.0d));
            NUnit.Framework.Assert.AreEqual("NEGATIVE_ONE", fmt.Format(-0.9d));
            NUnit.Framework.Assert.AreEqual("ZERO", fmt.Format(0.0d));
            NUnit.Framework.Assert.AreEqual("ZERO", fmt.Format(0.9d));
            NUnit.Framework.Assert.AreEqual("ONE", fmt.Format(1.0d));
            NUnit.Framework.Assert.AreEqual("GREATER_THAN_ONE", fmt.Format(1.1d));
            NUnit.Framework.Assert.AreEqual("GREATER_THAN_ONE", fmt.Format(999999999D));
            NUnit.Framework.Assert.AreEqual("GREATER_THAN_ONE", fmt.Format(System.Double.PositiveInfinity));
        }