private static void Main(string[] args) { Console.WriteLine("Please enter a valid number to generate series"); string input = Console.ReadLine(); int count; if (!int.TryParse(input, out count)) { Console.WriteLine("Invalid number entered. Please press any key to exit"); Console.Read(); return; } // Default series var defalutSeries = new GenerateSeries(20); foreach (var item in defalutSeries.GetSeries()) Console.WriteLine(item); //specific series var rules = new Dictionary<int, string>() { {5, "Seven"}, {7, "Nine"}, {20, "Twenty"} }; var specificSeries = new GenerateSeries(50, rules); foreach (var item in specificSeries.GetSeries()) Console.WriteLine(item); Console.Read(); }
public void Generate_UpperLimit_Test() { var limit = 100000; GenerateSeries series = new GenerateSeries(limit) ; //Assert.Throws<InvalidOperationException>(() => series =new GenerateSeries(limit)); }
public void GenerateSeries_Count_Test() { var limit = 30; var series = new GenerateSeries(limit); var actual = series.GetSeries(); Assert.AreEqual(limit, actual.Count); }
public void GenerateSeries_Default_Series_Test() { var limit = 20; var series = new GenerateSeries(limit); var actual = series.GetSeries(); CollectionAssert.AreEqual(new int[] {0,10,12,13,15,16,18}, actual.Select((a, i) => i).Where(i => actual[i].StartsWith("1")).ToArray()); CollectionAssert.AreEqual( new int[] {2,5,8,11,17}, actual.Select((a, i) => i).Where(i => actual[i].Equals("Fizz")).ToArray()); CollectionAssert.AreEqual(new int[] {4,9,19}, actual.Select((a, i) => i).Where(i => actual[i].Equals("Buzz")).ToArray()); CollectionAssert.AreEqual(new int[] { 14 }, actual.Select((a, i) => i).Where(i => actual[i].Equals("FizzBuzz")).ToArray()); }
public void GenerateSeries_Custom_Series_test() { var rules = new Dictionary<int,string>() { {7,"Seven" }, {9, "Nine" }, {20,"Twenty" } }; var limit = 50; var series = new GenerateSeries(limit,rules); var actual = series.GetSeries(); CollectionAssert.AreEqual(new int[] {1,21,22,23,24,25,28}, actual.Select((a, i) => i).Where(i => actual[i].StartsWith("2")).ToArray()); CollectionAssert.AreEqual(new int[] {6,13,20,27,34,41,48 }, actual.Select((a, i) => i).Where(i => actual[i].Equals("Seven")).ToArray()); CollectionAssert.AreEqual(new int[] { 8,17,26,35,44 }, actual.Select((a, i) => i).Where(i => actual[i].Equals("Nine")).ToArray()); CollectionAssert.AreEqual(new int[] { 19,39 }, actual.Select((a, i) => i).Where(i => actual[i].Equals("Twenty")).ToArray()); }