Saxonite 1.2.11.8

This commit is contained in:
Andy Howard
2024-06-17 11:48:16 +01:00
parent 7eb7dc55d6
commit 903d386617
2 changed files with 78 additions and 1 deletions
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Sarand.Net.Standard.Base.Utils;
namespace Sarand.UnitTests.Core.Base.Utils
{
[TestClass]
public class ListUtil_Tester
{
//-------------------------------------------------------------------
// Data members.
//-------------------------------------------------------------------
// Is Empty.
//-------------------------------------------------------------------
[TestMethod]
public void ListUtil_IsEmpty_Test()
{
List<String> values = new List<string>();
Assert.AreEqual(true, ListUtil.IsEmpty(values));
Assert.AreEqual(true, values.IsEmpty());
for (int i = 0; i < 10; i++)
values.Add(i.ToString());
Assert.AreEqual(false, ListUtil.IsEmpty(values));
Assert.AreEqual(false, values.IsEmpty());
values.Clear();
Assert.AreEqual(true, ListUtil.IsEmpty(values));
Assert.AreEqual(true, values.IsEmpty());
}
//-------------------------------------------------------------------
// Randomise.
//-------------------------------------------------------------------
[TestMethod]
public void ListUtil_Randomise_Test()
{
// Assume that randomising a list of 100 values highly unlikely to result in same sequence!
int itemsInList = 100;
int testsToRun = 1000;
for (int testIdx = 0; testIdx < testsToRun; testIdx++)
{
// Initialise list with sequence.
List<String> values = new List<string>();
for (int i = 0; i < itemsInList; i++)
values.Add(i.ToString());
for (int i = 0; i < itemsInList; i++)
Assert.AreEqual(i.ToString(), values[i]);
values = values.Randomise();
//Debug.WriteLine($"{SysUtil.Fn} Values: {values.Concat(",")}");
bool originalSequence = true;
for (int i = 0; i < itemsInList; i++)
{
if (values[i] != i.ToString())
{
originalSequence = false;
break;
}
}
Assert.AreEqual(false, originalSequence);
}
}
//-------------------------------------------------------------------
}
}
+1 -1
View File
@@ -24,7 +24,7 @@ namespace Sarand.Net.Standard.Base.Utils
/// <summary>Is the list empty</summary> /// <summary>Is the list empty</summary>
public static Boolean IsEmpty<T>(this IEnumerable<T> items) public static Boolean IsEmpty<T>(this IEnumerable<T> items)
{ {
return items.Count() == 0; return !items.Any();
} }
//------------------------------------------------------------------- //-------------------------------------------------------------------