Exemplo n.º 1
0
        public void CompareTo_Other_ReturnsExpected(sbyte i, object value, int expected)
        {
            if (value is sbyte sbyteValue)
            {
                Assert.Equal(expected, Math.Sign(i.CompareTo(sbyteValue)));
            }

            Assert.Equal(expected, Math.Sign(i.CompareTo(value)));
        }
Exemplo n.º 2
0
    public int Compare(bool leftExists, ReadOnlySpan <byte> left, bool rightExists, ReadOnlySpan <byte> right)
    {
        sbyte leftValue  = leftExists ? ScalarSpanReader.ReadSByte(left) : this.defaultValue;
        sbyte rightValue = rightExists ? ScalarSpanReader.ReadSByte(right) : this.defaultValue;

        return(leftValue.CompareTo(rightValue));
    }
Exemplo n.º 3
0
    public static void TestCompareTo(sbyte value, int expected)
    {
        sbyte i      = 114;
        int   result = CompareHelper.NormalizeCompare(i.CompareTo(value));

        Assert.Equal(expected, result);
    }
Exemplo n.º 4
0
        public int CompareTo(StringIdent other)
        {
            var indexComparison = Index.CompareTo(other.Index);

            return(indexComparison == 0 ? Length.CompareTo(other.Length) : indexComparison);

            ;
        }
Exemplo n.º 5
0
        public int CompareTo(Position other)
        {
            if (X == other.X)
            {
                return(Y.CompareTo(other.Y));
            }

            return(X.CompareTo(other.X));
        }
Exemplo n.º 6
0
        public static void CompareTo(sbyte i, object value, int expected)
        {
            if (value is sbyte)
            {
                Assert.Equal(expected, Math.Sign(i.CompareTo((sbyte)value)));
            }

            IComparable comparable = i;

            Assert.Equal(expected, Math.Sign(comparable.CompareTo(value)));
        }
Exemplo n.º 7
0
        public int CompareTo(GeoHash o)
        {
            int bitsCmp = (m_bits ^ FIRST_BIT_FLAGGED).CompareTo(o.m_bits ^ FIRST_BIT_FLAGGED);

            if (bitsCmp != 0)
            {
                return(bitsCmp);
            }
            else
            {
                return(m_significantBits.CompareTo(o.m_significantBits));
            }
        }
Exemplo n.º 8
0
        public override int Compare(int recordNo1, int recordNo2)
        {
            sbyte num3 = this.values[recordNo1];
            sbyte num2 = this.values[recordNo2];

            if (num3.Equals((sbyte)0) || num2.Equals((sbyte)0))
            {
                int num = base.CompareBits(recordNo1, recordNo2);
                if (num != 0)
                {
                    return(num);
                }
            }
            return(num3.CompareTo(num2));
        }
Exemplo n.º 9
0
        public override int Compare(int recordNo1, int recordNo2)
        {
            sbyte valueNo1 = _values[recordNo1];
            sbyte valueNo2 = _values[recordNo2];

            if (valueNo1.Equals(defaultValue) || valueNo2.Equals(defaultValue))
            {
                int bitCheck = CompareBits(recordNo1, recordNo2);
                if (0 != bitCheck)
                {
                    return(bitCheck);
                }
            }
            return(valueNo1.CompareTo(valueNo2));
            //return(valueNo1 - valueNo2); // copied from SByte.CompareTo(SByte)
        }
Exemplo n.º 10
0
        public override int CompareValueTo(int recordNo, object value)
        {
            if (base.NullValue == value)
            {
                if (this.IsNull(recordNo))
                {
                    return(0);
                }
                return(1);
            }
            sbyte num = this.values[recordNo];

            if ((num == 0) && this.IsNull(recordNo))
            {
                return(-1);
            }
            return(num.CompareTo((sbyte)value));
        }
Exemplo n.º 11
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);
            }

            sbyte valueNo1 = _values[recordNo];

            if ((defaultValue == valueNo1) && IsNull(recordNo))
            {
                return(-1);
            }
            return(valueNo1.CompareTo((sbyte)value));
            //return(valueNo1 - valueNo2); // copied from SByte.CompareTo(SByte)
        }
Exemplo n.º 12
0
    public bool PosTest3()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest3: The sbyte compared to is equal to the source");
        try
        {
            int   intA       = this.GetInt32(0, 127) + this.GetInt32(0, 128) * (-1);
            sbyte desByte    = (sbyte)intA;
            sbyte sourceByte = (sbyte)intA;
            int   retInt     = sourceByte.CompareTo(desByte);
            if (retInt != 0)
            {
                TestLibrary.TestFramework.LogError("005", "the ExpectResult is not the ActualResult");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("006", "Unexpect exception:" + e);
            retVal = false;
        }
        return(retVal);
    }
Exemplo n.º 13
0
                public override int Compare(Action x, Action y)
                {
                    if (x.type != y.type)
                    {
                        byte xPriority = typePriorities[x.type];
                        byte yPriority = typePriorities[y.type];

                        return(xPriority.CompareTo(yPriority));
                    }
                    else if (x.type == Type.Fight) //If both trying to fight
                    {
                        sbyte xMovePriority = Pokemon.Moves.PokemonMove.GetPokemonMoveById(x.user.ActivePokemon.moveIds[x.fightMoveIndex]).movePriority switch
                        {
                            true => 1,
                            null => 0,
                            false => - 1
                        };
                        sbyte yMovePriority = Pokemon.Moves.PokemonMove.GetPokemonMoveById(y.user.ActivePokemon.moveIds[y.fightMoveIndex]).movePriority switch
                        {
                            true => 1,
                            null => 0,
                            false => - 1
                        };

                        if (xMovePriority == yMovePriority)
                        {
                            if (battleData != null && battleData.stageModifiers.trickRoomRemainingTurns > 0)
                            {
                                return(y.user.ActivePokemon.GetBattleStats().speed.CompareTo(x.user.ActivePokemon.GetBattleStats().speed)); //Reverse speed comparison
                            }
                            else
                            {
                                return(x.user.ActivePokemon.GetBattleStats().speed.CompareTo(y.user.ActivePokemon.GetBattleStats().speed)); //Normal speed comparison
                            }
                        }
                        else
                        {
                            return(xMovePriority.CompareTo(yMovePriority));
                        }
                    }
                    else if (x.type == Type.Flee)
                    {
                        return(0);
                    }
                    else if (x.type == Type.SwitchPokemon)
                    {
                        return(0);
                    }
                    else if (x.type == Type.UseItem)
                    {
                        if (x.useItemItemToUse is PokeBall && y.useItemItemToUse is PokeBall)
                        {
                            Debug.LogError("Two participants trying to use poke ball");
                            return(0);
                        }
                        else if (x.useItemItemToUse is PokeBall)
                        {
                            return(1);
                        }
                        else if (y.useItemItemToUse is PokeBall)
                        {
                            return(-1);
                        }
                        else
                        {
                            return(0);
                        }
                    }
                    else
                    {
                        Debug.LogError("Action type hasn't been prepared for when comparing action priorities");
                        return(0);
                    }
                }
Exemplo n.º 14
0
 public int CompareTo(Fix8 other)
 {
     return(m_rawValue.CompareTo(other.m_rawValue));
 }
        private int SortEnumFields(IMemberDefinition first, IMemberDefinition second)
        {
            FieldDefinition firstField  = first as FieldDefinition;
            FieldDefinition secondField = second as FieldDefinition;

            if (firstField == null || firstField.Constant == null || firstField.Constant.Value == null)
            {
                return(1);
            }
            if (secondField == null || secondField.Constant == null || secondField.Constant.Value == null)
            {
                return(-1);
            }
            //return firstField.Constant.ToString().CompareTo(secondField.Constant.ToString());
            int valuesCompared = 0;

            if (firstField.Constant.Value.GetType().Name == "Int32")
            {
                int firstFieldValue  = (int)firstField.Constant.Value;
                int secondFieldValue = (int)secondField.Constant.Value;

                valuesCompared = firstFieldValue.CompareTo(secondFieldValue);
            }
            if (firstField.Constant.Value.GetType().Name == "UInt32")
            {
                uint firstFieldValue  = (uint)firstField.Constant.Value;
                uint secondFieldValue = (uint)secondField.Constant.Value;
                valuesCompared = firstFieldValue.CompareTo(secondFieldValue);
            }
            else if (firstField.Constant.Value.GetType().Name == "Int16")
            {
                short firstFieldValue  = (short)firstField.Constant.Value;
                short secondFieldValue = (short)secondField.Constant.Value;
                valuesCompared = firstFieldValue.CompareTo(secondFieldValue);
            }
            else if (firstField.Constant.Value.GetType().Name == "UInt16")
            {
                ushort firstFieldValue  = (ushort)firstField.Constant.Value;
                ushort secondFieldValue = (ushort)secondField.Constant.Value;
                valuesCompared = firstFieldValue.CompareTo(secondFieldValue);
            }
            else if (firstField.Constant.Value.GetType().Name == "Byte")
            {
                byte firstFieldValue  = (byte)firstField.Constant.Value;
                byte secondFieldValue = (byte)secondField.Constant.Value;
                valuesCompared = firstFieldValue.CompareTo(secondFieldValue);
            }
            else if (firstField.Constant.Value.GetType().Name == "SByte")
            {
                sbyte firstFieldValue  = (sbyte)firstField.Constant.Value;
                sbyte secondFieldValue = (sbyte)secondField.Constant.Value;
                valuesCompared = firstFieldValue.CompareTo(secondFieldValue);
            }
            else if (firstField.Constant.Value.GetType().Name == "Int64")
            {
                long firstFieldValue  = (long)firstField.Constant.Value;
                long secondFieldValue = (long)secondField.Constant.Value;
                valuesCompared = firstFieldValue.CompareTo(secondFieldValue);
            }
            else if (firstField.Constant.Value.GetType().Name == "UInt64")
            {
                ulong firstFieldValue  = (ulong)firstField.Constant.Value;
                ulong secondFieldValue = (ulong)secondField.Constant.Value;
                valuesCompared = firstFieldValue.CompareTo(secondFieldValue);
            }
            if (valuesCompared != 0)
            {
                return(valuesCompared);
            }
            return(firstField.Name.CompareTo(secondField.Name));
        }
Exemplo n.º 16
0
        /// <summary>Compare two values after converting them to type, pType.</summary>
        /// <param name="pType">Validate the objects after converting to this type.</param>
        /// <param name="pLeft">Left object in comparison.</param>
        /// <param name="pRight">Right object in the comparison.</param>
        /// <returns>-1 if left is smaller; 0 if same; +1 if is greater.</returns>
        /// <remarks>
        /// Converts the arguments to the target type if it can and calls CompareTo.
        /// <para>Added by IdeaBlade; inspired by the body of Csla MinValue(Of T).</para>
        /// </remarks>
        public static int Compare(Type pType, object pLeft, object pRight)
        {
            int result;

            if (pType.IsPrimitive)
            {
                if (pType.Equals(typeof(int)))
                {
                    int v1 = Convert.ToInt32(pLeft);
                    int v2 = Convert.ToInt32(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(long)))
                {
                    long v1 = Convert.ToInt64(pLeft);
                    long v2 = Convert.ToInt64(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(decimal)))
                {
                    decimal v1 = Convert.ToDecimal(pLeft);
                    decimal v2 = Convert.ToDecimal(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(float)))
                {
                    float v1 = Convert.ToSingle(pLeft);
                    float v2 = Convert.ToSingle(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(double)))
                {
                    double v1 = Convert.ToDouble(pLeft);
                    double v2 = Convert.ToDouble(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(byte)))
                {
                    byte v1 = Convert.ToByte(pLeft);
                    byte v2 = Convert.ToByte(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(char)))
                {
                    char v1 = Convert.ToChar(pLeft);
                    char v2 = Convert.ToChar(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(short)))
                {
                    short v1 = Convert.ToInt16(pLeft);
                    short v2 = Convert.ToInt16(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(bool)))
                {
                    bool v1 = Convert.ToBoolean(pLeft);
                    bool v2 = Convert.ToBoolean(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(ushort)))
                {
                    ushort v1 = Convert.ToUInt16(pLeft);
                    ushort v2 = Convert.ToUInt16(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(uint)))
                {
                    uint v1 = Convert.ToUInt32(pLeft);
                    uint v2 = Convert.ToUInt32(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(ulong)))
                {
                    ulong v1 = Convert.ToUInt64(pLeft);
                    ulong v2 = Convert.ToUInt64(pRight);
                    result = v1.CompareTo(v2);
                }
                else if (pType.Equals(typeof(sbyte)))
                {
                    sbyte v1 = Convert.ToSByte(pLeft);
                    sbyte v2 = Convert.ToSByte(pRight);
                    result = v1.CompareTo(v2);
                }
                else
                {
                    throw new ArgumentException(Resources.PrimitiveTypeRequired);
                }
                // not primitive
            }
            else if (pType.Equals(typeof(DateTime)))
            {
                DateTime v1 = Convert.ToDateTime(pLeft);
                DateTime v2 = Convert.ToDateTime(pRight);
                result = v1.CompareTo(v2);
            }
            else if (pType is IComparable)
            {
                result = ((IComparable)pLeft).CompareTo((IComparable)pRight);
            }
            else
            {
                throw new ArgumentException(Resources.MethodCallFailed);
            }
            return(result);
        }
Exemplo n.º 17
0
 /// <summary>
 ///     A T extension method that check if the value is between inclusively the minValue and maxValue.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="minValue">The minimum value.</param>
 /// <param name="maxValue">The maximum value.</param>
 /// <returns>true if the value is between inclusively the minValue and maxValue, otherwise false.</returns>
 /// ###
 /// <typeparam name="T">Generic type parameter.</typeparam>
 public static bool InRange(this sbyte @this, sbyte minValue, sbyte maxValue)
 {
     return(@this.CompareTo(minValue) >= 0 && @this.CompareTo(maxValue) <= 0);
 }
Exemplo n.º 18
0
 public static int CompareToAsc(this sbyte left, sbyte right)
 {
     return(left.CompareTo(right));
 }
Exemplo n.º 19
0
 public int CompareTo(sbyte other) => signed.CompareTo(other);
Exemplo n.º 20
0
        internal override int Compare(object value1, object value2)
        {
            sbyte num = (sbyte)value1;

            return(num.CompareTo(value2));
        }
Exemplo n.º 21
0
 /// <summary>
 ///     A T extension method that check if the value is between (exclusif) the minValue and maxValue.
 /// </summary>
 /// <param name="this">The @this to act on.</param>
 /// <param name="minValue">The minimum value.</param>
 /// <param name="maxValue">The maximum value.</param>
 /// <returns>true if the value is between the minValue and maxValue, otherwise false.</returns>
 /// ###
 /// <typeparam name="T">Generic type parameter.</typeparam>
 public static bool IsBetween(this sbyte @this, sbyte minValue, sbyte maxValue)
 {
     return(minValue.CompareTo(@this) == -1 && @this.CompareTo(maxValue) == -1);
 }