Beispiel #1
0
        private void Run_Divide_Float_Int(Random r)
        {
            var a = (float)(r.NextDouble() * r.Next(-1000, 1000));

            a = float.Parse(a.ToString("f5"));
            var b = r.Next(-1000, 1000);

            if (b == 0)
            {
                b = 1;
            }
            var result = a / b;

            LoopBase(() => result = a / b);

            var fa      = FloatHelper.ToFraction(a);
            var fb      = new Fraction(b);
            var fresult = fa / fb;

            LoopFixed(() => fresult = fa / fb);

            if (!FloatHelper.Approximately(fresult.ToFloat(), result))
            {
                throw new InvalidOperationException();
            }
        }
Beispiel #2
0
        private void Run_Subtract_Float_Int(Random r)
        {
            var a      = (float)(r.NextDouble() * r.Next(-10000, 10000));
            var b      = r.Next(-10000, 10000);
            var result = a - b;

            LoopBase(() => result = a - b);

            var fa      = FloatHelper.ToFraction(a);
            var fb      = new Fraction(b);
            var fresult = fa - fb;

            LoopFixed(() => fresult = fa - fb);

            if (!FloatHelper.Approximately(fresult.ToFloat(), result))
            {
                throw new InvalidOperationException();
            }
        }
Beispiel #3
0
        private void Run_Compare_Float_Float(Random r)
        {
            var a = (float)(r.NextDouble() * r.Next(-10000, 1000000));

            a = float.Parse(a.ToString("f5"));
            var b = (float)(r.NextDouble() * r.Next(-10000, 1000000));

            b = float.Parse(b.ToString("f5"));
            var result = a.CompareTo(b);

            LoopBase(() => result = a.CompareTo(b));

            var fa      = FloatHelper.ToFraction(a);
            var fb      = b.ToFraction();
            var fresult = fa.CompareTo(fb);

            LoopFixed(() => fresult = fa.CompareTo(fb));

            if (result != fresult)
            {
                throw new InvalidOperationException();
            }
        }
Beispiel #4
0
        private void Run_Multiply_Float_Float(Random r)
        {
            var a = (float)(r.NextDouble() * r.Next(-1000, 1000));

            a = float.Parse(a.ToString("f5"));
            var b = (float)(r.NextDouble() * r.Next(-1000, 1000));

            b = float.Parse(b.ToString("f5"));
            var result = a * b;

            LoopBase(() => result = a * b);

            var fa      = FloatHelper.ToFraction(a);
            var fb      = b.ToFraction();
            var fresult = fa * fb;

            LoopFixed(() => fresult = fa * fb);

            if (!FloatHelper.Approximately(fresult.ToFloat(), result))
            {
                throw new InvalidOperationException();
            }
        }