예제 #1
0
        public void TestAddMethodThrowsException()
        {
            var    rand   = new Random();
            ushort input1 = (ushort)rand.Next();
            ushort input2 = (ushort)rand.Next();

            ushort actual = Numeric <ushort> .Add(input1, input2);
        }
예제 #2
0
        public void TestAddMethod()
        {
            var rand   = new Random();
            var input1 = new Fake();
            var input2 = new Fake();

            var result = Numeric <Fake> .Add(input1, input2);

            Assert.IsTrue(result.FakeCalled);
        }
예제 #3
0
        public void TestAddMethod()
        {
            var rand     = new Random();
            int input1   = rand.Next();
            int input2   = rand.Next();
            int expected = input1 + input2;

            int actual = Numeric <int> .Add(input1, input2);

            Assert.AreEqual(expected, actual);
        }
예제 #4
0
        public void TestAddMethod()
        {
            var    rand     = new Random();
            double input1   = rand.Next();
            double input2   = rand.Next();
            double expected = input1 + input2;

            double actual = Numeric <double> .Add(input1, input2);

            Assert.AreEqual(expected, actual);
        }
예제 #5
0
        public void TestAddMethod()
        {
            var   rand     = new Random();
            ulong input1   = (ulong)rand.Next();
            ulong input2   = (ulong)rand.Next();
            ulong expected = input1 + input2;

            ulong actual = Numeric <ulong> .Add(input1, input2);

            Assert.AreEqual(expected, actual);
        }
예제 #6
0
        /// <summary>
        /// Create a canonical representation for the addition of two scalars.
        /// </summary>
        /// <remarks>
        /// 0 + y => y
        /// x + 0 => x
        /// x + x => 2 * x
        /// x + b => b + x
        /// a + b => c
        /// a + (b + y) => (a + b) + y
        /// -x +  y =>   y - x
        ///  x + -y =>   x - y
        /// -x + -y => -(x + y)
        /// </remarks>
        public static Scalar <Type> Create(Scalar <Type> x, Scalar <Type> y)
        {
            // 0 + y => y
            if (x.IsZero)
            {
                return(y);
            }
            // x + 0 => x
            if (y.IsZero)
            {
                return(x);
            }
            // x + x => 2 * x
            if (x == y)
            {
                return(Numeric <Type> .Two * x);
            }

            if (y is Const cy)
            {
                if (x is Const cx)
                {
                    // a + b => c
                    return(Numeric.Add(cx.Value, cy.Value));
                }
                else
                {
                    // x + b => b + x
                    return(Create(y, x));
                }
            }

            // a + (b + y) => (a + b) + y
            if (y is Add <Type> add)
            {
                return((x + add.x) + add.y);
            }

            // -x +  y =>   y - x
            // (-x) + (-y) => (-y) - x => -(x + y)
            if (x is Neg <Type> negx)
            {
                return(y - negx.x);
            }
            //  x + -y =>   x - y
            if (y is Neg <Type> negy)
            {
                return(x - negy.x);
            }

            return(new Add <Type>(x, y));
        }
예제 #7
0
파일: ToolsTest.cs 프로젝트: S031/MetaStack
 public void numericTest()
 {
     using (FileLog l = new FileLog("NumericTest", new FileLogSettings()
     {
         DateFolderMask = "yyyy-MM-dd"
     }))
     {
         l.Write(LogLevels.Debug, "NumericTest Start");
         decimal d = 987456123.97m;
         l.Write(LogLevels.Debug, "decimal d = ", d.ToString());
         l.Write(LogLevels.Debug, "Numeric.AsString(100, \"\", false)", Numeric.AsString(100, "", false));
         Assert.IsTrue(Numeric.AsString(100, "", false).Trim() == "Сто");
         l.Write(LogLevels.Debug, "Numeric.AsString(d, \"RUR\", true)", Numeric.AsString(d, "RUR", true));
         Assert.IsTrue(Numeric.AsString(d, "RUR", true).Trim() == "Девятьсот восемьдесят семь миллионов четыреста пятьдесят шесть тысяч сто двадцать три рубля 97 копеек");
         Numeric.Add("KG", new string[7] {
             "килограмм", "килограмма", "килограмм", "сотая килограмма", "сотых килограмма", "сотых килограмма", "M"
         });
         l.Write(LogLevels.Debug, "Numeric.AsString(d, \"KG\", true)", Numeric.AsString(d, "KG", true));
         Assert.IsTrue(Numeric.AsString(d, "KG", true).Trim() == "Девятьсот восемьдесят семь миллионов четыреста пятьдесят шесть тысяч сто двадцать три килограмма 97 сотых килограмма");
         l.Write(LogLevels.Debug, "Numeric.AsString(d - 2, \"KG\", true)", Numeric.AsString(d - 2, "KG", true));
         Assert.IsTrue(Numeric.AsString(d - 2, "KG", false).Trim() == "Девятьсот восемьдесят семь миллионов четыреста пятьдесят шесть тысяч сто двадцать один килограмм");
         l.Write(LogLevels.Debug, "NumericTest Finish");
     }
 }