-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_projects.py
147 lines (115 loc) · 3.19 KB
/
make_projects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#! python3
import os, sys, shutil
data_code = """namespace <NAMESPACE>;
public class Data
{
}"""
parser_code = """namespace <NAMESPACE>;
public static class Parser
{
public static Data Parse(string data)
{
return new Data();
}
}"""
solver_code = """namespace <NAMESPACE>;
public static class Solver
{
public static object Part1(Data data)
{
return null!;
}
public static object Part2(Data data)
{
return null!;
}
}"""
solution_code = """using utils;
namespace <NAMESPACE>;
public class Solution : ISolution
{
public static void Main()
{
var solution = new Solution();
Console.WriteLine($"Part1: {solution.SolvePart1()}");
Console.WriteLine($"Part2: {solution.SolvePart2()}");
}
public Solution()
{
_data = Parser.Parse(Input.GetData());
}
public object SolvePart1()
{
return Solver.Part1(_data);
}
public object SolvePart2()
{
return Solver.Part2(_data);
}
private readonly Data _data;
}"""
input_code = """namespace <NAMESPACE>;
public static class Input
{
public static string GetData()
{
return @"";
}
}"""
parser_tests_code = """using NUnit.Framework;
namespace <NAMESPACE>;
public class ParserTests
{
[Test]
public void Parser_Works_Correctly()
{
Assert.That(Parser.Parse(""), Is.Not.Null);
}
}"""
solver_tests_code = """using NUnit.Framework;
namespace <NAMESPACE>;
public class SolverTests
{
private const string Data = @"";
[Test]
public void Part1()
{
Assert.That(Solver.Part1(Parser.Parse(Data)), Is.Null);
}
[Test]
public void Part2()
{
Assert.That(Solver.Part2(Parser.Parse(Data)), Is.Null);
}
}"""
project = sys.argv[1]
lib = f"{project}"
os.system(f"dotnet new classlib --no-restore -o {lib}")
os.remove(f"{lib}/Class1.cs")
with open(f"{lib}/Data.cs", "w") as f:
f.write(data_code.replace("<NAMESPACE>", lib.replace("-", "_")))
with open(f"{lib}/Parser.cs", "w") as f:
f.write(parser_code.replace("<NAMESPACE>", lib.replace("-", "_")))
with open(f"{lib}/Solver.cs", "w") as f:
f.write(solver_code.replace("<NAMESPACE>", lib.replace("-", "_")))
app = f"{project}.app"
os.system(f"dotnet new console --no-restore -o {app}")
os.remove(f"{app}/Program.cs")
with open(f"{app}/Solution.cs", "w") as f:
f.write(solution_code.replace("<NAMESPACE>", app.replace("-", "_")))
with open(f"{app}/Input.cs", "w") as f:
f.write(input_code.replace("<NAMESPACE>", app.replace("-", "_")))
tests = f"{project}.tests"
os.system(f"dotnet new nunit --no-restore -o {tests}")
os.remove(f"{tests}/UnitTest1.cs")
with open(f"{tests}/ParserTests.cs", "w") as f:
f.write(parser_tests_code.replace("<NAMESPACE>", tests.replace("-", "_")))
with open(f"{tests}/SolverTests.cs", "w") as f:
f.write(solver_tests_code.replace("<NAMESPACE>", tests.replace("-", "_")))
os.system(f"dotnet add {app} reference utils")
os.system(f"dotnet add {app} reference {lib}")
os.system(f"dotnet add {tests} reference {lib}")
os.system(f"dotnet add solutions.tests reference {app}")
os.system(f"dotnet sln add {lib}")
os.system(f"dotnet sln add {app}")
os.system(f"dotnet sln add {tests}")