Skip to content

Commit

Permalink
Expanded test coverage on file classes
Browse files Browse the repository at this point in the history
  • Loading branch information
nbollis committed Nov 16, 2023
1 parent d0a55b2 commit 81f9338
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
7 changes: 2 additions & 5 deletions mzLib/Readers/SearchResults/PsmFromTsvFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ namespace Readers;

public class PsmFromTsvFile : ResultFile<PsmFromTsv>, IResultFile
{
public override SupportedFileType FileType { get; }
public override SupportedFileType FileType => SupportedFileType.psmtsv;
public override Software Software { get; set; }

/// <summary>
/// Constructor used to initialize from the factory method
/// </summary>
public PsmFromTsvFile() : base() { }

public PsmFromTsvFile(string filePath) : base(filePath, Software.MetaMorpheus)
{

}
public PsmFromTsvFile(string filePath) : base(filePath, Software.MetaMorpheus) { }

public override void LoadResults()
{
Expand Down
7 changes: 2 additions & 5 deletions mzLib/Readers/SearchResults/SpectrumMatchFromTsvFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ namespace Readers;

public class SpectrumMatchFromTsvFile : ResultFile<SpectrumMatchFromTsv>, IResultFile
{
public override SupportedFileType FileType { get; }
public override SupportedFileType FileType => FilePath.ParseFileType();
public override Software Software { get; set; }

/// <summary>
/// Constructor used to initialize from the factory method
/// </summary>
public SpectrumMatchFromTsvFile() : base() { }

public SpectrumMatchFromTsvFile(string filePath) : base(filePath, Software.MetaMorpheus)
{

}
public SpectrumMatchFromTsvFile(string filePath) : base(filePath, Software.MetaMorpheus) { }

public override void LoadResults()
{
Expand Down
51 changes: 51 additions & 0 deletions mzLib/Test/FileReadingTests/TestPsmFromTsv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,56 @@ public static void TestSimpleToLibrarySpectrum()

Assert.That(librarySpectrumWithNeutralLoss.Contains("WaterLoss"));
}

[Test]
[TestCase("FileReader - PsmFromTsv")]
[TestCase("FileReader - SpectrumMatchFromTsv")]
[TestCase("File Construction - PsmFromTsv")]
[TestCase("File Construction - SpectrumMatchFromTsv")]
public static void TestPsmFiles(string fileLoadingType)
{
string psmTsvPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"FileReadingTests\SearchResults\TDGPTMDSearchResults.psmtsv");
List<PsmFromTsv> psms = SpectrumMatchTsvReader.ReadPsmTsv(psmTsvPath, out var warnings);
Assert.That(warnings.Count == 2);

IResultFile loadedFile = null;
switch (fileLoadingType)
{
case "FileReader - PsmFromTsv":
var file = FileReader.ReadFile<PsmFromTsvFile>(psmTsvPath);
file.LoadResults();
Assert.That(file.Results.Count == psms.Count);
loadedFile = file;
break;

case "FileReader - SpectrumMatchFromTsv":
var file2 = FileReader.ReadFile<SpectrumMatchFromTsvFile>(psmTsvPath);
file2.LoadResults();
Assert.That(file2.Results.Count == psms.Count);
loadedFile = file2;
break;

case "File Construction - PsmFromTsv":
var file3 = new PsmFromTsvFile(psmTsvPath);
file3.LoadResults();
Assert.That(file3.Results.Count == psms.Count);
loadedFile = file3;
break;

case "File Construction - SpectrumMatchFromTsv":
var file4 = new SpectrumMatchFromTsvFile(psmTsvPath);
file4.LoadResults();
Assert.That(file4.Results.Count == psms.Count);
loadedFile = file4;
break;

default:
Assert.Fail();
break;
}

Assert.That(loadedFile.FileType == SupportedFileType.psmtsv);
Assert.Throws<NotImplementedException>(() => { loadedFile.WriteResults(""); });
}
}
}

0 comments on commit 81f9338

Please sign in to comment.