forked from SciSharp/NumSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestClass.cs
More file actions
44 lines (40 loc) · 1.99 KB
/
TestClass.cs
File metadata and controls
44 lines (40 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NumSharp.Backends.Unmanaged;
namespace NumSharp.UnitTest
{
public class TestClass
{
public void AssertAreEqual(object expected, object given, string msg = null)
{
if (expected is string)
Assert.AreEqual(expected, given, msg ?? $"Expected '{expected}', given '{given}'");
else if (expected is Array && given is Array)
AssertSequenceEqual(expected as Array, given as Array);
else if (expected is ICollection && given is ICollection)
AssertSequenceEqual(expected as ICollection, given as ICollection);
else if (expected is IArraySlice && given is IArraySlice)
AssertSequenceEqual((expected as IArraySlice).ToArray(), (given as IArraySlice).ToArray());
else if (expected is IArraySlice && given is Array)
AssertSequenceEqual((expected as IArraySlice).ToArray(), given as Array);
else if (expected is Array && given is IArraySlice)
AssertSequenceEqual((expected as Array), (given as IArraySlice).ToArray());
else
Assert.AreEqual(expected, given, msg ?? $"Expected '{expected}', given '{given}'");
}
private void AssertSequenceEqual(ICollection a, ICollection b)
{
AssertSequenceEqual(a.OfType<object>().ToArray(), b.OfType<object>().ToArray());
}
private void AssertSequenceEqual(Array a, Array b)
{
Assert.AreEqual(a.Length, b.Length, $"Arrays are not of same length. Expected '{a.Length}', given '{b.Length}'");
for (int i = 0; i < a.Length; i++)
AssertAreEqual(a.GetValue(i), b.GetValue(i), $"Elements at index {i} differ. Expected '{a.GetValue(i)}', given '{b.GetValue(i)}'");
}
}
}