Skip to content

Commit 8d1e9e0

Browse files
aleksisvtmoo
authored andcommitted
Modified source and tests to match the new R project folder structure in RExerciseDescParser
runTests works without scripts on linux
1 parent 9c01c25 commit 8d1e9e0

File tree

29 files changed

+598
-109
lines changed

29 files changed

+598
-109
lines changed

tmc-langs-r/getAvailablePoints.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

tmc-langs-r/runTests.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
import java.nio.file.Paths;
1414
import java.util.ArrayList;
1515
import java.util.List;
16-
import java.util.Map;
1716

1817

1918

2019
class RExerciseDescParser {
2120

2221
private static Path RESULT_FILE = Paths.get(".available_points.json");
23-
private static final TypeReference<Map<String, List<String>>> MAP_TYPE_REFERENCE =
24-
new TypeReference<Map<String, List<String>>>() {};
22+
private static final TypeReference<List<RResult>> MAP_TYPE_REFERENCE =
23+
new TypeReference<List<RResult>>() {};
2524
private Path path;
2625
private ObjectMapper mapper;
2726

@@ -31,12 +30,13 @@ public RExerciseDescParser(Path path) {
3130
}
3231

3332
public ImmutableList<TestDesc> parse() throws IOException {
33+
3434
List<TestDesc> testDescs = new ArrayList<>();
3535
byte[] json = Files.readAllBytes(path.resolve(RESULT_FILE));
36-
Map<String, List<String>> parse = mapper.readValue(json, MAP_TYPE_REFERENCE);
37-
for (String name : parse.keySet()) {
38-
ImmutableList<String> points = ImmutableList.copyOf(parse.get(name));
39-
testDescs.add(new TestDesc(name, points));
36+
List<RResult> parse = mapper.readValue(json, MAP_TYPE_REFERENCE);
37+
for (RResult result : parse) {
38+
ImmutableList<String> points = ImmutableList.copyOf(result.getPoints());
39+
testDescs.add(new TestDesc(result.getName(), points));
4040
}
4141
return ImmutableList.copyOf(testDescs);
4242
}

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

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ public class RPlugin extends AbstractLanguagePlugin{
3838
private static final Path R_FOLDER_PATH = Paths.get("R");
3939
private static final Path TEST_FOLDER_PATH = Paths.get("tests");
4040
private static final Path TESTTHAT_FOLDER_PATH = Paths.get("testthat");
41-
private static final Path TMC_FOLDER_PATH = Paths.get("tmc");
41+
private static final Path TESTTHAT_FILE_PATH = Paths.get("testthat.R");
4242
private static final Path DESCRIPTION_PATH = Paths.get("DESCRIPTION");
43-
private static final Path RHISTORY_PATH = Paths.get(".Rhistory");
4443
private static final Path RESULT_R_PATH = Paths.get("result.R");
4544

4645

@@ -67,9 +66,8 @@ public RPlugin() {
6766
public boolean isExerciseTypeCorrect(Path path) {
6867
return Files.exists(path.resolve(R_FOLDER_PATH))
6968
|| 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));
69+
|| Files.exists(path.resolve(TEST_FOLDER_PATH).resolve(TESTTHAT_FILE_PATH))
70+
|| Files.exists(path.resolve(DESCRIPTION_PATH));
7371
/*
7472
R folder contains the actual R files used in the
7573
project/package. It is automatically included when creating a
@@ -146,32 +144,25 @@ public ValidationResult checkCodeStyle(Path path, Locale messageLocale) throws U
146144
}
147145

148146
public String[] getTestCommand() {
149-
150-
String[] rscr;
151-
String[] command;
147+
String[] command = new String[]{"Rscript"};
148+
String[] args;
152149
if (SystemUtils.IS_OS_WINDOWS) {
153-
rscr = new String[] {"Rscript", "-e"};
154-
command = new String[] {"\"library('tmcRtestrunner');run_tests_with_default(TRUE)\""};
150+
args = new String[]{"-e", "\"library('tmcRtestrunner');run_tests()\""};
155151
} else {
156-
rscr = new String[] {"bash"};
157-
command = new String[] {Paths.get("").toAbsolutePath().toString() + "/runTests.sh"};
152+
args = new String[]{"-e", "library(tmcRtestrunner);run_tests()"};
158153
}
159-
return ArrayUtils.addAll(rscr, command);
154+
return ArrayUtils.addAll(command, args);
160155
}
161-
156+
162157
public String[] getAvailablePointsCommand() {
163-
String[] rscr;
164-
String[] command;
158+
String[] command = new String[]{"Rscript"};
159+
String[] args;
165160
if (SystemUtils.IS_OS_WINDOWS) {
166-
rscr = new String[] {"Rscript", "-e"};
167-
command = new String[] {"\"library(tmcRtestrunner);"
168-
+ "run_available_points(\"$PWD\")\""};
161+
args = new String[]{"-e", "\"library('tmcRtestrunner');run_available_points()\""};
169162
} else {
170-
rscr = new String[] {"bash"};
171-
command = new String[] {Paths.get("").toAbsolutePath().toString()
172-
+ "/getAvailablePoints.sh"};
163+
args = new String[]{"-e", "library(tmcRtestrunner);run_available_points()"};
173164
}
174-
return ArrayUtils.addAll(rscr, command);
165+
return ArrayUtils.addAll(command, args);
175166
}
176167

177168

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
package fi.helsinki.cs.tmc.langs.r;
3+
4+
import java.util.List;
5+
6+
7+
public class RResult {
8+
9+
private String name;
10+
private List<String> points;
11+
12+
public RResult(){
13+
14+
}
15+
16+
public String getName() {
17+
return name;
18+
}
19+
20+
public void setName(String name) {
21+
this.name = name;
22+
}
23+
24+
public List<String> getPoints() {
25+
return points;
26+
}
27+
28+
public void setPoints(List<String> points) {
29+
this.points = points;
30+
}
31+
32+
33+
}

tmc-langs-r/src/test/java/fi/helsinki/cs/tmc/langs/r/RExerciseDescParserTest.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,32 @@ public RExerciseDescParserTest() {
3030

3131
@Test
3232
public void testThatParseSeemsToWorkOnExampleJson() {
33-
assertEquals(re.size(),6);
34-
assertEquals(re.get(0).points.size(),2);
33+
assertEquals(re.size(),22);
34+
assertEquals(re.get(0).points.size(),3);
3535
assertEquals(re.get(0).name,"Addition works");
36-
assertEquals(re.get(1).points.size(),2);
36+
assertEquals(re.get(1).points.size(),3);
3737
assertEquals(re.get(1).name,"Multiplication works");
38-
assertEquals(re.get(2).points.size(),1);
38+
assertEquals(re.get(2).points.size(),2);
3939
assertEquals(re.get(2).name,"Subtraction works");
40-
assertEquals(re.get(3).points.size(),1);
40+
assertEquals(re.get(3).points.size(),2);
4141
assertEquals(re.get(3).name,"Division works");
42-
assertEquals(re.get(4).points.size(),0);
42+
assertEquals(re.get(4).points.size(),1);
4343
assertEquals(re.get(4).name, "Test with no points");
44-
assertEquals(re.get(5).points.size(),0);
44+
assertEquals(re.get(5).points.size(),1);
4545
assertEquals(re.get(5).name, "Dummy test set to fail");
46+
assertEquals(re.get(6).points.size(),2);
47+
assertEquals(re.get(6).name, "Matrix transpose with [[1,2]] works");
48+
assertEquals(re.get(7).points.size(),2);
49+
assertEquals(re.get(7).name, "Matrix transpose with [[1,2],[3,4]] works");
50+
assertEquals(re.get(8).points.size(),2);
51+
assertEquals(re.get(8).name, "Constant string works");
52+
for (int i = 1;i <= 13;i++) {
53+
assertEquals(re.get(8 + i).name, "Exercise " + i + " is correct");
54+
if (i == 3) {
55+
assertEquals(re.get(8 + i).points.size(),3);
56+
} else {
57+
assertEquals(re.get(8 + i).points.size(),2);
58+
}
59+
}
4660
}
4761
}

0 commit comments

Comments
 (0)