private void appendProblemStatement(List <string> output, ParsedTopCoderTask task) { output.Add(String.Empty); output.Add("/**"); output.Add(" * PROBLEM STATEMENT: "); output.Add(" * " + task.ProblemStatement.Replace("\r\n", "\r\n * ")); output.Add(" */"); }
private void appendConstraints(List <string> output, ParsedTopCoderTask task) { output.Add(String.Empty); output.Add("/**"); output.Add(" * CONSTRAINTS: "); output.Add(" * " + task.Constraints.Replace("\r\n", "\r\n * ")); //add cutting lines? output.Add(" */"); }
private void Button_Generate_Click(object sender, RoutedEventArgs e) { TopCoderTaskParser parser = new TopCoderTaskParser(); ParsedTopCoderTask task = parser.Parse(TextBox_Input.Text); TopCoderFileGenerator generator = new TopCoderFileGenerator(); TextBox_Output.Text = generator.generate(task); }
private void appendLimits(List <string> output, ParsedTopCoderTask task) { output.Add(String.Empty); output.Add("/**"); output.Add(" * LIMITS:"); output.Add(" * time limit: " + task.TimeLimit); output.Add(" * memory limit: " + task.MemoryLimit); output.Add(" */"); }
private void appendClass(List <string> output, ParsedTopCoderTask task) { output.Add(String.Empty); output.Add("public class " + task.ClassName); output.Add("{"); output.Add("\tpublic " + task.MethodSignature); output.Add("\t{"); output.Add("\t\t"); output.Add("\t}"); output.Add("}"); }
private void appendTests(List <string> output, ParsedTopCoderTask task) { output.Add(String.Empty); output.Add("[TestClass]"); output.Add("public class " + task.ClassName + "Tests"); output.Add("{"); foreach (TopCoderExample example in task.Examples) { appendTest(output, example, task); } output.Add("}"); }
public string generate(ParsedTopCoderTask task) { List <string> output = new List <string>(); appendUnitTestUsing(output); appendTimeComments(output); appendProblemStatement(output, task); appendLimits(output, task); appendConstraints(output, task); appendUsings(output); appendClass(output, task); appendTests(output, task); return(output.Aggregate((curr, next) => curr += "\r\n" + next)); }
private void appendTest(List <string> output, TopCoderExample example, ParsedTopCoderTask task) { string objName = task.ClassName.ToLower(); output.Add(String.Empty); if (example.comment != String.Empty) { output.Add("\t//" + example.comment); } output.Add("\t[TestMethod]"); output.Add("\t public void TestCase" + example.testCaseNo.ToString() + "()"); output.Add("\t{"); output.Add("\t\t" + task.ClassName + " " + objName + " = new " + task.ClassName + "();"); string assertLine = String.Empty; assertLine += "\t\tAssert.AreEqual(" + example.expectedOutput + ", " + objName + "." + task.Method + "("; for (int i = 0; i < example.inputs.Count; i++) { if (i != 0) { assertLine += ", "; } if (task.Parameters[i].Contains("[]")) { assertLine += "new " + task.Parameters[i] + example.inputs[i]; } else { assertLine += example.inputs[i]; } } assertLine += "));"; output.Add(assertLine); output.Add("\t}"); }
public ParsedTopCoderTask Parse(string bareTask) { ParsedTopCoderTask parsed = new ParsedTopCoderTask(); string[] lines = bareTask.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); int currLine = 0; while (lines[currLine] != "Problem Statement") { currLine++; } currLine += 2; while (lines[currLine] != "Definition") { parsed.ProblemStatement += lines[currLine] + "\r\n"; currLine++; } while (lines[currLine] != "Class:") { currLine++; } currLine++; parsed.ClassName = lines[currLine]; while (lines[currLine] != "Method:") { currLine++; } currLine++; parsed.Method = lines[currLine]; while (lines[currLine] != "Parameters:") { currLine++; } currLine++; parsed.Parameters = lines[currLine].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries); while (lines[currLine] != "Method signature:") { currLine++; } currLine++; parsed.MethodSignature = lines[currLine]; while (lines[currLine] != "Time limit (s):") { currLine++; } currLine++; parsed.TimeLimit = lines[currLine] + "s"; while (lines[currLine] != "Memory limit (MB):") { currLine++; } currLine++; parsed.MemoryLimit = lines[currLine] + "MB"; while (lines[currLine] != "Constraints") { currLine++; } while (lines[currLine] != "Examples") { parsed.Constraints += lines[currLine]; currLine++; } currLine++; string currExample = String.Empty; while (currLine < lines.Length) { if (Regex.IsMatch(lines[currLine], "This problem statement.*")) { if (currExample != String.Empty) { parsed.Examples.Add(new TopCoderExample(currExample)); } break; } if (currExample != String.Empty && Regex.IsMatch(lines[currLine], "^[0-9]*\\)")) { parsed.Examples.Add(new TopCoderExample(currExample)); currExample = String.Empty; } currExample += lines[currLine] + "\r\n"; currLine++; } return(parsed); }