Skip to content

Commit

Permalink
Even more equality tetsts
Browse files Browse the repository at this point in the history
  • Loading branch information
nbollis committed Dec 17, 2024
1 parent 9e4eb68 commit c9cbfa2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
15 changes: 14 additions & 1 deletion mzLib/Test/TestPeptideWithSetMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public static void TestPeptideOligoEquality()
Assert.That(!peptide.Equals(oligo));
Assert.That(!((IBioPolymerWithSetMods)oligo).Equals(peptide));
Assert.That(!((IBioPolymerWithSetMods)peptide).Equals(oligo));
Assert.That(!((object)oligo).Equals(peptide));
Assert.That(!((object)peptide).Equals(oligo));
}

[Test]
Expand Down Expand Up @@ -1208,9 +1210,13 @@ public static void TestPeptideWithSetModsEquals()
PeptideWithSetModifications peptide1 = protein1.Digest(digestionParams, new List<Modification>(), new List<Modification>()).First();
PeptideWithSetModifications peptide2 = protein2.Digest(digestionParams, new List<Modification>(), new List<Modification>()).First();

// Test equality
// Test equality - same peptide
Assert.IsTrue(peptide1.Equals(peptide1));

// different peptide
Assert.IsTrue(!peptide1.Equals(peptide2));
Assert.IsTrue(!peptide1.Equals((object)peptide2));
Assert.IsTrue(!peptide1.Equals((IBioPolymerWithSetMods)peptide2));
Assert.AreNotEqual(peptide1.GetHashCode(), peptide2.GetHashCode());

// Test inequality with different start residue
Expand All @@ -1220,8 +1226,15 @@ public static void TestPeptideWithSetModsEquals()
// Test inequality with different parent accession
PeptideWithSetModifications peptide4 = new PeptideWithSetModifications(protein2, digestionParams, 1, 9, CleavageSpecificity.Full, "", 0, new Dictionary<int, Modification>(), 0);
Assert.IsFalse(peptide1.Equals(peptide4));

// all fail on null
Assert.That(!peptide1.Equals(null));
Assert.That(!peptide1.Equals((object)null));
Assert.That(!peptide1.Equals((PeptideWithSetModifications)null));
}



[Test]
public static void TestIBioPolymerWithSetModsModificationFromFullSequence()
{
Expand Down
28 changes: 20 additions & 8 deletions mzLib/Test/Transcriptomics/TestOligoWithSetMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,34 @@ public static void TestEquality()
.Digest(new RnaDigestionParams(), [], [])
.ElementAt(1);

Assert.That(oligoWithSetMods, Is.EqualTo(oligoWithSetMods2));
// same oligos
Assert.That(oligoWithSetMods.Equals(oligoWithSetMods2));
Assert.That(oligoWithSetMods.Equals((object)oligoWithSetMods2));
Assert.That(oligoWithSetMods.Equals((OligoWithSetMods)oligoWithSetMods2));
Assert.That(oligoWithSetMods.Equals(oligoWithSetMods));
Assert.That(oligoWithSetMods.Equals((object)oligoWithSetMods));
Assert.That(oligoWithSetMods.Equals((OligoWithSetMods)oligoWithSetMods));
Assert.That(oligoWithSetMods.GetHashCode(), Is.EqualTo(oligoWithSetMods2.GetHashCode()));
Assert.That(oligoWithSetMods.Equals((object)oligoWithSetMods2)); // Test the Equals(Object obj) method

// all fail on null
Assert.That(!oligoWithSetMods2.Equals(null));
Assert.That(!oligoWithSetMods2.Equals((object)null));
Assert.That(!oligoWithSetMods2.Equals((OligoWithSetMods)null));

// Null parent checks
oligoWithSetMods = new(oligoWithSetMods.FullSequence, modDict.ToDictionary(p => p.Value.First().IdWithMotif, p => p.Value.First()));
oligoWithSetMods2 = new OligoWithSetMods(oligoWithSetMods.FullSequence, modDict.ToDictionary(p => p.Value.First().IdWithMotif, p => p.Value.First()));
var oligoWithSetMods3 = new OligoWithSetMods(oligoWithSetMods.FullSequence + "AGAUA", modDict.ToDictionary(p => p.Value.First().IdWithMotif, p => p.Value.First()));

Assert.That(oligoWithSetMods, Is.EqualTo(oligoWithSetMods2));
Assert.That(oligoWithSetMods, Is.EqualTo((object)oligoWithSetMods2));
Assert.That(oligoWithSetMods, Is.EqualTo((OligoWithSetMods)oligoWithSetMods2));
Assert.That(oligoWithSetMods, Is.Not.EqualTo(oligoWithSetMods3));
Assert.That(oligoWithSetMods, Is.Not.EqualTo((object)oligoWithSetMods3));
Assert.That(oligoWithSetMods, Is.Not.EqualTo((IBioPolymerWithSetMods)oligoWithSetMods3));
// same oligo null parent
Assert.That(oligoWithSetMods.Equals(oligoWithSetMods2));
Assert.That(oligoWithSetMods.Equals((object)oligoWithSetMods2));
Assert.That(oligoWithSetMods.Equals((OligoWithSetMods)oligoWithSetMods2));

// different oligo null parent
Assert.That(!oligoWithSetMods.Equals(oligoWithSetMods3));
Assert.That(!oligoWithSetMods.Equals((object)oligoWithSetMods3));
Assert.That(!oligoWithSetMods.Equals((IBioPolymerWithSetMods)oligoWithSetMods3));
}

[Test]
Expand Down

0 comments on commit c9cbfa2

Please sign in to comment.