示例#1
0
        public void methods()
        {
            Assert.True(R1L.GetHex() == R1L.ToString());
            Assert.True(R2L.GetHex() == R2L.ToString());
            Assert.True(OneL.GetHex() == OneL.ToString());
            Assert.True(MaxL.GetHex() == MaxL.ToString());
            uint256 TmpL = new uint256(R1L);

            Assert.True(TmpL == R1L);
            TmpL.SetHex(R2L.ToString());
            Assert.True(TmpL == R2L);
            TmpL.SetHex(ZeroL.ToString());
            Assert.True(TmpL == 0);
            TmpL.SetHex(HalfL.ToString());
            Assert.True(TmpL == HalfL);

            TmpL.SetHex(R1L.ToString());
            AssertEx.CollectionEquals(R1L.ToBytes(), R1Array);
            AssertEx.CollectionEquals(TmpL.ToBytes(), R1Array);
            AssertEx.CollectionEquals(R2L.ToBytes(), R2Array);
            AssertEx.CollectionEquals(ZeroL.ToBytes(), ZeroArray);
            AssertEx.CollectionEquals(OneL.ToBytes(), OneArray);
            Assert.True(R1L.Size == 32);
            Assert.True(R2L.Size == 32);
            Assert.True(ZeroL.Size == 32);
            Assert.True(MaxL.Size == 32);

            //No sense in .NET
            //Assert.True(R1L.begin() + 32 == R1L.end());
            //Assert.True(R2L.begin() + 32 == R2L.end());
            //Assert.True(OneL.begin() + 32 == OneL.end());
            //Assert.True(MaxL.begin() + 32 == MaxL.end());
            //Assert.True(TmpL.begin() + 32 == TmpL.end());
            Assert.True(R1L.GetLow64() == R1LLow64);
            Assert.True(HalfL.GetLow64() == 0x0000000000000000UL);
            Assert.True(OneL.GetLow64() == 0x0000000000000001UL);
            Assert.True(R1L.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 32);
            Assert.True(ZeroL.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 32);

            MemoryStream ss = new MemoryStream();

            R1L.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(R1Array));
            TmpL.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(R1L == TmpL);
            ss = new MemoryStream();
            ZeroL.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(ZeroArray));
            ss.Position = 0;
            TmpL.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(ZeroL == TmpL);
            ss = new MemoryStream();
            MaxL.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(MaxArray));
            ss.Position = 0;
            TmpL.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(MaxL == TmpL);
            ss = new MemoryStream();

            Assert.True(R1S.GetHex() == R1S.ToString());
            Assert.True(R2S.GetHex() == R2S.ToString());
            Assert.True(OneS.GetHex() == OneS.ToString());
            Assert.True(MaxS.GetHex() == MaxS.ToString());
            uint160 TmpS = new uint160(R1S);

            Assert.True(TmpS == R1S);
            TmpS.SetHex(R2S.ToString());
            Assert.True(TmpS == R2S);
            TmpS.SetHex(ZeroS.ToString());
            Assert.True(TmpS == 0);
            TmpS.SetHex(HalfS.ToString());
            Assert.True(TmpS == HalfS);

            TmpS.SetHex(R1S.ToString());

            Assert.True(ArrayToString(R1S.ToBytes()) == ArrayToString(R1Array.Take(20).ToArray()));
            Assert.True(ArrayToString(TmpS.ToBytes()) == ArrayToString(R1Array.Take(20).ToArray()));
            Assert.True(ArrayToString(R2S.ToBytes()) == ArrayToString(R2Array.Take(20).ToArray()));
            Assert.True(ArrayToString(ZeroS.ToBytes()) == ArrayToString(ZeroArray.Take(20).ToArray()));
            Assert.True(ArrayToString(OneS.ToBytes()) == ArrayToString(OneArray.Take(20).ToArray()));
            Assert.True(R1S.Size == 20);
            Assert.True(R2S.Size == 20);
            Assert.True(ZeroS.Size == 20);
            Assert.True(MaxS.Size == 20);
            //No sense in .NET
            //Assert.True(R1S.begin() + 20 == R1S.end());
            //Assert.True(R2S.begin() + 20 == R2S.end());
            //Assert.True(OneS.begin() + 20 == OneS.end());
            //Assert.True(MaxS.begin() + 20 == MaxS.end());
            //Assert.True(TmpS.begin() + 20 == TmpS.end());
            Assert.True(R1S.GetLow64() == R1LLow64);
            Assert.True(HalfS.GetLow64() == 0x0000000000000000UL);
            Assert.True(OneS.GetLow64() == 0x0000000000000001UL);
            Assert.True(R1S.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 20);
            Assert.True(ZeroS.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 20);

            R1S.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(R1Array.Take(20).ToArray()));
            ss.Position = 0;
            TmpS.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(R1S == TmpS);
            ss = new MemoryStream();
            ZeroS.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(ZeroArray.Take(20).ToArray()));
            ss.Position = 0;
            TmpS.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(ZeroS == TmpS);
            ss = new MemoryStream();
            MaxS.Serialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(MaxArray.Take(20).ToArray()));
            ss.Position = 0;
            TmpS.Unserialize(ss, 0, ProtocolVersion.PROTOCOL_VERSION);
            Assert.True(MaxS == TmpS);
            ss = new MemoryStream();

            //for(int i = 0 ; i < 255 ; ++i)
            //{
            //	Assert.True((OneL << i).GetDouble() == Math.Pow(1.0, i));
            //	if(i < 160)
            //		Assert.True((OneS << i).GetDouble() == Math.Pow(1.0, i));
            //}
            //Assert.True(ZeroL.GetDouble() == 0.0);
            //Assert.True(ZeroS.GetDouble() == 0.0);
            //for(int i = 256 ; i > 53 ; --i)
            //	Assert.True(almostEqual((R1L >> (256 - i)).GetDouble(), Math.Pow(R1Ldouble, i)));
            //for(int i = 160 ; i > 53 ; --i)
            //	Assert.True(almostEqual((R1S >> (160 - i)).GetDouble(), Math.Pow(R1Sdouble, i)));
            //ulong R1L64part = (R1L >> 192).GetLow64();
            //ulong R1S64part = (R1S >> 96).GetLow64();
            //for(int i = 53 ; i > 0 ; --i) // doubles can store all integers in {0,...,2^54-1} exactly
            //{
            //	Assert.True((R1L >> (256 - i)).GetDouble() == (double)(R1L64part >> (64 - i)));
            //	Assert.True((R1S >> (160 - i)).GetDouble() == (double)(R1S64part >> (64 - i)));
            //}
        }
示例#2
0
		public void methods()
		{
			Assert.True(R1L.ToString() == R1L.ToString());
			Assert.True(R2L.ToString() == R2L.ToString());
			Assert.True(OneL.ToString() == OneL.ToString());
			Assert.True(MaxL.ToString() == MaxL.ToString());
			uint256 TmpL = new uint256(R1L);
			Assert.True(TmpL == R1L);
			TmpL.SetHex(R2L.ToString());
			Assert.True(TmpL == R2L);
			TmpL.SetHex(ZeroL.ToString());
			Assert.True(TmpL == 0);
			TmpL.SetHex(HalfL.ToString());
			Assert.True(TmpL == HalfL);

			TmpL.SetHex(R1L.ToString());
			AssertEx.CollectionEquals(R1L.ToBytes(), R1Array);
			AssertEx.CollectionEquals(TmpL.ToBytes(), R1Array);
			AssertEx.CollectionEquals(R2L.ToBytes(), R2Array);
			AssertEx.CollectionEquals(ZeroL.ToBytes(), ZeroArray);
			AssertEx.CollectionEquals(OneL.ToBytes(), OneArray);
			Assert.True(R1L.Size == 32);
			Assert.True(R2L.Size == 32);
			Assert.True(ZeroL.Size == 32);
			Assert.True(MaxL.Size == 32);

			//No sense in .NET
			//Assert.True(R1L.begin() + 32 == R1L.end());
			//Assert.True(R2L.begin() + 32 == R2L.end());
			//Assert.True(OneL.begin() + 32 == OneL.end());
			//Assert.True(MaxL.begin() + 32 == MaxL.end());
			//Assert.True(TmpL.begin() + 32 == TmpL.end());
			Assert.True(R1L.GetLow64() == R1LLow64);
			Assert.True(HalfL.GetLow64() == 0x0000000000000000UL);
			Assert.True(OneL.GetLow64() == 0x0000000000000001UL);
			Assert.True(R1L.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 32);
			Assert.True(ZeroL.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 32);

			MemoryStream ss = new MemoryStream();
			R1L.ReadWrite(ss, true, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(R1Array));
			ss.Position = 0;
			TmpL.ReadWrite(ss, false, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(R1L == TmpL);
			ss = new MemoryStream();
			ZeroL.ReadWrite(ss, true, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(ZeroArray));
			ss.Position = 0;
			TmpL.ReadWrite(ss, false, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(ZeroL == TmpL);
			ss = new MemoryStream();
			MaxL.ReadWrite(ss, true, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(MaxArray));
			ss.Position = 0;
			TmpL.ReadWrite(ss, false, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(MaxL == TmpL);
			ss = new MemoryStream();

			uint160 TmpS = new uint160(R1S);
			Assert.True(TmpS == R1S);
			TmpS.SetHex(R2S.ToString());
			Assert.True(TmpS == R2S);
			TmpS.SetHex(ZeroS.ToString());
			Assert.True(TmpS == 0);
			TmpS.SetHex(HalfS.ToString());
			Assert.True(TmpS == HalfS);

			TmpS.SetHex(R1S.ToString());

			Assert.True(ArrayToString(R1S.ToBytes()) == ArrayToString(R1Array.Take(20).ToArray()));
			Assert.True(ArrayToString(TmpS.ToBytes()) == ArrayToString(R1Array.Take(20).ToArray()));
			Assert.True(ArrayToString(R2S.ToBytes()) == ArrayToString(R2Array.Take(20).ToArray()));
			Assert.True(ArrayToString(ZeroS.ToBytes()) == ArrayToString(ZeroArray.Take(20).ToArray()));
			Assert.True(ArrayToString(OneS.ToBytes()) == ArrayToString(OneArray.Take(20).ToArray()));
			Assert.True(R1S.Size == 20);
			Assert.True(R2S.Size == 20);
			Assert.True(ZeroS.Size == 20);
			Assert.True(MaxS.Size == 20);
			//No sense in .NET
			//Assert.True(R1S.begin() + 20 == R1S.end());
			//Assert.True(R2S.begin() + 20 == R2S.end());
			//Assert.True(OneS.begin() + 20 == OneS.end());
			//Assert.True(MaxS.begin() + 20 == MaxS.end());
			//Assert.True(TmpS.begin() + 20 == TmpS.end());
			Assert.True(R1S.GetLow64() == R1LLow64);
			Assert.True(HalfS.GetLow64() == 0x0000000000000000UL);
			Assert.True(OneS.GetLow64() == 0x0000000000000001UL);
			Assert.True(R1S.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 20);
			Assert.True(ZeroS.GetSerializeSize(0, ProtocolVersion.PROTOCOL_VERSION) == 20);

			R1S.ReadWrite(ss, true, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(R1Array.Take(20).ToArray()));
			ss.Position = 0;
			TmpS.ReadWrite(ss, false, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(R1S == TmpS);
			ss = new MemoryStream();
			ZeroS.ReadWrite(ss, true, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(ZeroArray.Take(20).ToArray()));
			ss.Position = 0;
			TmpS.ReadWrite(ss, false, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(ZeroS == TmpS);
			ss = new MemoryStream();
			MaxS.ReadWrite(ss, true, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(ArrayToString(ss.ToArray()) == ArrayToString(MaxArray.Take(20).ToArray()));
			ss.Position = 0;
			TmpS.ReadWrite(ss, false, ProtocolVersion.PROTOCOL_VERSION);
			Assert.True(MaxS == TmpS);
			ss = new MemoryStream();

			//for(int i = 0 ; i < 255 ; ++i)
			//{
			//	Assert.True((OneL << i).GetDouble() == Math.Pow(1.0, i));
			//	if(i < 160)
			//		Assert.True((OneS << i).GetDouble() == Math.Pow(1.0, i));
			//}
			//Assert.True(ZeroL.GetDouble() == 0.0);
			//Assert.True(ZeroS.GetDouble() == 0.0);
			//for(int i = 256 ; i > 53 ; --i)
			//	Assert.True(almostEqual((R1L >> (256 - i)).GetDouble(), Math.Pow(R1Ldouble, i)));
			//for(int i = 160 ; i > 53 ; --i)
			//	Assert.True(almostEqual((R1S >> (160 - i)).GetDouble(), Math.Pow(R1Sdouble, i)));
			//ulong R1L64part = (R1L >> 192).GetLow64();
			//ulong R1S64part = (R1S >> 96).GetLow64();
			//for(int i = 53 ; i > 0 ; --i) // doubles can store all integers in {0,...,2^54-1} exactly
			//{
			//	Assert.True((R1L >> (256 - i)).GetDouble() == (double)(R1L64part >> (64 - i)));
			//	Assert.True((R1S >> (160 - i)).GetDouble() == (double)(R1S64part >> (64 - i)));
			//}
		}