Created
November 30, 2015 07:13
-
-
Save adbre/df164b983b2dca5f9a26 to your computer and use it in GitHub Desktop.
This file contains 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
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using NUnit.Framework; | |
namespace TestPad | |
{ | |
public class Tests | |
{ | |
[Test] | |
public void NoWarning() | |
{ | |
var enumerable = new CustomDataSource("Miss Kaboo made possum pie"); | |
GivesNoWarning(enumerable); | |
Assert.That(enumerable.GetEnumeratorCalls, Is.EqualTo(1)); | |
} | |
[Test] | |
public void Warning() | |
{ | |
var enumerable = new CustomDataSource("Miss Kaboo made possum pie"); | |
GivesWarning(enumerable); | |
Assert.That(enumerable.GetEnumeratorCalls, Is.EqualTo(1)); | |
} | |
class CustomDataSource : IEnumerable<char> | |
{ | |
private string _data; | |
public CustomDataSource(string data) | |
{ | |
_data = data; | |
} | |
public int GetEnumeratorCalls { get; private set; } | |
public IEnumerator<char> GetEnumerator() | |
{ | |
GetEnumeratorCalls++; | |
return ((IEnumerable<char>)_data.ToCharArray()).GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return GetEnumerator(); | |
} | |
} | |
public IEnumerable<char> GivesWarning(IEnumerable<char> a) | |
{ | |
var b = a.Skip(5).ToList(); | |
var c = a.Take(5).ToList(); | |
var d = new List<char>(); | |
d.AddRange(b); | |
d.AddRange(c); | |
return c; | |
} | |
public IEnumerable<char> GivesNoWarning(IEnumerable<char> a) | |
{ | |
var b = new List<char>(); | |
var c = new List<char>(); | |
var d = "abcdefghuijklmnopqrstuvwxyz"; | |
b.AddRange(d.Where(ch => !a.Contains(ch))); | |
c = a.Where(ch => !b.Contains(ch)).ToList(); | |
return c; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment