public void CompareTo()
        {
            //If you do int foo =  d_ninf.CompareTo(d_pinf); Assertion.Assert(".." foo < 0, true) this works.... WHY???
            Assert.IsTrue(d_ninf.CompareTo(d_pinf) < 0, "#A1");
            Assert.IsTrue(d_neg.CompareTo(d_pos) < 0, "#A2");
            Assert.IsTrue(d_nan.CompareTo(d_neg) < 0, "#A3");

            Assert.AreEqual(0, d_pos.CompareTo(d_pos2), "#B1");
            Assert.AreEqual(0, d_pinf.CompareTo(d_pinf), "#B2");
            Assert.AreEqual(0, d_ninf.CompareTo(d_ninf), "#B3");
            Assert.AreEqual(0, d_nan.CompareTo(d_nan), "#B4");

            Assert.IsTrue(d_pos.CompareTo(d_neg) > 0, "#C1");
            Assert.IsTrue(d_pos.CompareTo(d_nan) > 0, "#C2");
            Assert.IsTrue(d_pos.CompareTo(null) > 0, "#C3");

            try
            {
                d_pos.CompareTo(s);
                Assert.Fail("#D1");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual(typeof(ArgumentException), ex.GetType(), "#D2");
            }
        }
示例#2
0
      private Double getfreeitemdiscountamount(Item item, Double quantity)
      {
          Double discount = 0;

          while (Convert.ToInt32(quantity) > item.discount.buy)
          {
              if (quantity.CompareTo(Convert.ToDouble(item.discount.buy + item.discount.free)) > 0 ||
                  quantity.CompareTo(Convert.ToDouble(item.discount.buy + item.discount.free)) == 0)
              {
                  discount = discount + Convert.ToDouble(item.discount.free * item.price);
                  quantity = quantity - Convert.ToDouble(item.discount.buy + item.discount.free);
              }
          }
          return(discount);
      }
示例#3
0
 public void compareToFunction(Double length1, Double length2)
 {
     if (length1.CompareTo(length2) == 0)
     {
         Console.WriteLine("Both lines are equal");
     }
     else if (length1.CompareTo(length2) > 0)
     {
         Console.WriteLine("Line 1 is greater than Line 2");
     }
     else
     {
         Console.WriteLine("Line 2 is greater than Line 1");
     }
 }
示例#4
0
        public int Compare(object x, object y)
        {
            Double theX = (x != null && Double.TryParse(x.ToString(), out theX)) ? theX : Double.MaxValue;
            Double theY = (y != null && Double.TryParse(y.ToString(), out theY)) ? theY : Double.MaxValue;

            return(theX.CompareTo(theY));
        }
示例#5
0
        static void Main(string[] args)
        {
            // task 3
            Task.Run(async() =>
            {
                AnalysisResult task = await UploadAndAnalyzeImage("download.jpg");
                for (int i = 0; i < task.Tags.Length; ++i)
                {
                    Console.WriteLine("Name " + task.Tags[i].Name + "\nConfidence " + task.Tags[i].Confidence);
                }
            }).GetAwaiter().GetResult();

            // task 4
            string[] fileEntries = Directory.GetFiles("Images");
            String   target      = "Tagless";

            Directory.CreateDirectory(target);
            //File.Copy("download.jpg", target + "\\lel.jpg", true);
            foreach (string fileName in fileEntries)
            {
                Console.WriteLine(fileName);
                Task.Run(async() =>
                {
                    AnalysisResult task = await UploadAndAnalyzeImage(fileName);
                    if (task.Tags.Length == 0)
                    {
                        Console.WriteLine("No Tags");
                    }
                    else
                    {
                        Console.WriteLine("It has tags");
                    }
                    if (task.Tags.Length == 0)
                    {
                        String copy       = fileName;
                        String[] spliting = copy.Split(new char[] { '\\' });
                        File.Copy(fileName, target + "\\" + spliting[1], true);
                    }
                    else
                    {
                        Double maximum = task.Tags[0].Confidence;
                        int index      = 0;
                        for (int i = 0; i < task.Tags.Length; ++i)
                        {
                            if (maximum.CompareTo(task.Tags[i].Confidence) >= 0)
                            {
                                maximum = task.Tags[i].Confidence;
                                index   = i;
                            }
                        }
                        Console.WriteLine(task.Tags[index].Name + " " + index + " " + task.Tags[index].Confidence);
                        String folder_target = task.Tags[index].Name;
                        String copy          = fileName;
                        Directory.CreateDirectory(folder_target);
                        String[] spliting = copy.Split(new char[] { '\\' });
                        File.Copy(fileName, folder_target + "\\" + spliting[1], true);
                    }
                }).GetAwaiter().GetResult();
            }
        }
        private NominaPercepcionesJubilacionPensionRetiro createJubilacionRetiro(ConceptosJubilacion conceptosJubilacion, Double total, Double?montoDiario, Double ultSueldoMen)
        {
            NominaPercepcionesJubilacionPensionRetiro jubilacionPensionRetiro = new NominaPercepcionesJubilacionPensionRetiro();

            if (conceptosJubilacion == ConceptosJubilacion.TOTAL)
            {
                jubilacionPensionRetiro.TotalUnaExhibicion = (UtileriasSat.castNumerosToBigDecimal(total));
            }
            if (conceptosJubilacion == ConceptosJubilacion.PARCIAL)
            {
                jubilacionPensionRetiro.MontoDiario      = (UtileriasSat.castNumerosToBigDecimal(total));
                jubilacionPensionRetiro.TotalParcialidad = (UtileriasSat.castNumerosToBigDecimal(montoDiario));
            }
            if (ultSueldoMen.CompareTo(total) > 0)
            {
                jubilacionPensionRetiro.IngresoAcumulable = (UtileriasSat.castNumerosToBigDecimal(total));
            }
            else
            {
                jubilacionPensionRetiro.IngresoAcumulable = (UtileriasSat.castNumerosToBigDecimal(ultSueldoMen));
            }
            jubilacionPensionRetiro.IngresoNoAcumulable = (UtileriasSat.castNumerosToBigDecimal(total - ultSueldoMen));

            return(jubilacionPensionRetiro);
        }
示例#7
0
文件: Form1.cs 项目: Haurum/P2
        // Funktion der håndtere sorteringen i tabellen
        private void TableCustomSort(object sender, DataGridViewSortCompareEventArgs e)
        {
            // Pos er en int, Parser derfor til int
            if (e.Column == DataTable.Columns[0])
            {
                int a = int.Parse(e.CellValue1.ToString()), b = int.Parse(e.CellValue2.ToString());
                e.SortResult = a.CompareTo(b);
            }
            // Distance er en double. Sortere derfor som double
            else if (e.Column == DataTable.Columns[4] || e.Column == DataTable.Columns[5])
            {
                Double a = Double.Parse(e.CellValue1.ToString()), b = Double.Parse(e.CellValue2.ToString());
                e.SortResult = a.CompareTo(b);
            }
            // Hvis der kigges på et stræk, indholder DataTable.Columns[6] final position, der er en int.
            else if (e.Column == DataTable.Columns[6] && isLeg)
            {
                int a = int.Parse(e.CellValue1.ToString()), b = int.Parse(e.CellValue2.ToString());
                e.SortResult = a.CompareTo(b);
            }
            else
            {
                e.SortResult = e.CellValue1.ToString().CompareTo(e.CellValue2.ToString());
            }

            e.Handled = true;
        }
示例#8
0
 public int CompareTo(object other)
 {
     return(other is Fixed16_16?CompareTo(((Fixed16_16)other).Value) :
                other is uint?CompareTo((uint)other) :
                    other is float?CompareTo((float)other) :
                        Double.CompareTo(other));
 }
示例#9
0
    // 比较筹码数
    public static int CompareChips(string num1, string num2)
    {
        // Debug.Log("进入 Utils.cs文件 CompareChips方法,比较大小 " + num1 + " 和 " + num2);
        // 容错判断
        if (num1 == null || num2 == null)
        {
            Debug.Log("传递过来的比较参数不正确");
            return(0);
        }
        int    result  = 0; // 0代表相等,小于0代表小于,大于0代表大于
        UInt64 num1_64 = 0;
        UInt64 num2_64 = 0;

        if (UInt64.TryParse(num1, out num1_64) && UInt64.TryParse(num2, out num2_64))
        {
            // Debug.Log("成功,转换为UInt64类型," + num1 + " To " + num1_64 + ", " + num2 + " To " + num2_64);
            result = num1_64.CompareTo(num2_64);
        }
        else if (num1.Contains(".") || num2.Contains("."))
        {
            Double num1_double = 0;
            Double num2_double = 0;
            if (Double.TryParse(num1, out num1_double) && Double.TryParse(num2, out num2_double))
            {
                // Debug.Log("成功,转换为Double类型," + num1 + " To " + num1_double + ", " + num2 + " To " + num2_double);
                result = num1_double.CompareTo(num2_double);
            }
        }
        // Debug.Log("运算结果: " + result);
        return(result);
    }
示例#10
0
    private int GetLowerBound(List <double> thisList, Double thisValue)
    {
        var lower = 0;
        var upper = thisList.Count;
        var index = 0;

        while ((lower <= upper))
        {
            int comparisonResult = thisValue.CompareTo(thisList[index]);
            if (comparisonResult == 0)
            {
                return(index);
            }

            if (comparisonResult < 0)
            {
                upper = index - 1;
            }
            else
            {
                lower = index + 1;
            }
            index = (lower + upper) / 2;
        }
        return(lower);
    }
示例#11
0
        static void Main(string[] args)
        {
            //Task 3
            Task.Run(async() =>
            {
                AnalysisResult task = await UploadAndAnalyzeImage("9.png");
                for (int i = 0; i < task.Tags.Length; ++i)
                {
                    Console.WriteLine("Name " + task.Tags[i].Name + "\nConfidence " + task.Tags[i].Confidence);
                }
            }).GetAwaiter().GetResult();

            //Task 4
            string[] files = Directory.GetFiles(".");
            Directory.CreateDirectory("Tagless");
            foreach (string fileName in files)
            {
                Task.Run(async() =>
                {
                    AnalysisResult task = await UploadAndAnalyzeImage(fileName);
                    Console.WriteLine(fileName);
                    if (task.Tags.Length == 0)
                    {
                        Console.WriteLine("No Tags");
                    }
                    else
                    {
                        Console.WriteLine("It has tags");
                    }
                    if (task.Tags.Length == 0)
                    {
                        String copy    = fileName;
                        String[] split = copy.Split(new char[] { '\\' });
                        File.Copy(fileName, "Tagless" + "\\" + split[1], true);
                    }
                    else
                    {
                        Double max    = task.Tags[0].Confidence;
                        int max_index = 0;
                        for (int i = 0; i < task.Tags.Length; ++i)
                        {
                            if (max.CompareTo(task.Tags[i].Confidence) >= 0)
                            {
                                max       = task.Tags[i].Confidence;
                                max_index = i;
                            }
                        }
                        Console.WriteLine(task.Tags[max_index].Name + " " + max_index + " " + task.Tags[max_index].Confidence);
                        String new_folder = task.Tags[max_index].Name;
                        String copy       = fileName;
                        Directory.CreateDirectory(new_folder);
                        String[] split = copy.Split(new char[] { '\\' });
                        File.Copy(fileName, new_folder + "\\" + split[1], true);
                    }
                }).GetAwaiter().GetResult();
            }
        }
示例#12
0
 public new void Sort()
 {
     this.Sort(delegate(T x, T y)
     {
         Double sx = x.Priority;
         Double sy = y.Priority;
         return(sx.CompareTo(sy));
     });
     this.Reverse();
 }
示例#13
0
        /// <summary>
        /// Compare this value to the specified value.
        /// Ordering follows the natural order of the number of the instances.
        /// Instances of null value are ordered after those without null.
        /// </summary>
        /// <param name="v">Value to compare to. Non-null.</param>
        /// <returns>A negative integer, zero, or a positive integer as this object is less than,
        /// equal to, or greater than the specified object.</returns>
        public int CompareTo(Value v)
        {
            if (v == null)
            {
                throw new ArgumentNullException("v cannot be null.");
            }
            Double v1 = value.HasValue ? value.Value : Double.MaxValue;
            Double v2 = v.value.HasValue ? v.value.Value : Double.MaxValue;

            return(v1.CompareTo(v2));
        }
示例#14
0
        private static void TestCompare(Double a, Double b)
        {
            String di = a.CompareTo(b).ToString() + ' ' + b.CompareTo(a).ToString();

            BigNum na = a;
            BigNum nb = b;

            String ni = na.CompareTo(nb).ToString() + ' ' + nb.CompareTo(na).ToString();

            Console.WriteLine("{0,18} comp {1,18} = {2,18} : {3,18} -> {4}", a, b, di, ni, di == ni ? "Pass" : "Fail");
        }
示例#15
0
 public int CompareTo(AcceptType other)
 {
     if (_Quality == other._Quality)
     {
         return(_PlaceOfOccurence.CompareTo(other._PlaceOfOccurence));
     }
     else
     {
         return(_Quality.CompareTo(other._Quality) * -1);
     }
 }
示例#16
0
 public Int32 CompareTo(ItemAndPriority <T> other)
 {
     if (priority != other.priority)
     {
         return(priority.CompareTo(other.priority));
     }
     else
     {
         return(item.CompareTo(other.item));
     }
 }
示例#17
0
 public static int CompareTo([JsFakeThis] Double _this, object other)
 {
     if (other == null)
     {
         return(1);
     }
     if (!(other is Double))
     {
         throw new ArgumentException();
     }
     return(_this.CompareTo((Double)other));
 }
示例#18
0
        private void MethodTests()
        {
            featureTest.FailureMessage = "\tFailed Double Method Test";
            featureTest.Send("Double Method Test");
            Double value1 = 1;
            Double value2 = 2;
            Double value3 = 3;
            Object obj1   = value1;
            Object obj2   = value2;
            Object obj3   = value3;

            featureTest.AssertTrue(value2.CompareTo(value1) > 0);
            featureTest.AssertTrue(value2.CompareTo(value3) < 0);
            featureTest.AssertTrue(value2.CompareTo(value2) == 0);

            featureTest.AssertTrue(value2.CompareTo(obj1) > 0);
            featureTest.AssertTrue(value2.CompareTo(obj3) < 0);
            featureTest.AssertTrue(value2.CompareTo(obj2) == 0);

            featureTest.AssertTrue(!value2.Equals(value1));
            featureTest.AssertTrue(!value2.Equals(value3));
            featureTest.AssertTrue(value2.Equals(value2));

            featureTest.AssertTrue(!value2.Equals(obj1));
            featureTest.AssertTrue(!value2.Equals(obj3));
            featureTest.AssertTrue(value2.Equals(obj2));
            featureTest.AssertTrue(Double.Parse("33.0") == 33.0);
            String str = (35.3).ToString();

            featureTest.AssertTrue(str == "35.3");
            Double parsed;

            featureTest.AssertTrue(Double.TryParse(str, out parsed));
            featureTest.AssertTrue(parsed == 35.3);
            featureTest.AssertTrue(Double.IsFinite(3.0 / 1));
            featureTest.AssertTrue(!Double.IsInfinity(3.0 / 1));
            featureTest.AssertTrue(Double.IsInfinity(Double.PositiveInfinity));
            featureTest.AssertTrue(!Double.IsNaN(3.0 / 1));
            featureTest.AssertTrue(Double.IsNaN(Double.NaN));
            featureTest.AssertTrue(Double.IsNegativeInfinity(Double.NegativeInfinity));
            featureTest.AssertTrue(!Double.IsNegativeInfinity(Double.PositiveInfinity));
            featureTest.AssertTrue(!Double.IsNegativeInfinity(Double.NaN));
            featureTest.AssertTrue(!Double.IsPositiveInfinity(Double.NegativeInfinity));
            featureTest.AssertTrue(Double.IsPositiveInfinity(Double.PositiveInfinity));
            featureTest.AssertTrue(!Double.IsPositiveInfinity(Double.NaN));
#if V3
            featureTest.AssertTrue(Double.IsFinite(3.0 / 1));
            featureTest.AssertTrue(!Double.IsFinite(Double.NaN));
            featureTest.AssertTrue(Double.IsNegative(-3.0));
            featureTest.AssertTrue(!Double.IsNegative(3.0));
            featureTest.AssertTrue(Double.IsNegative(Double.NaN));
            featureTest.AssertTrue(Double.IsNormal(3.0));
            featureTest.AssertTrue(!Double.IsNormal(Double.PositiveInfinity));
            featureTest.AssertTrue(!Double.IsNormal(Double.NaN));
            featureTest.AssertTrue(Double.IsSubnormal(Double.Epsilon));
            featureTest.AssertTrue(Double.IsSubnormal(2.2250738585072009E-308));
            featureTest.AssertTrue(!Double.IsSubnormal(2.2250738585072014E-308));
#endif
        }
示例#19
0
            public Tuple <ISet <T>, ISet <T> > Partition(Tuple <T, T> promoted, ICollection <T> dataSet, DistanceMetric <T> distanceMetric)
            {
                List <T> queue1 = new List <T>(dataSet);

                queue1.Sort((data1, data2) =>
                {
                    Double distance1 = distanceMetric.Invoke(data1, promoted.Item1);
                    Double distance2 = distanceMetric.Invoke(data2, promoted.Item1);
                    return(distance1.CompareTo(distance2));
                });

                List <T> queue2 = new List <T>(dataSet);

                queue2.Sort((data1, data2) =>
                {
                    Double distance1 = distanceMetric.Invoke(data1, promoted.Item2);
                    Double distance2 = distanceMetric.Invoke(data2, promoted.Item2);
                    return(distance1.CompareTo(distance2));
                });

                ISet <T> first  = new HashSet <T>();
                ISet <T> second = new HashSet <T>();

                int index1 = 0;
                int index2 = 0;

                while (index1 < queue1.Count || index2 != queue2.Count)
                {
                    while (index1 < queue1.Count)
                    {
                        T data = queue1[index1++];
                        if (!second.Contains(data))
                        {
                            first.Add(data);
                            break;
                        }
                    }

                    while (index2 < queue2.Count)
                    {
                        T data = queue2[index2++];
                        if (!first.Contains(data))
                        {
                            second.Add(data);
                            break;
                        }
                    }
                }

                return(new Tuple <ISet <T>, ISet <T> >(first, second));
            }
示例#20
0
        /// <summary>
        /// 将对象的指定属性值和传入值进行比较
        /// </summary>
        /// <param name="data"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns>一个 32 位有符号整数,该整数指示此实例在排序顺序中是位于 value 参数之前、之后还是与其出现在同一位置。 值 Condition 小于零 此实例位于 value 之前。 零 此实例在排序顺序中的位置与 value 相同。 大于零 此实例位于 value 之后。 - 或 - value 为 null。</returns>
        public static int PropertiesCompareValue(this object data, string name, string value)
        {
            Type objType = data.GetType();

            PropertyInfo[] props = objType.GetProperties(bf);
            var            res   = 0;

            foreach (PropertyInfo item in props)
            {
                if (item.Name == name)
                {
                    var temp = item.GetValue(data);
                    switch (item.PropertyType.FullName)
                    {
                    case "System.String":
                        res = value.CompareTo(temp) * -1;
                        break;

                    case "System.Int32":
                        var intTemp = 0;
                        int.TryParse(value, out intTemp);
                        res = intTemp.CompareTo(temp) * -1;
                        break;

                    case "System.DateTime":
                        DateTime dateTemp = DateTime.Now;
                        DateTime.TryParse(value, out dateTemp);
                        res = dateTemp.CompareTo(temp) * -1;
                        break;

                    case "System.Single":
                        float fTemp = 0.0f;
                        float.TryParse(value, out fTemp);
                        res = fTemp.CompareTo(temp) * -1;
                        break;

                    case "System.Double":
                        Double dTemp = 0.0d;
                        Double.TryParse(value, out dTemp);
                        res = dTemp.CompareTo(temp) * -1;
                        break;

                    default:
                        var fName = item.PropertyType.FullName;
                        break;
                    }
                    //return value.CompareTo(temp) * -1;
                }
            }
            return(res);
        }
示例#21
0
    public static void TestCompareTo()
    {
        Double i = 234;

        Assert.Equal(0, i.CompareTo((Double)234));

        Assert.True(i.CompareTo(Double.MinValue) > 0);
        Assert.True(i.CompareTo((Double)0) > 0);
        Assert.True(i.CompareTo((Double)(-123)) > 0);
        Assert.True(i.CompareTo((Double)123) > 0);
        Assert.True(i.CompareTo((Double)456) < 0);
        Assert.True(i.CompareTo(Double.MaxValue) < 0);

        Assert.True(Double.NaN.CompareTo(Double.NaN) == 0);
        Assert.True(Double.NaN.CompareTo(0) < 0);
        Assert.True(i.CompareTo(Double.NaN) > 0);
    }
示例#22
0
        override public int Compare(int recordNo1, int recordNo2)
        {
            Double valueNo1 = values[recordNo1];
            Double valueNo2 = values[recordNo2];

            if (valueNo1 == defaultValue || valueNo2 == defaultValue)
            {
                int bitCheck = CompareBits(recordNo1, recordNo2);
                if (0 != bitCheck)
                {
                    return(bitCheck);
                }
            }
            return(valueNo1.CompareTo(valueNo2)); // not simple, checks Nan
        }
示例#23
0
        /// <summary>
        /// Compares the current length against the given one.
        /// </summary>
        /// <param name="other">The length to compare to.</param>
        /// <returns>The result of the comparison.</returns>
        public Int32 CompareTo(Length other)
        {
            if (_value != 0f || other._value != 0f)
            {
                if (_unit == other._unit)
                {
                    return(_value.CompareTo(other._value));
                }
                else if (IsAbsolute && other.IsAbsolute)
                {
                    return(ToPixel().CompareTo(other.ToPixel()));
                }
            }

            return(0);
        }
        /*finiquito*/
        private NominaPercepcionesSeparacionIndemnizacion createSeparacionIndemnizacion(Double totalSeparacionIndeminizacion, Double ultSueldoMes, int anioServ)
        {
            NominaPercepcionesSeparacionIndemnizacion separacionIndemnizacion = new NominaPercepcionesSeparacionIndemnizacion();

            separacionIndemnizacion.NumAñosServicio     = (anioServ);
            separacionIndemnizacion.TotalPagado         = (UtileriasSat.castNumerosToBigDecimal(totalSeparacionIndeminizacion));
            separacionIndemnizacion.UltimoSueldoMensOrd = (UtileriasSat.castNumerosToBigDecimal(ultSueldoMes));
            if (ultSueldoMes.CompareTo(totalSeparacionIndeminizacion) > 0)
            {
                separacionIndemnizacion.IngresoAcumulable = (UtileriasSat.castNumerosToBigDecimal(totalSeparacionIndeminizacion));
            }
            else
            {
                separacionIndemnizacion.IngresoAcumulable = (UtileriasSat.castNumerosToBigDecimal(ultSueldoMes));
            }
            separacionIndemnizacion.IngresoNoAcumulable = (UtileriasSat.castNumerosToBigDecimal(totalSeparacionIndeminizacion - ultSueldoMes));
            return(separacionIndemnizacion);
        }
示例#25
0
        public override int CompareValueTo(int recordNo, object value)
        {
            System.Diagnostics.Debug.Assert(0 <= recordNo, "Invalid record");
            System.Diagnostics.Debug.Assert(null != value, "null value");

            if (NullValue == value)
            {
                if (IsNull(recordNo))
                {
                    return(0);
                }
                return(1);
            }

            Double valueNo1 = values[recordNo];

            if ((defaultValue == valueNo1) && IsNull(recordNo))
            {
                return(-1);
            }
            return(valueNo1.CompareTo((Double)value));
        }
示例#26
0
    public static NumericRelationship Compare(ValueType value1, ValueType value2)
    {
        if (!IsNumeric(value1))
        {
            throw new ArgumentException("value1 is not a number.");
        }
        else if (!IsNumeric(value2))
        {
            throw new ArgumentException("value2 is not a number.");
        }

        // Use BigInteger as common integral type
        if (IsInteger(value1) && IsInteger(value2))
        {
            BigInteger bigint1 = (BigInteger)value1;
            BigInteger bigint2 = (BigInteger)value2;
            return((NumericRelationship)BigInteger.Compare(bigint1, bigint2));
        }
        // At least one value is floating point; use Double.
        else
        {
            Double dbl1 = 0;
            Double dbl2 = 0;
            try {
                dbl1 = Convert.ToDouble(value1);
            }
            catch (OverflowException) {
                Console.WriteLine("value1 is outside the range of a Double.");
            }
            try {
                dbl2 = Convert.ToDouble(value2);
            }
            catch (OverflowException) {
                Console.WriteLine("value2 is outside the range of a Double.");
            }
            return((NumericRelationship)dbl1.CompareTo(dbl2));
        }
    }
示例#27
0
    public bool PosTest8()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest8: Verify the result is NaN when radian is NaN.");

        try
        {
            Double d = Math.Sinh(Double.NaN);
            if (d.CompareTo(Double.NaN) != 0)
            {
                TestLibrary.TestFramework.LogError("P08.1", "The result is error when radian is NaN!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P08.2", "Unexpected exception occurs: " + e);
            retVal = false;
        }

        return(retVal);
    }
示例#28
0
    public bool PosTest4()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest4: Ensure the return value of CompareTo(System.Double) equal to zero when both this instance and value are NaN.");

        try
        {
            Double d1   = 0.0;
            long   myl1 = 0;
            myl1 = myl1 | 0x7ff0000000000001;
            byte[] mybytes1 = { 0, 0, 0, 0, 0, 0, 0, 0 };
            mybytes1 = BitConverter.GetBytes(myl1);
            d1       = BitConverter.ToDouble(mybytes1, 0);

            Double d2   = 0.0;
            long   myl2 = 0;
            myl2 = myl2 | 0x7ff0000000000002;
            byte[] mybytes2 = { 0, 0, 0, 0, 0, 0, 0, 0 };
            mybytes2 = BitConverter.GetBytes(myl2);
            d2       = BitConverter.ToDouble(mybytes2, 0);

            if (d1.CompareTo(d2) != 0)
            {
                TestLibrary.TestFramework.LogError("004.1", "The return value of CompareTo(System.Double) does not equal to zero when both this instance and value are NaN!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
示例#29
0
        /// <summary>
        /// IComparer{T}.Compare(T, T)
        /// </summary>
        public int Compare(string a, string b)
        {
            StringComparer sc = StringComparer.CurrentCultureIgnoreCase;

            if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b))
            {
                return(sc.Compare(a, b));
            }

            string numericX = this.Location == AlphaNumberSettings.Leading ? FindLeadingNumber(a) : FindTrailingNumber(a);
            string numericY = this.Location == AlphaNumberSettings.Leading ? FindLeadingNumber(b) : FindTrailingNumber(b);

            if (numericX != string.Empty && numericY != string.Empty)
            {
                if (this.Location == AlphaNumberSettings.Trailing)
                {
                    int stringPartCompareResult = sc.Compare(a.Remove(a.Length - numericX.Length), b.Remove(b.Length - numericY.Length));
                    if (stringPartCompareResult != 0)
                    {
                        return(stringPartCompareResult);
                    }

                    Double nX = Double.Parse(numericX);
                    Double nY = Double.Parse(numericY);
                    return(nX.CompareTo(nY));
                }
                else
                {
                    int numberPartCompareResult = Double.Parse(numericX).CompareTo(Double.Parse(numericY));
                    return(numberPartCompareResult != 0 ? numberPartCompareResult : sc.Compare(a, b));
                }
            }
            else
            {
                return(sc.Compare(a, b));
            }
        }
示例#30
0
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Ensure the result is correct when NumberStyles is set to AllowDecimalPoint.");

        try
        {
            Double d = Double.Parse("123.1", NumberStyles.AllowDecimalPoint, nfi);
            if (d.CompareTo(123.1) != 0)
            {
                TestLibrary.TestFramework.LogError("P02.1", "The result is not correct when NumberStyles is set to AllowDecimalPoint!");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("P02.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }