Created
October 18, 2012 18:01
-
-
Save handcraftsman/3913788 to your computer and use it in GitHub Desktop.
sample code breaker
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
// this breaker was used on @scichelli's | |
// collection comparer | |
// https://gist.github.com/3836918/ | |
[Test] | |
public void Breaker() | |
{ | |
var legal = GetIntLegals(); | |
for (int i = 0; i < 1000000; i++) | |
{ | |
var expected = legal | |
.Concat(legal) | |
.Shuffle() | |
.Take(4) | |
.Concat(new[] { "...", "..." }.Random(1, 2)) | |
.Shuffle() | |
.ToArray(); | |
var actual = expected.Select(x => x == "..." ? legal.Random(0, 3) : new[] { x }) | |
.SelectMany(x => x) | |
.ToArray(); | |
var expectedText = " var expected = new[] { \"" + String.Join("\", \"", expected) + "\" };"; | |
var actualText = " var actual = new[] { \"" + String.Join("\", \"", actual) + "\" };"; | |
try | |
{ | |
AssertStructure(actual, expected); | |
} | |
catch (Exception exception) | |
{ | |
Console.WriteLine("Broke it with:" + exception.Message); | |
Console.WriteLine(expectedText); | |
Console.WriteLine(actualText); | |
break; | |
} | |
} | |
} | |
public IList<string> GetIntLegals() | |
{ | |
return "1234567890".Select(x => "" + x).ToList(); | |
} | |
public IList<string> GetIntLetterLegals() | |
{ | |
var legal1 = "1234567890".Select(x => "" + x).ToList(); | |
var legal2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".Select(x => "" + x).ToList(); | |
var legal = (from n in legal1 | |
from m in legal2 | |
select n + m).ToList(); | |
return legal; | |
} | |
public IList<string> GetVisibleTextLegals() | |
{ | |
var legal = @"qwertyuiop[]\asdfghjkl;'zxcvbnm,./`1234567890-=~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:""ZXCVBNM<>?".Select(x => "" + x).ToList(); | |
return legal; | |
} |
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
public static class Extensions | |
{ | |
private static readonly Random Rnd = new Random(); | |
public static IList<T> Random<T>(this IEnumerable<T> list, int min, int max) | |
{ | |
var items = list.ToList(); | |
var rand = Rnd.Next(min, max + 1); | |
return items.Shuffle().Take(rand).ToArray(); | |
} | |
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> list) | |
{ | |
var toreturn = new List<T>(list); | |
for (var i = 1; i < toreturn.Count; i++) | |
{ | |
var pos = Rnd.Next(i + 1); | |
var x = toreturn[i]; | |
toreturn[i] = toreturn[pos]; | |
toreturn[pos] = x; | |
} | |
return toreturn; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment