public void MassTest() { // Using simple 100% abundances var provider = new MockElementProvider(); provider.OverwriteElement(new Element(1, "H", new[] { new Isotope(1, 0, 1.0) })); provider.OverwriteElement(new Element(8, "O", new[] { new Isotope(16, 8, 1.0) })); var formula = ChemicalFormula.Water(provider); var elements = formula.GetElements(); Assert.AreEqual(18, formula.GetMass(MassType.Monoisotopic)); Assert.AreEqual(18, formula.GetMass(MassType.Average)); // Switch to 75/25 provider.OverwriteElement(new Element(8, "O", new[] { new Isotope(16, 8, 0.75), new Isotope(17, 9, 0.25) })); formula = ChemicalFormula.Water(provider); elements = formula.GetElements(); Assert.AreEqual(18, formula.GetMass(MassType.Monoisotopic)); Assert.AreEqual(18.25, formula.GetMass(MassType.Average)); }
public void ChemicalFormulaCompareTest() { var provider = new MockElementProvider(); var formula = ChemicalFormula.Water(provider); var formula2 = ChemicalFormula.Water(provider); IElement h = provider.GetElement("H"); IElement o = provider.GetElement("O"); var formula3 = new ChemicalFormula(new[] { new EntityCardinality <IElement>(h, 1), new EntityCardinality <IElement>(o, 2), }); Assert.AreEqual(formula, formula2); Assert.AreNotEqual(formula, formula3); // Equality when element object is different. IElement anotherH = new Element(1, "H", h.Isotopes); IElement anotherO = new Element(1, "O", o.Isotopes); ChemicalFormula formula4 = new ChemicalFormula(new[] { new EntityCardinality <IElement>(anotherH, 2), new EntityCardinality <IElement>(anotherO, 1), }); Assert.IsTrue(formula.Equals(formula4)); Assert.IsTrue(formula2.Equals(formula4)); Assert.IsFalse(formula3.Equals(formula4)); }
public void MulticharacterElementParseTest() { string formulaString = "He2O"; var chemicalFormula = this.SimpleParseTest(formulaString, new[] { Tuple.Create("He", 2), Tuple.Create("O", 1) }); Assert.AreNotEqual(ChemicalFormula.Water(_elementProvider), chemicalFormula); }
public void WaterTest() { IElementProvider provider = new MockElementProvider(); IElement h = provider.GetElement("H"); IElement o = provider.GetElement("O"); var formula = ChemicalFormula.Water(provider); var elements = formula.GetElements(); Assert.AreEqual(2, elements.Count); Assert.AreEqual(2, elements.Single(x => x.Entity.Symbol == "H").Count); Assert.AreEqual(1, elements.Single(x => x.Entity.Symbol == "O").Count); Assert.AreEqual(h.Isotopes.FirstWithMax(x => x.RelativeAbundance).AtomicMass * 2 + o.Isotopes.FirstWithMax(x => x.RelativeAbundance).AtomicMass, formula.GetMass(MassType.Monoisotopic)); Assert.AreEqual(h.Isotopes.Sum(x => x.AtomicMass * x.RelativeAbundance) * 2 + o.Isotopes.Sum(x => x.AtomicMass * x.RelativeAbundance), formula.GetMass(MassType.Average)); }