Exemple #1
0
        public void TestCancel()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");
            IIsotope p    = ifac.GetMajorIsotope("P");
            IIsotope s    = ifac.GetMajorIsotope("S");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 1000);
            mfRange.AddIsotope(h, 0, 1000);
            mfRange.AddIsotope(o, 0, 1000);
            mfRange.AddIsotope(n, 0, 1000);
            mfRange.AddIsotope(p, 0, 1000);
            mfRange.AddIsotope(s, 0, 1000);

            double minMass = 100000.0;
            double maxMass = 100000.001;

            MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);

            var cancelThread = new ThreadStart(() => {
                Thread.Sleep(5);
                gen.Cancel();
            });

            new Thread(cancelThread).Start();

            Thread.Sleep(10);
            // We will get stuck in the next method call until the cancel thread
            // calls the Cancel() method
            gen.GetAllFormulas();

            // Next GetNextFormula() call should return null
            IMolecularFormula f = gen.GetNextFormula();

            Assert.IsNull(f);
        }
Exemple #2
0
        public void TestGetFinishedPercentage()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 10);
            mfRange.AddIsotope(h, 0, 10);
            mfRange.AddIsotope(o, 0, 10);
            mfRange.AddIsotope(n, 0, 10);

            double minMass = 100.0;
            double maxMass = 100.05;

            MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);

            double finishedPerc, lastFinishedPerc = 0d;

            // The initial value must be 0
            finishedPerc = gen.GetFinishedPercentage();
            Assert.AreEqual(0d, finishedPerc, 0.0001);

            // The value must increase after each generated formula
            while (gen.GetNextFormula() != null)
            {
                finishedPerc = gen.GetFinishedPercentage();
                Assert.IsTrue(finishedPerc > lastFinishedPerc);
                lastFinishedPerc = finishedPerc;
            }

            // The final value must be 1
            finishedPerc = gen.GetFinishedPercentage();
            Assert.AreEqual(1d, finishedPerc, 0.0001);
        }
Exemple #3
0
        public void TestGetNextFormula()
        {
            var      ifac = BODRIsotopeFactory.Instance;
            IIsotope c    = ifac.GetMajorIsotope("C");
            IIsotope h    = ifac.GetMajorIsotope("H");
            IIsotope n    = ifac.GetMajorIsotope("N");
            IIsotope o    = ifac.GetMajorIsotope("O");

            MolecularFormulaRange mfRange = new MolecularFormulaRange();

            mfRange.AddIsotope(c, 0, 10);
            mfRange.AddIsotope(h, 0, 10);
            mfRange.AddIsotope(o, 0, 10);
            mfRange.AddIsotope(n, 0, 10);

            double minMass = 100.0;
            double maxMass = 100.05;

            MolecularFormulaGenerator gen = new MolecularFormulaGenerator(builder, minMass, maxMass, mfRange);
            IMolecularFormula         f   = gen.GetNextFormula();

            Assert.IsNotNull(f);
        }