예제 #1
0
        public virtual void TestNonclonable()
        {
            var      isotope = new BODRIsotope("C", 6, 12, 12.0, 99.0);
            IIsotope clone   = (IIsotope)isotope.Clone();

            Assert.AreEqual(isotope, clone);
        }
예제 #2
0
        private BODRIsotopeFactory()
        {
            string configFile = "NCDK.Config.Data.isotopes.dat";
            var    ins        = ResourceLoader.GetAsStream(configFile);

            var buffer = new byte[8];

            ins.Read(buffer, 0, 4);
            Array.Reverse(buffer, 0, 4);
            int isotopeCount = BitConverter.ToInt32(buffer, 0);

            for (int i = 0; i < isotopeCount; i++)
            {
                var atomicNum = ins.ReadByte();
                ins.Read(buffer, 0, 2);
                Array.Reverse(buffer, 0, 2);
                var massNum = BitConverter.ToInt16(buffer, 0);
                ins.Read(buffer, 0, 8);
                Array.Reverse(buffer, 0, 8);
                var    exactMass = BitConverter.ToDouble(buffer, 0);
                double natAbund;
                if (ins.ReadByte() == 1)
                {
                    ins.Read(buffer, 0, 8);
                    Array.Reverse(buffer, 0, 8);
                    natAbund = BitConverter.ToDouble(buffer, 0);
                }
                else
                {
                    natAbund = 0;
                }
                var isotope = new BODRIsotope(PeriodicTable.GetSymbol(atomicNum), atomicNum, massNum, exactMass, natAbund);
                Add(isotope);
            }
        }
예제 #3
0
        public virtual void TestConstructor()
        {
            IIsotope isotope = new BODRIsotope("C", 6, 12, 12.0, 99.0);

            Assert.AreEqual("C", isotope.Symbol);
            Assert.AreEqual(6, isotope.AtomicNumber);
            Assert.AreEqual(12, isotope.MassNumber.Value);
            Assert.AreEqual(12.0, isotope.ExactMass.Value, 0.001);
            Assert.AreEqual(99.0, isotope.Abundance.Value, 0.001);
        }
예제 #4
0
        public void TestImmutable()
        {
            IIsotope isotope = new BODRIsotope("C", 6, 12, 12.0, 99.0)
            {
                // try mutations
                Symbol       = "N",
                AtomicNumber = 5,
                MassNumber   = 15,
                ExactMass    = 15.000,
                Abundance    = 0.364
            };

            // check if original
            Assert.AreEqual(6, isotope.AtomicNumber);
            Assert.AreEqual(12, isotope.MassNumber.Value);
            Assert.AreEqual(12.0, isotope.ExactMass.Value, 0.001);
            Assert.AreEqual(99.0, isotope.Abundance.Value, 0.001);
        }