Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit ec75870f authored by Michael KRISPER's avatar Michael KRISPER
Browse files

moved IEnumerable.ZipAll to Utils

parent 540b55f7
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,24 @@ namespace TUGraz.VectoCore.Utils
yield return item;
}
public static IEnumerable<TResult> ZipAll<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first,
IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
{
var firstEnum = first.GetEnumerator();
var secondEnum = second.GetEnumerator();
while (true) {
var firstHadNext = firstEnum.MoveNext();
var secondHadNext = secondEnum.MoveNext();
if (firstHadNext && secondHadNext) {
yield return resultSelector(firstEnum.Current, secondEnum.Current);
} else if (firstHadNext != secondHadNext) {
throw new IndexOutOfRangeException("The argument enumerables must have the same length.");
} else {
yield break;
}
}
}
public static T Sum<T>(this IEnumerable<T> list) where T : SIBase<T>
{
return list.Aggregate((sum, current) => sum + current);
......
......@@ -50,6 +50,9 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation
container.FinishSimulation();
sumWriter.Finish();
Assert.Inconclusive();
}
......
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Tests.Utils
{
......@@ -15,24 +15,6 @@ namespace TUGraz.VectoCore.Tests.Utils
TestModFiles(new[] { expectedFile }, new[] { actualFile });
}
public static IEnumerable<TResult> ZipAll<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first,
IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
{
var firstEnum = first.GetEnumerator();
var secondEnum = second.GetEnumerator();
while (true) {
var firstHadNext = firstEnum.MoveNext();
var secondHadNext = secondEnum.MoveNext();
if (firstHadNext && secondHadNext) {
yield return resultSelector(firstEnum.Current, secondEnum.Current);
} else if (firstHadNext != secondHadNext) {
throw new IndexOutOfRangeException("The argument enumerables must have the same length.");
} else {
yield break;
}
}
}
public static void TestModFiles(IEnumerable<string> expectedFiles, IEnumerable<string> actualFiles)
{
var resultFiles = expectedFiles.ZipAll(actualFiles, (expectedFile, actualFile) => new { expectedFile, actualFile });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment