Created
April 7, 2020 14:34
-
-
Save jasmin-mistry/a89913ca504713659a8fef07797cb919 to your computer and use it in GitHub Desktop.
recursive test c#
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
[Test] | |
public void Test() | |
{ | |
var str = "{\"start\":123,\"rows\":213,\"query\":{\"$eq\":[\"template\",\"Catalogue Allocation\"]},\"parentQuery\":{\"4\":{\"$eq\":[\"recordid\",\"65570\"]}}}"; | |
//var m = Regex.Matches(str,"\"(?<key>[^\"]+)\"\\s*:\\s*(?:\"([^\"]+)\"|(?<value>\\d+)),?", RegexOptions.IgnoreCase); | |
//var startGroup = m.FirstOrDefault(x => x.Success && x.Value.Contains("\"start\"")); | |
//var rowsGroup = m.FirstOrDefault(x => x.Success && x.Value.Contains("\"rows\"")); | |
//if (startGroup != null && rowsGroup != null) | |
//{ | |
// start = Convert.ToInt32(startGroup.Groups["value"].Value); | |
// rows = Convert.ToInt32(rowsGroup.Groups["value"].Value); | |
//} | |
dynamic o = JObject.Parse(str); | |
var start = Convert.ToInt32(o.start); | |
var rows = Convert.ToInt32(o.rows); | |
o.start = 452; | |
o.rows = 1000; | |
var str1 = JsonConvert.SerializeObject(o); | |
o.ShouldNotBeNull(); | |
} | |
[Test] | |
public void RecursiveTest() | |
{ | |
var list = Run(0, new List<int>()); | |
list.ShouldNotBeNull(); | |
} | |
private int numberFound = 15; | |
private List<int> numberList = Enumerable.Range(1, 15).ToList(); | |
private List<int> Run(int start, List<int> finalResult) | |
{ | |
var result = numberList.Skip(start).Take(5).ToList(); | |
finalResult.AddRange(result); | |
if ((start + 5) < numberFound) | |
{ | |
return Run(start + 5, finalResult); | |
} | |
return finalResult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment