Initial commit

This commit is contained in:
KäseToatz
2024-10-16 21:34:23 +02:00
commit 8d5e03d0df
9 changed files with 651 additions and 0 deletions

58
Tests/TestUtils.cs Normal file
View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace BAI
{
public class TestUtils
{
// ------------------------------------------------------------
// Maakt een lijst op basis van een string.
// Getallen zijn ints, gescheiden door spaties
// ------------------------------------------------------------
public static List<int> IntListFromString(string str)
{
List<int> list = new List<int>();
if (str.Length > 0)
list = str.Split(" ").Select(Int32.Parse).ToList();
return list;
}
// ------------------------------------------------------------
// Maakt een lijst op basis van een string.
// Getallen zijn uints, gescheiden door spaties
// ------------------------------------------------------------
public static List<uint> UIntListFromString(string str)
{
List<uint> list = new List<uint>();
if (str.Length > 0)
list = str.Split(" ").Select(uint.Parse).ToList();
return list;
}
// ------------------------------------------------------------
// Maakt een string van een Enumerable.
// De enumerable kan eventueel gesorteerd worden (handig voor
// sets).
// ------------------------------------------------------------
public static string EnumToString<T>(IEnumerable<T> lst, bool sort = false)
{
List<T> lst2 = new List<T>(lst);
if (sort)
lst2.Sort();
return String.Join(" ", lst2);
}
// ------------------------------------------------------------
// Maakt een string van een Enumerable.
// Lijst wordt gesorteerd (handig voor vergelijken van sets).
// ------------------------------------------------------------
public static string EnumSortedToString<T>(IEnumerable<T> lst)
{
return EnumToString(lst, true);
}
}
}