Beispiel #1
0
        public void Test_RandomConvert()
        {
            int rngSeed = DateTime.Now.Millisecond;

            Console.WriteLine("RNG seed {0}", rngSeed);
            Random rnd         = new Random(rngSeed);
            int    repetitions = 100000;

            for (int rep = 0; rep < repetitions; ++rep)
            {
                Double value  = rnd.NextDouble();
                Real01 r      = new Real01(value);
                Double value1 = r.ToDouble();
                Assert.AreEqual(value, value1, Real01.EPSILON);

                // Test conversion operators.
                r      = value;
                value1 = (double)r;
                Assert.AreEqual(value, value1, Real01.EPSILON);

                // Test converter of internal representation
                UInt32 data = Real01.FromDouble(value);
                value1 = Real01.ToDouble(data);
                Assert.AreEqual(value, value1, Real01.EPSILON);
            }
        }
Beispiel #2
0
        public void Test_SimpleConvert()
        {
            double[] values = new double[] { 1.0, 0.0, 0.5, 0.333, 0.00000001 };
            for (int i = 0; i < values.Length; ++i)
            {
                Double value  = values[i];
                Real01 r      = new Real01(value);
                Double value1 = r.ToDouble();
                Assert.AreEqual(value, value1, Real01.EPSILON);

                // Test conversion operators.
                r      = value;
                value1 = (double)r;
                Assert.AreEqual(value, value1, Real01.EPSILON);

                // Test converter of internal representation
                UInt32 data = Real01.FromDouble(value);
                value1 = Real01.ToDouble(data);
                Assert.AreEqual(value, value1, Real01.EPSILON);
            }
        }