Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public final class RPlugin extends AbstractLanguagePlugin {
private static final Path R_FOLDER_PATH = Paths.get("R");
private static final Path TEST_FOLDER_PATH = Paths.get("tests");
private static final Path TESTTHAT_FOLDER_PATH = Paths.get("testthat");
private static final Path TESTTHAT_FILE_PATH = Paths.get("testthat.R");
private static final Path TMC_FOLDER_PATH = Paths.get("tmc");
private static final Path DESCRIPTION_PATH = Paths.get("DESCRIPTION");
private static final Path RHISTORY_PATH = Paths.get(".Rhistory");
private static final Path RESULT_R_PATH = Paths.get("result.R");

private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests.";
Expand All @@ -66,8 +66,8 @@ public RPlugin() {
public boolean isExerciseTypeCorrect(Path path) {
return Files.exists(path.resolve(R_FOLDER_PATH))
|| Files.exists(path.resolve(TEST_FOLDER_PATH).resolve(TESTTHAT_FOLDER_PATH))
|| Files.exists(path.resolve(TEST_FOLDER_PATH).resolve(TESTTHAT_FILE_PATH))
|| Files.exists(path.resolve(DESCRIPTION_PATH))
|| Files.exists(path.resolve(RHISTORY_PATH))
|| Files.exists(path.resolve(TMC_FOLDER_PATH).resolve(RESULT_R_PATH));
/*
R folder contains the actual R files used in the
Expand Down Expand Up @@ -153,7 +153,7 @@ public String[] getTestCommand() {
}
return ArrayUtils.addAll(command, args);
}

public String[] getAvailablePointsCommand() {
String[] command = new String[] {"Rscript"};
String[] args;
Expand All @@ -164,7 +164,7 @@ public String[] getAvailablePointsCommand() {
}
return ArrayUtils.addAll(command, args);
}

@Override
public void clean(Path path) {
// TO DO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

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


Expand Down Expand Up @@ -26,29 +25,21 @@











public class RPluginTest {

private RPlugin plugin;

@Before
public void setUp() {
plugin = new RPlugin();
}

@After
public void tearDown() {
Path testDir = TestUtils.getPath(getClass(), "project1");
File resultsJson = new File(testDir.toAbsolutePath().toString() + "/.results.json");
resultsJson.delete();
File availablePointsJson = new File(testDir.toAbsolutePath().toString()
File availablePointsJson = new File(testDir.toAbsolutePath().toString()
+ "/.available_points.json");
availablePointsJson.delete();
}
Expand All @@ -66,7 +57,7 @@ public void testGetTestCommand() {
String[] expectedCommand = ArrayUtils.addAll(command, args);
Assert.assertArrayEquals(expectedCommand,plugin.getTestCommand());
}

@Test
public void testGetAvailablePointsCommand() {
String[] command = new String[] {"Rscript"};
Expand All @@ -79,22 +70,22 @@ public void testGetAvailablePointsCommand() {
String[] expectedCommand = ArrayUtils.addAll(command, args);
Assert.assertArrayEquals(expectedCommand, plugin.getAvailablePointsCommand());
}

@Test
public void testGetPluginName() {
assertEquals("r", plugin.getLanguageName());
}

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

assertTrue(availablePointsJson.exists());
}

@Test
public void testRunTests() {
Path testDir = TestUtils.getPath(getClass(), "project1");
Expand All @@ -119,45 +110,47 @@ public void testRunTests() {
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());;
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());
}

@Test
public void excerciseIsCorrectTypeIfItContainsRFolder() {
public void exerciseIsCorrectTypeIfItContainsRFolder() {
Path testCasesRoot = TestUtils.getPath(getClass(), "recognition_test_cases");
Path project = testCasesRoot.resolve("R_folder");

assertTrue(plugin.isExerciseTypeCorrect(project));
}

@Test
public void excerciseIsCorrectTypeIfItContainsTestthatFolder() {
public void exerciseIsCorrectTypeIfItContainsTestthatFolder() {
Path testCasesRoot = TestUtils.getPath(getClass(), "recognition_test_cases");
Path project = testCasesRoot.resolve("testthat_folder");

assertTrue(plugin.isExerciseTypeCorrect(project));
}

@Test
public void excerciseIsCorrectTypeIfItContainsDescription() {
public void exerciseIsCorrectTypeIfItContainsDescription() {
Path testCasesRoot = TestUtils.getPath(getClass(), "recognition_test_cases");
Path project = testCasesRoot.resolve("description");

assertTrue(plugin.isExerciseTypeCorrect(project));
}

@Test
public void excerciseIsCorrectTypeIfItContainsRhistory() {
public void exerciseIsCorrectTypeIfItContainsTestthatFile() {
Path testCasesRoot = TestUtils.getPath(getClass(), "recognition_test_cases");
Path project = testCasesRoot.resolve("rhistory");
Path project = testCasesRoot.resolve("testthat_folder")
.resolve("tests");

assertTrue(plugin.isExerciseTypeCorrect(project));
File testThatR = new File(project.toAbsolutePath().toString() + "/testthat.R");
assertTrue(testThatR.exists());
}

@Test
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library("testthat")