public bool IndexFindProp(int el, List <int> xs) { FSharpFunc <int, bool> predFs = (Converter <int, bool>)(e => el == e); var funcsIdxL = new Func <int, List <int>, int>[] { Seqops.IndexOfLp, (el1, xs1) => SequenceopsFs.findIndexSeqI(predFs, xs1) }; var funcsFndL = new Func <int, List <int>, int>[] { Seqops.FindLp }; var funcsIdxA = new Func <int, int[], int>[] { SeqopsArr.IndexOfLp }; var funcsFndA = new Func <int, int[], int>[] { SeqopsArr.FindLp }; var ansIdx = xs.IndexOf(el); var ansFnd = xs.Find(e => el == e); return(funcsIdxL.Aggregate(true, (acc, f) => acc && ansIdx == f(el, xs)) && funcsFndL.Aggregate(true, (acc, f) => acc && ansFnd == f(el, xs)) && funcsIdxA.Aggregate(true, (acc, f) => acc && ansIdx == f(el, xs.ToArray())) && funcsFndA.Aggregate(true, (acc, f) => acc && ansFnd == f(el, xs.ToArray()))); }
public void IndexFindTest() { int el = 3; FSharpFunc <int, bool> predFs = (Converter <int, bool>)(e => el == e); var funcsIdxL = new Func <int, List <int>, int>[] { Seqops.IndexOfLp, (el1, xs) => SequenceopsFs.findIndexSeqI(predFs, xs) }; var funcsFndL = new Func <int, List <int>, int>[] { Seqops.FindLp }; var funcsIdxA = new Func <int, int[], int>[] { SeqopsArr.IndexOfLp }; var funcsFndA = new Func <int, int[], int>[] { SeqopsArr.FindLp }; int n = 5; List <int>[] lsts = { Enumerable.Range(0, n).ToList(), Enumerable.Range(0, n).Reverse().ToList() }; foreach (var lst in lsts) { foreach (var f in funcsIdxL) { Assert.AreEqual(lst.IndexOf(el), f(el, lst), "IndexOfTestL"); } foreach (var f in funcsFndL) { Assert.AreEqual(lst.Find(e => el == e), f(el, lst), "FindTestL"); } foreach (var f in funcsIdxA) { Assert.AreEqual(lst.IndexOf(el), f(el, lst.ToArray()), "IndexOfTestA"); } foreach (var f in funcsFndA) { Assert.AreEqual(lst.Find(e => el == e), f(el, lst.ToArray()), "FindTestA"); } } }