From 455a0d0b46007c0c7992a3126525b94df16a2da1 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 30 Jun 2020 05:44:34 -0700 Subject: [PATCH] More tests --- IDEHelper/Tests/src/Generics.bf | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/IDEHelper/Tests/src/Generics.bf b/IDEHelper/Tests/src/Generics.bf index 4e087acd..5b4d0167 100644 --- a/IDEHelper/Tests/src/Generics.bf +++ b/IDEHelper/Tests/src/Generics.bf @@ -1,4 +1,5 @@ using System; +using System.Collections; namespace Tests { @@ -120,5 +121,30 @@ namespace Tests float totals = GetSum(fVals); Test.Assert(totals == 10+20+30+40+50); } + + public static mixin TransformArray(Input[InputSize] array, delegate void(Input, ref Output) predicate) where InputSize : const int where Output : new + { + Output[2] output = default; + for (int i = 0; i < array.Count; i++) + { + output[i] = scope:mixin Output(); + predicate(array[i], ref output[i]); + } + output + } + + [Test] + public static void TestSizedArrays() + { + int[2] arr = .(2, 4); + + delegate void(int, ref String) toString = scope (i, str) => { i.ToString(str); }; + + List l2 = scope .(); + l2.Add(TransformArray!(arr, toString)); + + Test.Assert(l2.Front[0] == "2"); + Test.Assert(l2.Front[1] == "4"); + } } }