Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better assert message for AllSetupAndCleanupMethodRunsTest
- Loading branch information
1 parent
adf72c1
commit b1baa71
Showing
2 changed files
with
32 additions
and
1 deletion.
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
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 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace BenchmarkDotNet.Tests.XUnit | ||
{ | ||
public static class SmartAssert | ||
{ | ||
public static void Equal<T>(IReadOnlyList<T> expected, IReadOnlyList<T> actual) | ||
{ | ||
Exception CreateException(string comment) | ||
{ | ||
var builder = new StringBuilder(); | ||
builder.AppendLine($"Failure ({comment})"); | ||
builder.AppendLine("*** Expected ***"); | ||
for (int i = 0; i < expected.Count; i++) | ||
builder.AppendLine($"[{i}]: {expected[i]}"); | ||
builder.AppendLine("*** Actual ***"); | ||
for (int i = 0; i < actual.Count; i++) | ||
builder.AppendLine($"[{i}]: {actual[i]}"); | ||
return new Exception(builder.ToString()); | ||
} | ||
|
||
if (expected.Count != actual.Count) | ||
throw CreateException("Length mismatch"); | ||
for (int i = 0; i < expected.Count; i++) | ||
if (!expected[i].Equals(actual[i])) | ||
throw CreateException($"Element mismatch (index={i})"); | ||
} | ||
} | ||
} |