1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-16 23:34:10 +02:00

Added comptype test

This commit is contained in:
Brian Fiete 2021-01-16 06:26:55 -08:00
parent 83069fa216
commit 8435caf340
8 changed files with 87 additions and 47 deletions

View file

@ -252,6 +252,34 @@ namespace Tests
return result;
}
struct DoublingEnumerator<TElem, TEnum> : IEnumerator<TElem>
where TElem : operator TElem + TElem
where TEnum : concrete, IEnumerator<TElem>
{
TEnum mEnum;
public this(TEnum e)
{
mEnum = e;
}
public Result<TElem> GetNext() mut
{
switch (mEnum.GetNext())
{
case .Ok(let val): return .Ok(val + val);
case .Err: return .Err;
}
}
}
static DoublingEnumerator<TElem, decltype(default(TCollection).GetEnumerator())> GetDoublingEnumerator<TCollection, TElem>(this TCollection it)
where TCollection: concrete, IEnumerable<TElem>
where TElem : operator TElem + TElem
{
return .(it.GetEnumerator());
}
[Test]
public static void TestBasics()
{
@ -306,6 +334,11 @@ namespace Tests
Test.Assert(MethodF(floatList) == 0);
Test.Assert(floatList.Sum((x) => x * 2) == 12);
var e = floatList.GetDoublingEnumerator();
Test.Assert(e.GetNext().Value == 2);
Test.Assert(e.GetNext().Value == 4);
Test.Assert(e.GetNext().Value == 6);
}
}