Exemplo n.º 1
0
        public void TestTiming()
        {
            // Generate an Ensemble
            DataSet.Ensemble ensemble = EnsembleHelper.GenerateEnsemble(30);

            Stopwatch watch = new Stopwatch();


            // Test Serialize()
            watch = new Stopwatch();
            watch.Start();
            for (int x = 0; x < 1000; x++)
            {
                string encoded = Newtonsoft.Json.JsonConvert.SerializeObject(ensemble.EarthWaterMassData);
            }
            watch.Stop();
            long resultSerialize = watch.ElapsedMilliseconds;

            // Test Deserialize()
            string encodedd = Newtonsoft.Json.JsonConvert.SerializeObject(ensemble.EarthWaterMassData);

            watch = new Stopwatch();
            watch.Start();
            for (int x = 0; x < 1000; x++)
            {
                DataSet.EarthWaterMassDataSet decoded = Newtonsoft.Json.JsonConvert.DeserializeObject <DataSet.EarthWaterMassDataSet>(encodedd);
            }
            watch.Stop();
            long resultDeserialize = watch.ElapsedMilliseconds;

            Debug.WriteLine(String.Format("Serialize:{0}  Deserialize:{1}", resultSerialize, resultDeserialize));

            Debug.WriteLine("Complete");
        }
Exemplo n.º 2
0
        public void TestJson()
        {
            // Generate an Ensemble
            DataSet.Ensemble ensemble = EnsembleHelper.GenerateEnsemble(30);

            // Modify the data
            ensemble.EarthWaterMassData.VelocityEast        = 2.3f;
            ensemble.EarthWaterMassData.VelocityNorth       = 3.4f;
            ensemble.EarthWaterMassData.VelocityVertical    = 4.5f;
            ensemble.EarthWaterMassData.WaterMassDepthLayer = 3.77f;

            string encoded = Newtonsoft.Json.JsonConvert.SerializeObject(ensemble.EarthWaterMassData);                                      // Serialize object to JSON

            DataSet.EarthWaterMassDataSet decoded = Newtonsoft.Json.JsonConvert.DeserializeObject <DataSet.EarthWaterMassDataSet>(encoded); // Deserialize the JSON

            // Verify the values are the same
            Assert.AreEqual(2.3f, decoded.VelocityEast, "Velocity East is incorrect.");
            Assert.AreEqual(3.4f, decoded.VelocityNorth, "Velocity North is incorrect.");
            Assert.AreEqual(4.5f, decoded.VelocityVertical, "Velocity Vertical is incorrect.");
            Assert.AreEqual(3.77f, decoded.WaterMassDepthLayer, "Water Mass Depty Layer is incorrect.");
        }