-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
260 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/// <summary> | ||
/// Author: Krzysztof Dobrzyński | ||
/// Project: Chemistry.NET | ||
/// Source: https://github.com/Sejoslaw/Chemistry.NET | ||
/// </summary> | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Chemistry.NET.Common; | ||
using Chemistry.NET.Compounds.Collections; | ||
using Chemistry.NET.Compounds.Models; | ||
using Xunit; | ||
|
||
namespace Chemistry.NET.Tests | ||
{ | ||
public class ChemicalStackTests | ||
{ | ||
[Fact] | ||
public void Should_calculate_electrons_neutrons_protons_for_ElementStack() | ||
{ | ||
foreach (var element in Container.Elements) | ||
{ | ||
var randomElementNumberOnStack = new Random().Next(); | ||
var stack = new ElementStack(element, randomElementNumberOnStack); | ||
|
||
Assert.Equal(stack.GetTotalElectronsCount(), element.Structure.ElectronsCount * randomElementNumberOnStack); | ||
Assert.Equal(stack.GetTotalNeutronsCount(), element.Structure.NeutronsCount * randomElementNumberOnStack); | ||
Assert.Equal(stack.GetTotalProtonsCount(), element.Structure.ProtonsCount * randomElementNumberOnStack); | ||
Assert.Equal(stack.GetAtoms().Count(), 1); | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData("H2O", 10, 8, 10, 2)] | ||
[InlineData("H2O2", 18, 16, 18, 2)] | ||
[InlineData("H(CH2)4", 33, 24, 33, 2)] | ||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/// <summary> | ||
/// Author: Krzysztof Dobrzyński | ||
/// Project: Chemistry.NET | ||
/// Source: https://github.com/Sejoslaw/Chemistry.NET | ||
/// </summary> | ||
|
||
using Chemistry.NET.Compounds.Models; | ||
using Xunit; | ||
|
||
namespace Chemistry.NET.Tests | ||
{ | ||
public class MoleculeTests | ||
{ | ||
[Theory] | ||
[InlineData("H2", true, false, true)] | ||
[InlineData("H2O", false, true, false)] | ||
[InlineData("CHO", false, true, false)] | ||
[InlineData("CH(CH2)4", false, true, false)] | ||
[InlineData("CH", false, true, true)] | ||
[InlineData("CH(CH2Li3)4", false, true, false)] | ||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/// <summary> | ||
/// Author: Krzysztof Dobrzyński | ||
/// Project: Chemistry.NET | ||
/// Source: https://github.com/Sejoslaw/Chemistry.NET | ||
/// </summary> | ||
|
||
namespace Chemistry.NET.Molecules | ||
{ | ||
/// <summary> | ||
/// Describes an object to be a Molecule. | ||
/// </summary> | ||
public interface IMolecule | ||
{ | ||
/// <summary> | ||
/// Homonuclear molecules are molecules composed of only one type of element. | ||
/// Homonuclear molecules may consist of various numbers of atoms, depending on the element's properties. | ||
/// </summary> | ||
/// <value></value> | ||
bool IsHomonuclear { get; } | ||
/// <summary> | ||
/// A heteronuclear molecule is a molecule composed of atoms of more than one chemical element. | ||
/// </summary> | ||
/// <value></value> | ||
bool IsHeteronuclear { get; } | ||
/// <summary> | ||
/// Diatomic molecules are molecules composed of only two atoms, of the same or different chemical elements. | ||
/// </summary> | ||
/// <value></value> | ||
bool IsDiatomic { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/// <summary> | ||
/// Author: Krzysztof Dobrzyński | ||
/// Project: Chemistry.NET | ||
/// Source: https://github.com/Sejoslaw/Chemistry.NET | ||
/// </summary> | ||
|
||
using System.Linq; | ||
using Chemistry.NET.Molecules; | ||
|
||
namespace Chemistry.NET.Compounds.Models | ||
{ | ||
public partial class ChemicalCompound : IMolecule | ||
{ | ||
public bool IsHomonuclear => this.GetAtoms().Count() == 1; | ||
public bool IsHeteronuclear => this.GetAtoms().Count() > 1; | ||
public bool IsDiatomic | ||
{ | ||
get | ||
{ | ||
var atoms = this.GetAtoms(); | ||
return (atoms.Count() == 1 && atoms.ElementAt(0).Count == 2) || | ||
(atoms.Count() == 2 && atoms.ElementAt(0).Count == 1 && atoms.ElementAt(1).Count == 1); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters