示例#1
0
        public void FromByteArrayTest()
        {
            const double Epsilon = 0.0001;

            Guid id = Guid.NewGuid();

            MemoryStream stream = new MemoryStream();
            stream.Write(id.ToByteArray(), 0, 16);
            stream.Write(BitConverter.GetBytes(2.53), 0, sizeof(double));
            stream.Write(BitConverter.GetBytes(4.56), 0, sizeof(double));
            byte[] bytes = stream.ToArray();

            Centroid expected = new Centroid
            {
                ID = id,
                X = 2.53F,
                Y = 4.56F
            };
            Centroid actual;
            actual = Centroid.FromByteArray(bytes);

            Assert.AreEqual(expected.ID, actual.ID);
            Assert.IsTrue(Math.Abs(expected.X - actual.X) < Epsilon);
            Assert.IsTrue(Math.Abs(expected.Y - actual.Y) < Epsilon);
        }
示例#2
0
        public void CentroidConstructorTest()
        {
            Guid id = Guid.NewGuid();
            Point p = new Point
            {
                X = 1,
                Y = 2
            };
            Centroid target = new Centroid(id, p);

            Assert.AreEqual(target.X, p.X);
            Assert.AreEqual(target.Y, p.Y);
            Assert.AreEqual(target.ID, id);
        }
示例#3
0
        public static List <Centroid> ListFromByteStream(Stream stream)
        {
            List <Centroid> centroids = new List <Centroid>();

            byte[] centroidBytes = new byte[Centroid.Size];
            while (stream.Position + Centroid.Size <= stream.Length)
            {
                stream.Read(centroidBytes, 0, Centroid.Size);
                Centroid c = Centroid.FromByteArray(centroidBytes);
                centroids.Add(c);
            }

            return(centroids);
        }
示例#4
0
        public void ToByteArrayTest()
        {
            Guid id = Guid.NewGuid();
            Centroid target = new Centroid
            {
                ID = id,
                X = 1.23,
                Y = 3.45
            };

            MemoryStream stream = new MemoryStream();
            stream.Write(id.ToByteArray(), 0, 16);
            stream.Write(BitConverter.GetBytes(1.23), 0, sizeof(double));
            stream.Write(BitConverter.GetBytes(3.45), 0, sizeof(double));
            byte[] expected = stream.ToArray();

            byte[] actual;
            actual = target.ToByteArray();
            Assert.AreEqual(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }