Created
June 4, 2014 21:39
-
-
Save DForshner/5c14553bf70b00fc6c82 to your computer and use it in GitHub Desktop.
Returns true if there are any true values in an array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class BoolExtensions | |
| { | |
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | |
| [DebuggerStepThrough] | |
| public static bool AnyTrue(this IEnumerable<bool> bools) | |
| { | |
| return bools.Aggregate((a, b) => (a || b)); | |
| } | |
| } | |
| [TestClass] | |
| public class BoolExtensionsTests | |
| { | |
| [TestMethod] | |
| public void AnyTrue_WhenNoTrue_ExpectFalse() | |
| { | |
| var bools = new bool[] { false, false, false, false, false }; | |
| Assert.IsFalse(bools.AnyTrue()); | |
| } | |
| [TestMethod] | |
| public void AnyTrue_WhenLastTrue_ExpectTrue() | |
| { | |
| var bools = new bool[] { false, false, false, false, true }; | |
| Assert.IsTrue(bools.AnyTrue()); | |
| } | |
| [TestMethod] | |
| public void AnyTrue_WhenFirstTrue_ExpectTrue() | |
| { | |
| var bools = new bool[] { false, false, false, false, true }; | |
| Assert.IsTrue(bools.AnyTrue()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment