Exemplo n.º 1
0
        public void CompareToWorksCorrectly(GameVersion v1, GameVersion v2, int comparison)
        {
            // Act
            var genericCompareTo           = v1.CompareTo(v2);
            var nonGenericCompareTo        = v1.CompareTo((object)v2);
            var lessThanOperator           = v1 < v2;
            var lessThanOrEqualOperator    = v1 <= v2;
            var greaterThanOperator        = v1 > v2;
            var greaterThanOrEqualOperator = v1 >= v2;

            var reverseGenericCompareTo           = v2.CompareTo(v1);
            var reverseNonGenericCompareTo        = v2.CompareTo((object)v1);
            var reverseLessThanOperator           = v2 < v1;
            var reverseLessThanOrEqualOperator    = v2 <= v1;
            var reverseGreaterThanOperator        = v2 > v1;
            var reverseGreaterThanOrEqualOperator = v2 >= v1;

            // Assert
            Assert.AreEqual(Math.Sign(comparison), Math.Sign(genericCompareTo));
            Assert.AreEqual(Math.Sign(comparison), Math.Sign(nonGenericCompareTo));
            Assert.AreEqual(comparison < 0, lessThanOperator);
            Assert.AreEqual(comparison <= 0, lessThanOrEqualOperator);
            Assert.AreEqual(comparison > 0, greaterThanOperator);
            Assert.AreEqual(comparison >= 0, greaterThanOrEqualOperator);
            Assert.AreEqual(-Math.Sign(comparison), Math.Sign(reverseGenericCompareTo));
            Assert.AreEqual(-Math.Sign(comparison), Math.Sign(reverseNonGenericCompareTo));
            Assert.AreEqual(comparison > 0, reverseLessThanOperator);
            Assert.AreEqual(comparison >= 0, reverseLessThanOrEqualOperator);
            Assert.AreEqual(comparison < 0, reverseGreaterThanOperator);
            Assert.AreEqual(comparison <= 0, reverseGreaterThanOrEqualOperator);
        }
Exemplo n.º 2
0
    static int CompareTo(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2 && TypeChecker.CheckTypes <GameVersion>(L, 2))
            {
                GameVersion obj  = (GameVersion)ToLua.CheckObject <GameVersion>(L, 1);
                GameVersion arg0 = (GameVersion)ToLua.ToObject(L, 2);
                int         o    = obj.CompareTo(arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <object>(L, 2))
            {
                GameVersion obj  = (GameVersion)ToLua.CheckObject <GameVersion>(L, 1);
                object      arg0 = ToLua.ToVarObject(L, 2);
                int         o    = obj.CompareTo(arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: GameVersion.CompareTo"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Exemplo n.º 3
0
 public int CompareTo(Version other)
 {
     return(GameVersion.CompareTo(other));
 }