Exemple #1
0
        [TestMethod] public void ToDecimalTest()
        {
            var m = GetRandom.Decimal();
            var d = GetRandom.Double(Convert.ToSingle(decimal.MinValue),
                                     Convert.ToSingle(decimal.MaxValue));
            var f = GetRandom.Float(Convert.ToSingle(decimal.MinValue),
                                    Convert.ToSingle(decimal.MaxValue));
            var l  = GetRandom.Int64();
            var i  = GetRandom.Int32();
            var s  = GetRandom.Int16();
            var b  = GetRandom.Int8();
            var ul = GetRandom.UInt64();
            var ui = GetRandom.UInt32();
            var us = GetRandom.UInt16();
            var ub = GetRandom.UInt8();

            Assert.AreEqual(m, Decimals.ToDecimal(m));
            Assert.AreEqual(Convert.ToDecimal(d), Decimals.ToDecimal(d));
            Assert.AreEqual(Convert.ToDecimal(f), Decimals.ToDecimal(f));
            Assert.AreEqual(Convert.ToDecimal(l), Decimals.ToDecimal(l));
            Assert.AreEqual(Convert.ToDecimal(i), Decimals.ToDecimal(i));
            Assert.AreEqual(Convert.ToDecimal(s), Decimals.ToDecimal(s));
            Assert.AreEqual(Convert.ToDecimal(b), Decimals.ToDecimal(b));
            Assert.AreEqual(Convert.ToDecimal(ul), Decimals.ToDecimal(ul));
            Assert.AreEqual(Convert.ToDecimal(ui), Decimals.ToDecimal(ui));
            Assert.AreEqual(Convert.ToDecimal(us), Decimals.ToDecimal(us));
            Assert.AreEqual(Convert.ToDecimal(ub), Decimals.ToDecimal(ub));
            Assert.AreEqual(1.2345M, Decimals.ToDecimal("1.2345"));
            Assert.AreEqual(1.2345M, Decimals.ToDecimal(1.2345D));
            Assert.AreEqual(1.2345M, Decimals.ToDecimal(1.2345F));
        }
Exemple #2
0
 [TestMethod] public void ReciprocalTest()
 {
     Assert.AreEqual(1 / d1, Decimals.Reciprocal(d1));
     Assert.AreEqual(0, Decimals.Reciprocal(decimal.MaxValue));
     Assert.AreEqual(0, Decimals.Reciprocal(decimal.MinValue));
     Assert.AreEqual(decimal.MaxValue, Decimals.Reciprocal(decimal.Zero));
 }
Exemple #3
0
 public override Int32 GetHashCode()
 {
     return((ColumnName ?? "").ToLower().GetHashCode() ^
            DataType.GetHashCode() ^
            Length.GetHashCode() ^
            Decimals.GetHashCode());
 }
        public string ToNumericString()
        {
            var builder = new StringBuilder();

            Integers = Integers.TrimStart(Constants.ZeroCharacter);
            Decimals = Decimals.TrimEnd(Constants.ZeroCharacter);

            if (Digits.Length > 0)
            {
                if (IsNegative)
                {
                    builder.Append(Constants.NegationCharacter);
                }

                builder.Append(Integers);

                if (HasDecimal)
                {
                    builder.Append(Constants.DecimalCharacter);
                    builder.Append(Decimals);
                }
            }
            else
            {
                builder.Append(Constants.ZeroCharacter);
            }

            return(builder.ToString());
        }
Exemple #5
0
 [TestMethod] public void IsEqualTest()
 {
     Assert.IsTrue(Decimals.IsEqual(decimal.MinValue, decimal.MinValue));
     Assert.IsTrue(Decimals.IsEqual(decimal.MaxValue, decimal.MaxValue));
     Assert.IsTrue(Decimals.IsEqual(d1, d1));
     Assert.IsFalse(Decimals.IsEqual(d1, d2));
 }
Exemple #6
0
        public void AddTest()
        {
            var expected = new Decimals(4);
            var actual   = x + y;

            Assert.AreEqual(expected, actual);
        }
Exemple #7
0
        public void CreateDecimalsTest()
        {
            var decimals = new Decimals(1.25);

            Assert.NotNull(decimals);
            Assert.AreEqual(1.25, decimals.Dec_num);
        }
Exemple #8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Value1,Value2,Value3,ProductDecimals,SumDecimals")] Decimals decimals)
        {
            if (id != decimals.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(decimals);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DecimalsExists(decimals.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(decimals));
        }
Exemple #9
0
 [TestMethod] public void MultiplyTest()
 {
     Assert.AreEqual(decimal.Zero, Decimals.Multiply(decimal.Zero, d1));
     Assert.AreEqual(decimal.Zero, Decimals.Multiply(d1, decimal.Zero));
     Assert.AreEqual(decimal.MaxValue, Decimals.Multiply(d1, decimal.MaxValue));
     Assert.AreEqual(decimal.MaxValue, Decimals.Multiply(d1, decimal.MinValue));
     Assert.AreEqual(d1 * 0.12345M, Decimals.Multiply(d1, 0.12345M));
 }
Exemple #10
0
 [TestMethod] public void IsLessTest()
 {
     Assert.IsTrue(Decimals.IsLess(decimal.MinValue, decimal.MaxValue));
     Assert.IsTrue(Decimals.IsLess(d1, decimal.MaxValue));
     Assert.IsTrue(Decimals.IsLess(decimal.MinValue, Decimals.Add(decimal.MinValue, 1)));
     Assert.IsTrue(Decimals.IsLess(Decimals.Add(decimal.MinValue, 1), d1));
     Assert.IsFalse(Decimals.IsLess(d1, Decimals.Add(decimal.MinValue, 1)));
     Assert.IsFalse(Decimals.IsLess(d1, d1));
 }
Exemple #11
0
 [TestMethod] public void IsGreaterTest()
 {
     Assert.IsTrue(Decimals.IsGreater(decimal.MaxValue, decimal.MinValue));
     Assert.IsTrue(Decimals.IsGreater(decimal.MaxValue, d1));
     Assert.IsTrue(Decimals.IsGreater(Decimals.Add(decimal.MinValue, 1), decimal.MinValue));
     Assert.IsTrue(Decimals.IsGreater(Decimals.Add(d1, 1), d1));
     Assert.IsFalse(Decimals.IsGreater(decimal.MinValue, d1));
     Assert.IsFalse(Decimals.IsGreater(d1, d1));
 }
Exemple #12
0
 [TestMethod] public void SubtractTest()
 {
     Assert.AreEqual(d1 - d2, Decimals.Subtract(d1, d2));
     Assert.AreEqual(0, Decimals.Subtract(d1, d1));
     Assert.AreEqual(0, Decimals.Subtract(decimal.MaxValue, decimal.MaxValue));
     Assert.AreEqual(0, Decimals.Subtract(decimal.MinValue, decimal.MinValue));
     Assert.AreEqual(decimal.MaxValue,
                     Decimals.Subtract(decimal.MinValue, decimal.MaxValue));
     Assert.AreEqual(decimal.MaxValue,
                     Decimals.Subtract(decimal.MaxValue, decimal.MinValue));
 }
Exemple #13
0
        public async Task <IActionResult> Create([Bind("Id,Value1,Value2,Value3,ProductDecimals,SumDecimals")] Decimals decimals)
        {
            if (ModelState.IsValid)
            {
                _context.Add(decimals);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(decimals));
        }
Exemple #14
0
 public int InsertDecimals(Decimals pDecimals)
 {
     try
     {
         return(_AD.InsertDecimals(pDecimals));
     }
     catch (Exception ex)
     {
         throw;
     }
 }
 public void WriteXmlSubtree(XmlWriter writer)
 {
     writer.WriteStartElement(XmlStrings.DoublesGen);
     writer.WriteAttributeString(XmlStrings.NameAttr, Name);
     writer.WriteStartElement(XmlStrings.ParamsNode);
     writer.WriteAttributeString("min", Min.ToString());
     writer.WriteAttributeString("max", Max.ToString());
     writer.WriteAttributeString("decimals", Decimals.ToString());
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
Exemple #16
0
        [TestMethod] public void SquareTest()
        {
            void test(decimal x)
            {
                Assert.AreEqual(Decimals.Multiply(x, x), Decimals.Square(x));
            }

            test(d1);
            test(d2);
            test(decimal.MinValue);
            test(decimal.MaxValue);
        }
Exemple #17
0
 public bool UpdateDecimals(Decimals pDecimals)
 {
     try
     {
         _AD.UpdateDecimals(pDecimals);
         return(true);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemple #18
0
        public RenkoFeed(double brickPips, Decimals decimals)
        {
            if ((brickPips < 0.1) || (brickPips > 99.9) ||
                (brickPips != Math.Round(brickPips, 1)))
            {
                throw new ArgumentOutOfRangeException(nameof(brickPips));
            }

            brickTicks = brickPips.PipsToRate(decimals);

            this.decimals = decimals;
        }
Exemple #19
0
        public static int GetDecimals(this Currency currency)
        {
            if (Decimals.TryGetValue(currency.Id, out var result))
            {
                return(result);
            }

            // The reason we return 8 is since this value will usually be used for rounding, and
            // since Litium stores prices with 8 decimals in the database, it's a reasonable default.
            // Although this should technically rarely happen unless someone uses a currency not included
            // in ISO-4217, such as Bitcoin.
            return(8);
        }
Exemple #20
0
        [TestMethod] public void ToStringTest()
        {
            void action(decimal x)
            {
                Assert.AreEqual(x.ToString(UseCulture.Invariant), Decimals.ToString(x));
            }

            action(GetRandom.Decimal());
            action(1234.567m);
            action(1234567m);
            action(123456.7m);
            Assert.AreEqual(d1.ToString(UseCulture.English), Decimals.ToString(d1));
        }
 public void Test2()
 {
     testDates = new string[3]
     {
         "-30", "-50", "0"
     };
     inputProcessing   = new InputProcessing(new InputTest(testDates), null);
     quadraticEquation = new QuadraticEquation(inputProcessing.GetData());
     testSolution      = new string[2]
     {
         "-1.66", "0"
     };
     Assert.AreEqual(Decimals.Round(quadraticEquation.SolveWithRealSolutions(), 2), testSolution);
 }
Exemple #22
0
        internal static ILayout GetLayout(string dataType, Config config, FieldConfig fieldConfig)
        {
            string vtype = string.Empty;

            if (Shorts.Contains(dataType) || Integers.Contains(dataType) || Longs.Contains(dataType))
            {
                vtype = "int";

                if (dataType.EndsWith("_strict"))
                {
                    vtype = "int-strict";
                }
                if (dataType.EndsWith("_strict2"))
                {
                    vtype = "int-strict2";
                }

                return(new TextBox(config, fieldConfig, vtype));
            }

            if (Decimals.Contains(dataType))
            {
                vtype = "dec";

                if (dataType.EndsWith("_strict"))
                {
                    vtype = "dec-strict";
                }
                if (dataType.EndsWith("_strict2"))
                {
                    vtype = "dec-strict2";
                }

                return(new TextBox(config, fieldConfig, vtype));
            }

            if (Bools.Contains(dataType))
            {
                return(new Radios(config, fieldConfig));
            }

            if (Dates.Contains(dataType))
            {
                return(new TextBox(config, fieldConfig, "date"));
            }

            return(Files.Contains(dataType)
                ? new TextBox(config, fieldConfig, "file")
                : new TextBox(config, fieldConfig));
        }
Exemple #23
0
        public bool Equals(Fact other)
        {
            var result = other != null &&
                         Value.Equals(other.Value, StringComparison.Ordinal) &&
                         Metric.Equals(other.Metric) &&
                         Decimals.Equals(other.Decimals, StringComparison.Ordinal);

            if (result)
            {
                result = Unit == null
                                        ? other.Unit == null
                                        : Unit.Equals(other.Unit);
            }
            return(result);
        }
Exemple #24
0
        [TestMethod] public void TryParseTest()
        {
            void action(decimal x, string s)
            {
                Assert.IsTrue(Decimals.TryParse(s, out var y));
                Assert.AreEqual(x, y);
            }

            var d = GetRandom.Decimal();

            action(d, d.ToString(UseCulture.Invariant));
            action(1234.567m, "1234.567");
            action(1234567m, "1234,567");
            action(123456.7m, "1234,56.7");
        }
Exemple #25
0
        public int InsertDecimals(Decimals pDecimals)
        {
            string sql = @"[spInsertDecimals] '{0}', '{1}', '{2}', '{3}', '{4}'";

            sql = string.Format(sql, pDecimals.Description, pDecimals.Value.ToString().Replace(',', '.'), pDecimals.Status.Id,
                                pDecimals.CreatorUser, pDecimals.ModificationUser);
            try
            {
                return(_MB.EjecutarSQL(_CN, sql));
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Exemple #26
0
        public void UpdateDecimals(Decimals pDecimals)
        {
            string sql = @"[spUpdateDecimals] '{0}', '{1}', '{2}', '{3}', '{4}'";

            sql = string.Format(sql, pDecimals.Id, pDecimals.Description, pDecimals.Value.ToString().Replace(',', '.'), pDecimals.Status.Id,
                                pDecimals.ModificationUser);
            try
            {
                _MB.EjecutarSQL(_CN, sql);
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Exemple #27
0
        [TestMethod] public void AddTest()
        {
            Assert.AreEqual(d1 + d2, Decimals.Add(d1, d2));
            Assert.AreEqual(0, Decimals.Add(-d1, d1));
            Assert.AreEqual(0, Decimals.Add(decimal.MinValue, decimal.MaxValue));
            Assert.AreEqual(decimal.MaxValue, Decimals.Add(decimal.MaxValue, decimal.MaxValue));
            Assert.AreEqual(decimal.MaxValue, Decimals.Add(decimal.MinValue, decimal.MinValue));
            var absRandomDecimal = Math.Abs(d1);

            Assert.AreEqual(decimal.MaxValue, Decimals.Add(decimal.MaxValue, absRandomDecimal));
            Assert.AreEqual(decimal.MaxValue - absRandomDecimal,
                            Decimals.Add(decimal.MaxValue, -absRandomDecimal));
            Assert.AreEqual(decimal.MinValue + absRandomDecimal,
                            Decimals.Add(decimal.MinValue, absRandomDecimal));
            Assert.AreEqual(decimal.MaxValue, Decimals.Add(decimal.MinValue, -absRandomDecimal));
        }
        /// <summary>
        /// Initializes this instance, registers all Integers and Doubles
        /// </summary>
        protected void Init()
        {
            var t = GetType();

            if (MetricsExtensions.CachedMetricsDefinitions.ContainsKey(t.FullName))
            {
                MetricsExtensions.CachedMetricsDefinitions[t.FullName].SetTo(this);
                return;
            }



            PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            props = props.ToList().OrderBy(x => x.Name).ToArray();

            foreach (var p in props)
            {
                if (p.hasAttribute(imbAttributeName.measure_excludeFromMetrics))
                {
                    IgnoreComputations.Add(p);
                    IgnoreComputationsDict.Add(p.Name, p);
                    continue;
                }

                if (p.GetIndexParameters().Length == 0)
                {
                    if (p.PropertyType == typeof(Int32))
                    {
                        Integers.Add(p);
                        IntegersDict.Add(p.Name, p);
                    }
                    else if (p.PropertyType == typeof(Double))
                    {
                        Doubles.Add(p);
                        DoublesDict.Add(p.Name, p);
                    }
                    else if (p.PropertyType == typeof(Decimal))
                    {
                        Decimals.Add(p);
                        DecimalsDict.Add(p.Name, p);
                    }
                }
            }

            MetricsExtensions.StoreMetricsDefinition(this);
        }
Exemple #29
0
        public void DivTest()
        {
            var  divByZero          = new Decimals(0);
            bool triggeredException = false;

            try
            {
                double result = x / divByZero;
            }
            catch (DivideByZeroException e)
            {
                triggeredException = true;
            }
            Assert.True(triggeredException);
            Assert.AreEqual(2.2d, (double)(x / y));
            //Assert.That(2.2, Is.EqualTo(x / y).Within(10).Percent);
        }
Exemple #30
0
        public Decimals GetDecimalsById(int Id)
        {
            Decimals Decimals = new Decimals();
            string   sql      = @"[spGetDecimals] '{0}' ";

            sql = string.Format(sql, Id);

            try
            {
                DataSet ds = new DataSet();
                ds = _MB.CreaDS(ds, "Decimals", sql, _CN);
                if (ds.Tables["Decimals"].Rows.Count > 0)
                {
                    foreach (DataRow item in ds.Tables["Decimals"].Rows)
                    {
                        Decimals = new Decimals()
                        {
                            Id          = int.Parse(item["Id"].ToString()),
                            Description = item["Description"].ToString(),
                            Value       = decimal.Parse(item["Value"].ToString()),
                            Status      = new Status()
                            {
                                Id = int.Parse(item["IdStatus"].ToString()), Description = item["DescripStatus"].ToString()
                            },
                            CreationDate     = (item["CreationDate"].ToString() != "") ? DateTime.Parse(item["CreationDate"].ToString()) : DateTime.Parse("01/01/1900"),
                            ModificationDate = (item["ModificationDate"].ToString() != "") ? DateTime.Parse(item["ModificationDate"].ToString()) : DateTime.Parse("01/01/1900"),
                            CreatorUser      = int.Parse(item["CreatorUser"].ToString()),
                            ModificationUser = int.Parse(item["ModificationUser"].ToString()),
                        };
                    }
                }
                return(Decimals);
            }
            catch (Exception)
            {
                throw;
            }
        }