コード例 #1
0
        public void Should_contain_the_same_atoms(string symbol1, string symbol2)
        {
            var compound1 = ChemicalCompound.New(symbol1);
            var compound2 = ChemicalCompound.New(symbol2);

            Assert.True(compound1.AreIsomers(compound2));
        }
コード例 #2
0
        public ActionResult Save(ChemicalCompound chemicalCompound)
        {
            if (!ModelState.IsValid)
            {
                var model = new ChemicalViewModel
                {
                    ChemicalTypes    = _context.ChemicalTypes.ToList(),
                    ChemicalCompound = chemicalCompound
                };
                return(View("New", model));
            }

            if (chemicalCompound.Id == 0)
            {
                _context.ChemicalCompounds.Add(chemicalCompound);
            }
            else
            {
                var compoundInDb = _context.ChemicalCompounds.SingleOrDefault(c => c.Id == chemicalCompound.Id);
                compoundInDb.Name           = chemicalCompound.Name;
                compoundInDb.ChemicalTypeId = chemicalCompound.ChemicalTypeId;
                compoundInDb.ChemicalSymbol = chemicalCompound.ChemicalSymbol;
            }
            _context.SaveChanges();
            return(RedirectToAction("AllChemicallCompounds", "ChemicalCompounds"));
        }
コード例 #3
0
        public void Check_molecule_properties(string compoundSymbol, bool isHomonuclear, bool isHeteronuclear, bool isDiatomic)
        {
            var compound = ChemicalCompound.New(compoundSymbol, "");

            Assert.Equal(compound.IsHomonuclear, isHomonuclear);
            Assert.Equal(compound.IsHeteronuclear, isHeteronuclear);
            Assert.Equal(compound.IsDiatomic, isDiatomic);
        }
コード例 #4
0
        public void Should_calculate_electrons_neutrons_protons_for_CompoundStack(string compoundSymbol, int electrons, int neutrons, int protons, int atoms)
        {
            var compound = ChemicalCompound.New(compoundSymbol);

            Assert.Equal(compound.GetTotalElectronsCount(), electrons);
            Assert.Equal(compound.GetTotalNeutronsCount(), neutrons);
            Assert.Equal(compound.GetTotalProtonsCount(), protons);
            Assert.Equal(compound.GetAtoms().Count(), atoms);
        }
コード例 #5
0
        public virtual string Write(ChemicalCompound input)
        {
            var builder = new StringBuilder();

            if (input.StructureTree.Count > 1)
            {
                builder.Append(input.StructureTree.Count);
            }

            WriteTree(builder, input.StructureTree);
            return(builder.ToString());
        }
コード例 #6
0
        public virtual ChemicalCompound Read(string input)
        {
            var compound = new ChemicalCompound(input);

            compound.StructureTree.IncreaseStackSize();

            InnerStacks.Clear();
            InnerStacks.Push(compound.StructureTree);

            var index = 0;

            ReadTree(input, compound.StructureTree, ref index);

            return(compound);
        }
コード例 #7
0
        public void Should_contain_phenyl_group(string compoundSymbol, bool hasPhenylGroup)
        {
            var compound = ChemicalCompound.New(compoundSymbol);

            Assert.Equal(compound.HasPhenylGroup, hasPhenylGroup);
        }
コード例 #8
0
        public void Should_contain_hydroxy_group(string compoundSymbol, bool hasHydroxyGroup)
        {
            var compound = ChemicalCompound.New(compoundSymbol);

            Assert.Equal(compound.HasHydroxyGroup, hasHydroxyGroup);
        }
コード例 #9
0
        public void Should_be_an_organic_compound(string compoundSymbol, bool isOrganic)
        {
            var compound = ChemicalCompound.New(compoundSymbol);

            Assert.Equal(compound.IsOrganic, isOrganic);
        }