Exemple #1
0
    public void TestCompare()
    {
        Assert.AreEqual(0, new Int256(1).CompareTo(new Int256(1)));
        Assert.AreEqual(-1, new Int256(1).CompareTo(new Int256(2)));
        Assert.AreEqual(1, new Int256(2).CompareTo(new Int256(1)));
        Assert.AreEqual(0, new Int256(0x123456789ABCDEF0, 0xA2A4A6A8D1D2D3D4, 0xB2B4B6B8C1C2C3C4, 0xC2C4C6C8B1B2B3B4).CompareTo(new Int256(0x123456789ABCDEF0, 0xA2A4A6A8D1D2D3D4, 0xB2B4B6B8C1C2C3C4, 0xC2C4C6C8B1B2B3B4)));

        //public ulong[] ToUIn64Array()
        //public uint[] ToUIn32Array()

        var t1 = new Int256(0x123456789ABCDEF0, 0xA2A4A6A8D1D2D3D4, 0xB2B4B6B8C1C2C3C4, 0xC2C4C6C8B1B2B3B4);

        ulong[] t2 = t1.ToUIn64Array();
        Assert.AreEqual(t2[0], 0xC2C4C6C8B1B2B3B4u);
        Assert.AreEqual(t2[1], 0xB2B4B6B8C1C2C3C4u);
        Assert.AreEqual(t2[2], 0xA2A4A6A8D1D2D3D4u);
        Assert.AreEqual(t2[3], 0x123456789ABCDEF0u);

        uint[] t3 = t1.ToUIn32Array();
        Assert.AreEqual(t3[0], 0xB1B2B3B4u);
        Assert.AreEqual(t3[1], 0xC2C4C6C8u);
        Assert.AreEqual(t3[2], 0xC1C2C3C4u);
        Assert.AreEqual(t3[3], 0xB2B4B6B8u);
        Assert.AreEqual(t3[4], 0xD1D2D3D4u);
        Assert.AreEqual(t3[5], 0xA2A4A6A8u);
        Assert.AreEqual(t3[6], 0x9ABCDEF0u);
        Assert.AreEqual(t3[7], 0x12345678u);

        //public static bool operator >(Int256 left, Int256 right)
        //public static bool operator <(Int256 left, Int256 right)
        //public static bool operator >=(Int256 left, Int256 right)
        //public static bool operator <=(Int256 left, Int256 right)
        //public static bool operator !=(Int256 left, Int256 right)
        //public static bool operator ==(Int256 left, Int256 right)

        Assert.AreEqual(true, new Int256(1) == new Int256(1));
        Assert.AreEqual(true, new Int256(10) == 10);
        Assert.AreEqual(true, new Int256(9) < 10);
        Assert.AreEqual(true, new Int256(11) > 10);
        Assert.AreEqual(true, new Int256(1) != new Int256(2));
        Assert.AreEqual(true, new Int256(0x123456789ABCDEFA) == 0x123456789ABCDEFA);

        var small1 = new Int256(0x123456789ABCDEF0, 0xA2A4A6A8D1D2D3D4, 0xB2B4B6B8C1C2C3C4, 0xC2C4C6C8B1B2B3B4);
        var big1   = new Int256(0x223456789ABCDEF0, 0xA2A4A6A8D1D2D3D4, 0xB2B4B6B8C1C2C3C4, 0xC2C4C6C8B1B2B3B4);
        var big1b  = new Int256(0x223456789ABCDEF0, 0xA2A4A6A8D1D2D3D4, 0xB2B4B6B8C1C2C3C4, 0xC2C4C6C8B1B2B3B4);
        var small2 = new Int256(0x123456789ABCDEF0, 0xA2A4A6A8D1D2D3D4, 0xB2B4B6B8C1C2C3C4, 0xC2C4C6C8B1B2B3B4);
        var big2   = new Int256(0x123456789ABCDEF0, 0xA2A4A6A8D1D2D3D4, 0xB2B4B6B8C1C2C3C4, 0xC2C4C6C8B1B2B3B5);

        Assert.AreEqual(true, small1 < big1);
        Assert.AreEqual(true, small2 < big2);
        Assert.AreEqual(true, small1 <= big1);
        Assert.AreEqual(true, small2 <= big2);
        Assert.AreEqual(true, big1 > small1);
        Assert.AreEqual(true, big2 > small2);
        Assert.AreEqual(true, big1 >= small1);
        Assert.AreEqual(true, big2 >= small2);
        Assert.AreEqual(true, big1 >= big1b);
        Assert.AreEqual(true, big1 <= big1b);
    }