mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-13 11:44:57 +00:00
Adding TryLast extension methods
This commit is contained in:
@@ -3,7 +3,6 @@ using ICD.Common.Utils.Extensions;
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
namespace ICD.Common.Utils.Tests.Extensions
|
||||
{
|
||||
@@ -62,6 +61,41 @@ namespace ICD.Common.Utils.Tests.Extensions
|
||||
Assert.AreEqual(true, exists);
|
||||
}
|
||||
|
||||
[TestCase(1)]
|
||||
public void TryLastTest(int expected)
|
||||
{
|
||||
IEnumerable<int> sequence = Enumerable.Empty<int>();
|
||||
int result;
|
||||
bool exists = sequence.TryLast(out result);
|
||||
|
||||
Assert.AreEqual(0, result);
|
||||
Assert.AreEqual(false, exists);
|
||||
|
||||
sequence = new[] { expected };
|
||||
exists = sequence.TryLast(out result);
|
||||
|
||||
Assert.AreEqual(expected, result);
|
||||
Assert.AreEqual(true, exists);
|
||||
}
|
||||
|
||||
[TestCase(0)]
|
||||
[TestCase(1)]
|
||||
public void TryLastPredicateTest(int expected)
|
||||
{
|
||||
IEnumerable<int> sequence = Enumerable.Range(1, 10).Except(expected);
|
||||
int result;
|
||||
bool exists = sequence.TryLast(i => i == expected, out result);
|
||||
|
||||
Assert.AreEqual(0, result);
|
||||
Assert.AreEqual(false, exists);
|
||||
|
||||
sequence = new[] { expected };
|
||||
exists = sequence.TryLast(i => i == expected, out result);
|
||||
|
||||
Assert.AreEqual(expected, result);
|
||||
Assert.AreEqual(true, exists);
|
||||
}
|
||||
|
||||
[TestCase(0, 0)]
|
||||
[TestCase(1, 10)]
|
||||
public void TryElementAtTest(int index, int expected)
|
||||
|
||||
Reference in New Issue
Block a user