public void FromByteArrayTest()
        {
            Guid centroidID = Guid.NewGuid();

            MemoryStream stream = new MemoryStream();

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

            ClusterPoint expected = new ClusterPoint
            {
                X          = 2.53F,
                Y          = 4.56F,
                CentroidID = centroidID
            };
            ClusterPoint actual;

            actual = ClusterPoint.FromByteArray(bytes);

            const double Epsilon = 0.0001;

            Assert.IsTrue(Math.Abs(expected.X - actual.X) < Epsilon);
            Assert.IsTrue(Math.Abs(expected.Y - actual.Y) < Epsilon);
            Assert.AreEqual(expected.CentroidID, actual.CentroidID);
        }
        public void InitializeStorageTest()
        {
            KMeansJobData jobData = new KMeansJobData(Guid.NewGuid(), 2, null, 4, 10, DateTime.Now);
            KMeansJob     target  = new KMeansJob(jobData, "server");

            target.InitializeStorage();

            // Verify that the created containers and blobs actually exist
            CloudBlobClient client = AzureHelper.StorageAccount.CreateCloudBlobClient();

            CloudBlobContainer c = null;

            try
            {
                c = client.GetContainerReference(jobData.JobID.ToString());
                c.FetchAttributes();
            }
            catch (StorageClientException e)
            {
                if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
                {
                    Assert.Fail();
                }
                else
                {
                    throw;
                }
            }

            CloudBlob points = null, centroids = null;

            try
            {
                points = c.GetBlobReference("points");
                points.FetchAttributes();
                centroids = c.GetBlobReference("centroids");
                centroids.FetchAttributes();
            }
            catch (StorageClientException e)
            {
                if (e.ErrorCode == StorageErrorCode.ResourceNotFound)
                {
                    Assert.Fail();
                }
                else
                {
                    throw;
                }
            }

            // Verify that unpacking a ClusterPoint actually yields a point with coordinates [-50, 50) and a null centroidID
            byte[] pointBytes;
            using (BlobStream pointsStream = points.OpenRead())
            {
                pointBytes = new byte[ClusterPoint.Size];
                pointsStream.Read(pointBytes, 0, ClusterPoint.Size);
            }
            ClusterPoint p = ClusterPoint.FromByteArray(pointBytes);

            Assert.IsTrue(p.X >= -50 && p.X < 50);
            Assert.IsTrue(p.Y >= -50 && p.Y < 50);
            Assert.AreEqual(p.CentroidID, Guid.Empty);

            // Verify that the blobs are the correct length
            Assert.AreEqual(points.Properties.Length, ClusterPoint.Size * jobData.N);
            Assert.AreEqual(centroids.Properties.Length, Centroid.Size * jobData.K);
        }