示例#1
0
        public void SmartDouble_Parse_ToString_BruteForce_Heavy_Test()
        {
            int test_count = 10000000;
            int parta_max  = 1000000000;
            int partb_max  = 1000000000;

            Random R = new Random();

            for (int i = 0; i < test_count; i++)
            {
                string s_parta = R.Next(parta_max).ToString();
                string s_partb = R.Next(partb_max).ToString();

                while ((s_partb.Length > 0) && (s_partb[s_partb.Length - 1] == '0'))
                {
                    s_partb = s_partb.Substring(0, s_partb.Length - 1);
                }

                string s_sd1 = s_parta;
                if (!string.IsNullOrEmpty(s_partb))
                {
                    s_sd1 += ("." + s_partb);
                }

                SmartDouble sd    = SmartDouble.Parse(s_sd1);
                string      s_sd2 = sd.ToString();

                Double d    = Double.Parse(s_sd1);
                string s_d2 = d.ToString();

                // Cross
                d  = Double.Parse(s_sd2);
                sd = SmartDouble.Parse(s_d2);

                Double error = Math.Abs((d - sd) / d);

                Assert.IsTrue(error < 1E-14, "Compare2DoubleHeavy " + s_sd1);
            }
        }
示例#2
0
        public void SmartDouble_Parse_ToString_BruteForce_Test()
        {
            int test_count = 10000000;
            int parta_max  = 1000000;
            int partb_max  = 1000000;

            Random R = new Random();

            for (int i = 0; i < test_count; i++)
            {
                string s_parta = R.Next(parta_max).ToString();
                string s_partb = R.Next(partb_max).ToString();

                // if (s_partb == "0")
                //    continue;

                while ((s_partb.Length > 0) && (s_partb[s_partb.Length - 1] == '0'))
                {
                    s_partb = s_partb.Substring(0, s_partb.Length - 1);
                }

                string s_sd1 = s_parta;
                if (!string.IsNullOrEmpty(s_partb))
                {
                    s_sd1 += ("." + s_partb);
                }

                //if (s_sd1.Length > 12)
                //    s_sd1 = s_sd1.Substring(0, 12);

                SmartDouble sd    = SmartDouble.Parse(s_sd1);
                string      s_sd2 = sd.ToString(8);

                Double d    = Double.Parse(s_sd1);
                string s_d2 = d.ToString();

                Assert.AreEqual(s_sd2, s_d2, "Compare2Double " + s_sd1);
            }
        }