Skip to content

Instantly share code, notes, and snippets.

@eouw0o83hf
Created July 29, 2019 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eouw0o83hf/19aa24564067fbf7bdcb2321a4afc87b to your computer and use it in GitHub Desktop.
Save eouw0o83hf/19aa24564067fbf7bdcb2321a4afc87b to your computer and use it in GitHub Desktop.
CrAzYcAsE test extensions
using System;
using System.Linq;
using Xunit;
namespace Example.Tests
{
public static class TestExtensions
{
public static string ToCrAzYcAsE(this string input)
=> input
?.WithIndex()
?.Aggregate("", (acc, i) =>
acc + (i.Index % 2 == 0 ?
Char.ToUpper(i.Value) :
Char.ToLower(i.Value)
)
);
}
/// M E T A
/// E
/// T
/// A
public class TestExtensionsTests
{
[Fact]
public void ToCrAzYcAsE_gIvEnNuLl_ShOuLdReTuRnNuLl()
=> Assert.Null(TestExtensions.ToCrAzYcAsE(null));
[Theory]
[InlineData("flatearth")]
[InlineData("FLATEARTH")]
[InlineData("flatEARTH")]
public void ToCrAzYcAsE_sHoUlDcRaZyCaSeThEiNpUt(string input)
=> Assert.Equal("FlAtEaRtH", input.ToCrAzYcAsE());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment