60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
using bts.api;
|
|
using bts.collections;
|
|
using bts.resources;
|
|
using bts.test;
|
|
using bts.utils.proto;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace bts.mcore {
|
|
[TestGroup]
|
|
class SecurityTests {
|
|
[Test]
|
|
public void test_security_equal() {
|
|
SecurityImmutable a = new SecurityImmutable(new Security() { Id = 42 });
|
|
SecurityImmutable b = new SecurityImmutable(new Security() { Id = 42 });
|
|
SecurityImmutable c = new SecurityImmutable(new Security() { Id = 4 });
|
|
|
|
Assert.IsTrue(a == b);
|
|
Assert.IsTrue(a.Equals(b));
|
|
Assert.IsFalse(a == c);
|
|
Assert.IsFalse(a.Equals(c));
|
|
|
|
Dictionary<SecurityImmutable, int> dict = new Dictionary<SecurityImmutable, int>();
|
|
dict[a] = 1;
|
|
dict[c] = 2;
|
|
Assert.That(dict[b] == 1);
|
|
Assert.That(dict[c] == 2);
|
|
}
|
|
|
|
[Test]
|
|
public void test_security_compare() {
|
|
foreach (var file_path in SecurityFiles.all())
|
|
_test_security_compare(_read_securities(file_path));
|
|
}
|
|
|
|
void _test_security_compare(IEnumerable<SecurityImmutable> securities) {
|
|
const int max_count = 2048;
|
|
var sec_list = securities as IList<SecurityImmutable> ?? securities.ToList();
|
|
if (sec_list.Count > max_count)
|
|
sec_list = sec_list.WrapSubRange(0, max_count);
|
|
ComparisonTests.transitive_comparison(sec_list, SecurityHelper.Comparer.InstanceImmutable);
|
|
ComparisonTests.identity_comparison(sec_list, SecurityHelper.Comparer.InstanceImmutable);
|
|
}
|
|
|
|
IEnumerable<SecurityImmutable> _read_securities(string file_path) =>
|
|
StreamHelper.ReadProtos<Security>(ResourceHelper.LoadResource(file_path)).Select(s => new SecurityImmutable(s));
|
|
|
|
static class SecurityFiles {
|
|
public const string
|
|
KrandallOrderBookCrash = "KrandallOrderBookCrash.security_proto",
|
|
NonDeterministicICEFutures = "NonDeterministicICEFutures.security_proto";
|
|
|
|
public static IEnumerable<string> all() {
|
|
yield return KrandallOrderBookCrash;
|
|
yield return NonDeterministicICEFutures;
|
|
}
|
|
}
|
|
}
|
|
}
|