Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;



class RExerciseDescParser {

private static Path RESULT_FILE = Paths.get(".available_points.json");
private static final TypeReference<Map<String, List<String>>> MAP_TYPE_REFERENCE =
new TypeReference<Map<String, List<String>>>() {};
private static final TypeReference<List<RResult>> MAP_TYPE_REFERENCE =
new TypeReference<List<RResult>>() {};
private Path path;
private ObjectMapper mapper;

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

public ImmutableList<TestDesc> parse() throws IOException {

List<TestDesc> testDescs = new ArrayList<>();
byte[] json = Files.readAllBytes(path.resolve(RESULT_FILE));
Map<String, List<String>> parse = mapper.readValue(json, MAP_TYPE_REFERENCE);
for (String name : parse.keySet()) {
ImmutableList<String> points = ImmutableList.copyOf(parse.get(name));
testDescs.add(new TestDesc(name, points));
List<RResult> parse = mapper.readValue(json, MAP_TYPE_REFERENCE);
for (RResult result : parse) {
ImmutableList<String> points = ImmutableList.copyOf(result.getPoints());
testDescs.add(new TestDesc(result.getName(), points));
}
return ImmutableList.copyOf(testDescs);
}
Expand Down
33 changes: 33 additions & 0 deletions tmc-langs-r/src/main/java/fi/helsinki/cs/tmc/langs/r/RResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

package fi.helsinki.cs.tmc.langs.r;

import java.util.List;


public class RResult {

private String name;
private List<String> points;

public RResult(){

}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<String> getPoints() {
return points;
}

public void setPoints(List<String> points) {
this.points = points;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,32 @@ public RExerciseDescParserTest() {

@Test
public void testThatParseSeemsToWorkOnExampleJson() {
assertEquals(re.size(),6);
assertEquals(re.get(0).points.size(),2);
assertEquals(re.size(),22);
assertEquals(re.get(0).points.size(),3);
assertEquals(re.get(0).name,"Addition works");
assertEquals(re.get(1).points.size(),2);
assertEquals(re.get(1).points.size(),3);
assertEquals(re.get(1).name,"Multiplication works");
assertEquals(re.get(2).points.size(),1);
assertEquals(re.get(2).points.size(),2);
assertEquals(re.get(2).name,"Subtraction works");
assertEquals(re.get(3).points.size(),1);
assertEquals(re.get(3).points.size(),2);
assertEquals(re.get(3).name,"Division works");
assertEquals(re.get(4).points.size(),0);
assertEquals(re.get(4).points.size(),1);
assertEquals(re.get(4).name, "Test with no points");
assertEquals(re.get(5).points.size(),0);
assertEquals(re.get(5).points.size(),1);
assertEquals(re.get(5).name, "Dummy test set to fail");
assertEquals(re.get(6).points.size(),2);
assertEquals(re.get(6).name, "Matrix transpose with [[1,2]] works");
assertEquals(re.get(7).points.size(),2);
assertEquals(re.get(7).name, "Matrix transpose with [[1,2],[3,4]] works");
assertEquals(re.get(8).points.size(),2);
assertEquals(re.get(8).name, "Constant string works");
for (int i = 1;i <= 13;i++) {
assertEquals(re.get(8 + i).name, "Exercise " + i + " is correct");
if (i == 3) {
assertEquals(re.get(8 + i).points.size(),3);
} else {
assertEquals(re.get(8 + i).points.size(),2);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@

package fi.helsinki.cs.tmc.langs.r;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;


import fi.helsinki.cs.tmc.langs.domain.RunResult;
import fi.helsinki.cs.tmc.langs.domain.TestResult;
import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy;
import fi.helsinki.cs.tmc.langs.utils.TestUtils;

import com.google.common.collect.ImmutableList;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;
import org.junit.After;
Expand All @@ -21,6 +27,13 @@










public class RPluginTest {

private RPlugin plugin;
Expand All @@ -32,9 +45,12 @@ public void setUp() {

@After
public void tearDown() {
Path testDir = TestUtils.getPath(getClass(), "passing");
Path testDir = TestUtils.getPath(getClass(), "project1");
File resultsJson = new File(testDir.toAbsolutePath().toString() + "/.results.json");
resultsJson.delete();
File availablePointsJson = new File(testDir.toAbsolutePath().toString()
+ "/.available_points.json");
availablePointsJson.delete();
}

@Test
Expand Down Expand Up @@ -71,14 +87,42 @@ public void testGetPluginName() {

@Test
public void testScanExercise() {
Path testDir = TestUtils.getPath(getClass(), "passing");
Path testDir = TestUtils.getPath(getClass(), "project1");
plugin.scanExercise(testDir, "arithmetics.R");
File availablePointsJson = new File(testDir.toAbsolutePath().toString()
+ "/.available_points.json");

assertTrue(availablePointsJson.exists());
}

@Test
public void testRunTests() {
Path testDir = TestUtils.getPath(getClass(), "passing");
plugin.runTests(testDir);
Path testDir = TestUtils.getPath(getClass(), "project1");
RunResult runRes = plugin.runTests(testDir);
ImmutableList<TestResult> re = runRes.testResults;
assertEquals(re.size(),22);
assertEquals(re.get(0).getName(),"Addition works");
assertTrue(re.get(1).isSuccessful());
assertEquals(re.get(1).getName(),"Multiplication works");
assertTrue(re.get(2).isSuccessful());
assertEquals(re.get(2).getName(),"Subtraction works");
assertTrue(re.get(3).isSuccessful());
assertEquals(re.get(3).getName(),"Division works");
assertTrue(re.get(4).isSuccessful());
assertEquals(re.get(4).getName(), "Test with no points");
assertFalse(re.get(5).isSuccessful());
assertEquals(re.get(5).getName(), "Dummy test set to fail");
assertTrue(re.get(6).isSuccessful());
assertEquals(re.get(6).getName(), "Matrix transpose with [[1,2]] works");
assertTrue(re.get(7).isSuccessful());
assertEquals(re.get(7).getName(), "Matrix transpose with [[1,2],[3,4]] works");
assertTrue(re.get(8).isSuccessful());
assertEquals(re.get(8).getName(), "Constant string works");
for (int i = 1;i <= 13;i++) {
assertEquals(re.get(8 + i).getName(), "Exercise " + i + " is correct");
assertTrue(re.get(8 + i).isSuccessful());;

}
File resultsJson = new File(testDir.toAbsolutePath().toString() + "/.results.json");

assertTrue(resultsJson.exists());
Expand Down
164 changes: 157 additions & 7 deletions tmc-langs-r/src/test/resources/example_json/.available_points.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,158 @@
{"Addition works": ["r1.1","r1.2"],
"Multiplication works":["r1.3", "r1.4"],
"Subtraction works":["r1.5"],
"Division works":["r1.6"],
"Test with no points":[],
"Dummy test set to fail":[]
}
[
{
"name": "Addition works",
"points": [
"r1",
"r1.1",
"r1.2"
]
},
{
"name": "Multiplication works",
"points": [
"r1",
"r1.3",
"r1.4"
]
},
{
"name": "Subtraction works",
"points": [
"r1",
"r1.5"
]
},
{
"name": "Division works",
"points": [
"r1",
"r1.6"
]
},
{
"name": "Test with no points",
"points": [
"r1"
]
},
{
"name": "Dummy test set to fail",
"points": [
"r1"
]
},
{
"name": "Matrix transpose with [[1,2]] works",
"points": [
"r2",
"r2.1"
]
},
{
"name": "Matrix transpose with [[1,2],[3,4]] works",
"points": [
"r2",
"r2.2"
]
},
{
"name": "Constant string works",
"points": [
"r3",
"r3.1"
]
},
{
"name": "Exercise 1 is correct",
"points": [
"r4",
"r4.1"
]
},
{
"name": "Exercise 2 is correct",
"points": [
"r4",
"r4.2"
]
},
{
"name": "Exercise 3 is correct",
"points": [
"r4",
"r4.3",
"r4.4"
]
},
{
"name": "Exercise 4 is correct",
"points": [
"r4",
"r4.5"
]
},
{
"name": "Exercise 5 is correct",
"points": [
"r4",
"r4.6"
]
},
{
"name": "Exercise 6 is correct",
"points": [
"r4",
"r4.7"
]
},
{
"name": "Exercise 7 is correct",
"points": [
"r4",
"r4.8"
]
},
{
"name": "Exercise 8 is correct",
"points": [
"r4",
"r4.9"
]
},
{
"name": "Exercise 9 is correct",
"points": [
"r4",
"r4.10"
]
},
{
"name": "Exercise 10 is correct",
"points": [
"r4",
"r4.11"
]
},
{
"name": "Exercise 11 is correct",
"points": [
"r4",
"r4.12"
]
},
{
"name": "Exercise 12 is correct",
"points": [
"r4",
"r4.13"
]
},
{
"name": "Exercise 13 is correct",
"points": [
"r4",
"r4.14"
]
}
]

3 changes: 3 additions & 0 deletions tmc-langs-r/src/test/resources/project1/.Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^\.travis\.yml$
^.*\.Rproj$
^\.Rproj\.user$
4 changes: 4 additions & 0 deletions tmc-langs-r/src/test/resources/project1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rdata
.Rhistory
.results.json
.available_points.json
9 changes: 9 additions & 0 deletions tmc-langs-r/src/test/resources/project1/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: project1
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.2.3)
License: What license is it under?
Encoding: UTF-8
LazyData: true
2 changes: 2 additions & 0 deletions tmc-langs-r/src/test/resources/project1/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated by roxygen2: fake comment so roxygen2 overwrites silently.
exportPattern("^[^\\.]")
Loading