// run all the tests in one piece of JSON static void RunJsonTests(string sourcename, string json) { _output.WriteLine($"Run JSON test: '{sourcename}'"); JsonTestData.Setup(json); var testdata = JsonTestData.ClassTestCases; _output.WriteLine($"json test count: {testdata.Count}"); var testcases = testdata .Where(t => t.Title.ToLower().Contains(_filter)) .Take(_take); var counter = 0; foreach (var testcase in testcases) { RunJsonTest(testcase.Title, testcase.Script, testcase.Inputs.Join(), testcase.TargetLevel.ToString(), testcase.FinalState, ++counter, testcase.RandomSeed); } }
// expand one piece of JSON into a set of converted test cases in a directory, create if needed static void RunJsonConvert(string path, string script, string dir) { _output.WriteLine($"Converting JSON: '{path}' to '{dir}'"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } JsonTestData.Setup(script); var testdata = JsonTestData.ClassTestCases; _output.WriteLine($"json: '{testdata.Count}'"); var badchars = new HashSet <char>(Path.GetInvalidFileNameChars()); var counter = 0; foreach (var testcase in testdata) { var title = new string(testcase.Title.Select(c => badchars.Contains(c) ? '-' : c).ToArray()); var filename = String.Format("{0:D3}-{1}.txt", ++counter, title); var outpath = Path.Combine(dir, filename); _output.WriteLine($"title: '{testcase.Title} to {outpath}"); using (var sw = new StreamWriter(outpath)) sw.Write(JsonTestData.ConvertToScript(testcase)); } }