Пример #1
0
        public void TestRemovalByPercentageFromSubstance()
        {
            Model model = new Model("Hello, world.", Guid.NewGuid());
            BasicReactionSupporter brs = new BasicReactionSupporter();

            LoadSampleCatalog(brs.MyMaterialCatalog);

            Debug.WriteLine("\r\nWe now work on a substance.");
            MaterialType mt = brs.MyMaterialCatalog["Hydrochloric Acid"];
            Substance    s  = (Substance)mt.CreateMass(100, 20);

            Debug.WriteLine("We have " + s);

            MaterialTransferSpecByPercentage tsbp = new MaterialTransferSpecByPercentage(brs.MyMaterialCatalog["Hydrochloric Acid"], .75, TimeSpan.FromMinutes(5));

            IMaterial removee = tsbp.GetExtract(s);

            Debug.WriteLine("Want to remove " + tsbp);
            Debug.WriteLine("Successful in removing " + removee + ".\r\nWhat remains is ");
            Debug.WriteLine(s);

            Assert.IsTrue(Math.Abs(s.Mass - 25.00) < 0.01, "The Water part is not 25 kg");
            Assert.IsTrue(tsbp.Duration.Hours == 6 && tsbp.Duration.Minutes == 15, "Removing 75% Water part did not take 5 Min");
        }
Пример #2
0
        public void TestRemovalByPercentageFromMixture()
        {
            Model model = new Model("Hello, world.", Guid.NewGuid());
            BasicReactionSupporter brs = new BasicReactionSupporter();

            LoadSampleCatalog(brs.MyMaterialCatalog);

            // Define reactions
            Reaction r = new Reaction(null, "Reaction", Guid.NewGuid());

            r.AddReactant(brs.MyMaterialCatalog["Caustic Soda"], 0.5231);
            r.AddReactant(brs.MyMaterialCatalog["Hydrochloric Acid"], 0.4769);
            r.AddProduct(brs.MyMaterialCatalog["Water"], 0.2356);
            r.AddProduct(brs.MyMaterialCatalog["Sodium Chloride"], 0.7644);
            brs.MyReactionProcessor.AddReaction(r);

            Mixture mixture = new Mixture(model, "Test mixture 1", Guid.NewGuid());

            brs.MyReactionProcessor.Watch(mixture);

            // Add substances
            AddSubstance(ref mixture, brs.MyMaterialCatalog["Caustic Soda"], 40, 20.0);
            AddSubstance(ref mixture, brs.MyMaterialCatalog["Hydrochloric Acid"], 40, 20.0);
            mixture.Temperature = 100.0;

            // Definitions to retrive substances from mixture
            Substance water            = null;
            Substance hydrochloricAcid = null;
            Substance sodiumCloride    = null;

            foreach (Substance su in mixture.Constituents)
            {
                switch (su.Name)
                {
                case "Water": water = su; break;

                case "Hydrochloric Acid": hydrochloricAcid = su; break;

                case "Sodium Chloride": sodiumCloride = su; break;
                }
            }

            Assert.IsTrue(Math.Abs(hydrochloricAcid.Mass - 3.53) < 0.01, "The Hydrochloric Acid part is not 3.53 kg");
            Assert.IsTrue(Math.Abs(water.Mass - 18.01) < 0.01, "The Water part is not 18.01 kg");
            Assert.IsTrue(Math.Abs(sodiumCloride.Mass - 58.45) < 0.01, "The Sodium Cloride part is not 58.45 kg");

            // Duration for removing mass given is per 1 kg
            MaterialTransferSpecByPercentage tsbp = new MaterialTransferSpecByPercentage(brs.MyMaterialCatalog["Water"], .5, TimeSpan.FromMinutes(5));

            IMaterial removee = tsbp.GetExtract(mixture);

            Debug.WriteLine("Want to remove " + tsbp);
            Debug.WriteLine("Successful in removing " + removee + ".\r\nWhat remains is ");
            Debug.WriteLine(mixture);

            // Now try to remove by mass from a substance.
            foreach (Substance su in mixture.Constituents)
            {
                switch (su.Name)
                {
                case "Water": water = su; break;

                case "Hydrochloric Acid": hydrochloricAcid = su; break;

                case "Sodium Chloride": sodiumCloride = su; break;
                }
            }

            Assert.IsTrue(Math.Abs(hydrochloricAcid.Mass - 3.53) < 0.01, "The Hydrochloric Acid part is not 3.53 kg");
            Assert.IsTrue(Math.Abs(water.Mass - 9.00) < 0.01, "The Water part is not 9.00 kg");
            Assert.IsTrue(Math.Abs(sodiumCloride.Mass - 58.45) < 0.01, "The Sodium Cloride part is not 58.45 kg");
            Assert.IsTrue(tsbp.Duration.Minutes == 45, "Removing 50% Water part did not take 5 Min"); // there are also a few seconds and miliseconds
        }