Skip to content

Commit 51a980f

Browse files
eerojalatmoo
authored andcommitted
Created preliminary RPlugin and RStudentFilePolicy classes
1 parent e9cb470 commit 51a980f

File tree

3 files changed

+95
-30
lines changed

3 files changed

+95
-30
lines changed

tmc-langs-r/src/main/java/fi/helsinki/cs/tmc/langs/r/RPlugin.java

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,24 @@
2929
import java.nio.file.Path;
3030
import java.util.Locale;
3131

32-
public final class RPlugin extends AbstractLanguagePlugin {
3332

33+
34+
public class RPlugin extends AbstractLanguagePlugin{
35+
36+
// Various static final Path-variables for filepaths
37+
// to various folders and files in a R exercise project here
38+
private static final Path R_FOLDER_PATH = Paths.get("R");
39+
private static final Path TEST_FOLDER_PATH = Paths.get("tests");
40+
private static final Path TESTTHAT_FOLDER_PATH = Paths.get("testthat");
41+
private static final Path TMC_FOLDER_PATH = Paths.get("tmc");
42+
private static final Path DESCRIPTION_PATH = Paths.get("DESCRIPTION");
43+
private static final Path RHISTORY_PATH = Paths.get(".RHistory");
44+
private static final Path RESULT_R_PATH = Paths.get("result.R");
45+
46+
47+
48+
// Various static final String-variables for
49+
// error messages related to parsing and running R tests here
3450
private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests.";
3551
private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results.";
3652
private static final String CANNOT_SCAN_EXERCISE_MESSAGE = "Failed to scan exercise.";
@@ -49,17 +65,40 @@ public RPlugin() {
4965

5066
@Override
5167
public boolean isExerciseTypeCorrect(Path path) {
52-
return false;
68+
return Files.exists(path.resolve(R_FOLDER_PATH))
69+
|| Files.exists(path.resolve(TEST_FOLDER_PATH).resolve(TESTTHAT_FOLDER_PATH))
70+
|| Files.exists(path.resolve(DESCRIPTION_PATH))
71+
|| Files.exists(path.resolve(RHISTORY_PATH))
72+
|| Files.exists(path.resolve(TMC_FOLDER_PATH).resolve(RESULT_R_PATH));
73+
/*
74+
R folder contains the actual R files used in the
75+
project/package. It is automatically included when creating a
76+
R package but now when making a regular project in RStudio.
77+
78+
test/testthat folder contains the unit testing
79+
files which use the testThat library for the R project.
80+
81+
DESCRIPTION file contains package information.
82+
Included automatically when making a new package, but not
83+
included when making a regular project in RStudio.
84+
85+
.RHistory file contains the history of executed code on
86+
the R terminal. Generated after running code on the R
87+
terminal for the first time.
88+
89+
tmc/result.R contains the call to tmcRtestrunner's runTests function.
90+
*/
5391
}
5492

5593
@Override
5694
protected StudentFilePolicy getStudentFilePolicy(Path projectPath) {
57-
return null;
95+
return new RStudentFilePolicy(projectPath);
5896
}
5997

98+
6099
@Override
61100
public String getPluginName() {
62-
return null;
101+
return "r";
63102
}
64103

65104
@Override
@@ -99,7 +138,8 @@ public RunResult runTests(Path path) {
99138
}
100139

101140
@Override
102-
public ValidationResult checkCodeStyle(Path path, Locale messageLocale) {
141+
public ValidationResult checkCodeStyle(Path path, Locale messageLocale) throws UnsupportedOperationException {
142+
// TO DO
103143
return null;
104144
}
105145

@@ -120,9 +160,10 @@ private String[] getAvailablePointsCommand() {
120160
+ "getAvailablePoints(\"$PWD\")\""};
121161
return ArrayUtils.addAll(rscr, command);
122162
}
123-
163+
164+
124165
@Override
125166
public void clean(Path path) {
126-
167+
// TO DO
127168
}
128169
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package fi.helsinki.cs.tmc.langs.r;
2+
3+
import fi.helsinki.cs.tmc.langs.io.ConfigurableStudentFilePolicy;
4+
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
8+
public class RStudentFilePolicy extends ConfigurableStudentFilePolicy {
9+
public RStudentFilePolicy(Path configFileParent) {
10+
super(configFileParent);
11+
}
12+
13+
/**
14+
* Returns {@code True} for all files in the <tt>projectRoot/R/</tt> directory and other
15+
* files required for building the project.
16+
*
17+
* <p>Will NOT return {@code True} for any test files. If test file modification are part
18+
* of the exercise, those test files are whitelisted as <tt>ExtraStudentFiles</tt> and the
19+
* decision to include them is made by {@link ConfigurableStudentFilePolicy}.
20+
*/
21+
@Override
22+
public boolean isStudentSourceFile(Path path, Path projectRootPath) {
23+
return path.startsWith(Paths.get("R"));
24+
}
25+
}

tmc-langs-r/src/test/resources/example_json/.results.json

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"status": "passed",
3+
"status": "pass",
44
"name": "Addition works",
55
"message": "",
66
"backtrace": "",
@@ -10,7 +10,7 @@
1010
]
1111
},
1212
{
13-
"status": "passed",
13+
"status": "pass",
1414
"name": "Multiplication works",
1515
"message": "",
1616
"backtrace": "",
@@ -20,7 +20,7 @@
2020
]
2121
},
2222
{
23-
"status": "passed",
23+
"status": "pass",
2424
"name": "Subtraction works",
2525
"message": "",
2626
"backtrace": "",
@@ -29,7 +29,7 @@
2929
]
3030
},
3131
{
32-
"status": "passed",
32+
"status": "pass",
3333
"name": "Division works",
3434
"message": "",
3535
"backtrace": "",
@@ -38,7 +38,7 @@
3838
]
3939
},
4040
{
41-
"status": "passed",
41+
"status": "pass",
4242
"name": "Test with no points",
4343
"message": "",
4444
"backtrace": "",
@@ -47,7 +47,7 @@
4747
]
4848
},
4949
{
50-
"status": "failed",
50+
"status": "fail",
5151
"name": "Dummy test set to fail",
5252
"message": "Failed with call: expect_true, FALSE\nFALSE isn't true.\nFailed with call: expect_equal, 1, 2\n1 not equal to 2.\n1/1 mismatches\n[1] 1 - 2 == -1\n",
5353
"backtrace": "",
@@ -56,7 +56,7 @@
5656
]
5757
},
5858
{
59-
"status": "passed",
59+
"status": "pass",
6060
"name": "Matrix transpose with [[1,2]] works",
6161
"message": "",
6262
"backtrace": "",
@@ -65,7 +65,7 @@
6565
]
6666
},
6767
{
68-
"status": "passed",
68+
"status": "pass",
6969
"name": "Matrix transpose with [[1,2],[3,4]] works",
7070
"message": "",
7171
"backtrace": "",
@@ -74,7 +74,7 @@
7474
]
7575
},
7676
{
77-
"status": "passed",
77+
"status": "pass",
7878
"name": "Constant string works",
7979
"message": "",
8080
"backtrace": "",
@@ -83,7 +83,7 @@
8383
]
8484
},
8585
{
86-
"status": "passed",
86+
"status": "pass",
8787
"name": "Exercise 1 is correct",
8888
"message": "",
8989
"backtrace": "",
@@ -92,7 +92,7 @@
9292
]
9393
},
9494
{
95-
"status": "passed",
95+
"status": "pass",
9696
"name": "Exercise 2 is correct",
9797
"message": "",
9898
"backtrace": "",
@@ -101,7 +101,7 @@
101101
]
102102
},
103103
{
104-
"status": "passed",
104+
"status": "pass",
105105
"name": "Exercise 3 is correct",
106106
"message": "",
107107
"backtrace": "",
@@ -111,7 +111,7 @@
111111
]
112112
},
113113
{
114-
"status": "passed",
114+
"status": "pass",
115115
"name": "Exercise 4 is correct",
116116
"message": "",
117117
"backtrace": "",
@@ -120,7 +120,7 @@
120120
]
121121
},
122122
{
123-
"status": "passed",
123+
"status": "pass",
124124
"name": "Exercise 5 is correct",
125125
"message": "",
126126
"backtrace": "",
@@ -129,7 +129,7 @@
129129
]
130130
},
131131
{
132-
"status": "passed",
132+
"status": "pass",
133133
"name": "Exercise 6 is correct",
134134
"message": "",
135135
"backtrace": "",
@@ -138,7 +138,7 @@
138138
]
139139
},
140140
{
141-
"status": "passed",
141+
"status": "pass",
142142
"name": "Exercise 7 is correct",
143143
"message": "",
144144
"backtrace": "",
@@ -147,7 +147,7 @@
147147
]
148148
},
149149
{
150-
"status": "passed",
150+
"status": "pass",
151151
"name": "Exercise 8 is correct",
152152
"message": "",
153153
"backtrace": "",
@@ -156,7 +156,7 @@
156156
]
157157
},
158158
{
159-
"status": "passed",
159+
"status": "pass",
160160
"name": "Exercise 9 is correct",
161161
"message": "",
162162
"backtrace": "",
@@ -165,7 +165,7 @@
165165
]
166166
},
167167
{
168-
"status": "passed",
168+
"status": "pass",
169169
"name": "Exercise 10 is correct",
170170
"message": "",
171171
"backtrace": "",
@@ -174,7 +174,7 @@
174174
]
175175
},
176176
{
177-
"status": "passed",
177+
"status": "pass",
178178
"name": "Exercise 11 is correct",
179179
"message": "",
180180
"backtrace": "",
@@ -183,7 +183,7 @@
183183
]
184184
},
185185
{
186-
"status": "passed",
186+
"status": "pass",
187187
"name": "Exercise 12 is correct",
188188
"message": "",
189189
"backtrace": "",
@@ -192,7 +192,7 @@
192192
]
193193
},
194194
{
195-
"status": "passed",
195+
"status": "pass",
196196
"name": "Exercise 13 is correct",
197197
"message": "",
198198
"backtrace": "",
@@ -201,4 +201,3 @@
201201
]
202202
}
203203
]
204-

0 commit comments

Comments
 (0)