66import static org .junit .Assert .assertTrue ;
77
88import fi .helsinki .cs .tmc .langs .domain .RunResult ;
9- import fi .helsinki .cs .tmc .langs .domain .TestDesc ;
109import fi .helsinki .cs .tmc .langs .domain .TestResult ;
1110import fi .helsinki .cs .tmc .langs .io .StudentFilePolicy ;
1211import fi .helsinki .cs .tmc .langs .utils .TestUtils ;
2423import java .nio .file .Path ;
2524import java .nio .file .Paths ;
2625
27-
28-
29-
30-
31-
32-
33-
34-
35-
36-
3726public class RPluginTest {
3827
3928 private RPlugin plugin ;
@@ -48,9 +37,14 @@ public void tearDown() {
4837 Path testDir = TestUtils .getPath (getClass (), "project1" );
4938 File resultsJson = new File (testDir .toAbsolutePath ().toString () + "/.results.json" );
5039 resultsJson .delete ();
51- File availablePointsJson = new File (testDir .toAbsolutePath ().toString ()
52- + "/.available_points.json" );
53- availablePointsJson .delete ();
40+
41+ testDir = TestUtils .getPath (getClass (), "simple_source_code_error" );
42+ resultsJson = new File (testDir .toAbsolutePath ().toString () + "/.results.json" );
43+ resultsJson .delete ();
44+
45+ testDir = TestUtils .getPath (getClass (), "simple_all_tests_pass" );
46+ resultsJson = new File (testDir .toAbsolutePath ().toString () + "/.results.json" );
47+ resultsJson .delete ();
5448 }
5549
5650 @ Test
@@ -96,50 +90,62 @@ public void testScanExercise() {
9690 }
9791
9892 @ Test
99- public void testScanExerciseInTheWrongPlace () {
100- Path testDir = TestUtils .getPath (getClass (), "project1" );
101- plugin .scanExercise (testDir , "ar.R" );
102- Path availablePointsJson = testDir .resolve (".available_points.json" );
103- ImmutableList <TestDesc > re = null ;
104- try {
105- re = new RExerciseDescParser (availablePointsJson ).parse ();
106- } catch (IOException e ) {
107- System .out .println ("Something wrong: " + e .getMessage ());
108- }
109- assertTrue (re == null );
93+ public void runTestsCreatesAJson () {
94+ Path testDir = TestUtils .getPath (getClass (), "passing" );
95+ plugin .runTests (testDir );
96+ File resultsJson = new File (testDir .toAbsolutePath ().toString () + "/.results.json" );
97+
98+ assertTrue (resultsJson .exists ());
11099 }
111100
112101 @ Test
113- public void testRunTests () {
114- Path testDir = TestUtils .getPath (getClass (), "project1" );
115- RunResult runRes = plugin .runTests (testDir );
116- ImmutableList <TestResult > re = runRes .testResults ;
117- assertEquals (re .size (),22 );
118- assertEquals (re .get (0 ).getName (),"Addition works" );
119- assertTrue (re .get (1 ).isSuccessful ());
120- assertEquals (re .get (1 ).getName (),"Multiplication works" );
121- assertTrue (re .get (2 ).isSuccessful ());
122- assertEquals (re .get (2 ).getName (),"Subtraction works" );
123- assertTrue (re .get (3 ).isSuccessful ());
124- assertEquals (re .get (3 ).getName (),"Division works" );
125- assertTrue (re .get (4 ).isSuccessful ());
126- assertEquals (re .get (4 ).getName (), "Test with no points" );
127- assertFalse (re .get (5 ).isSuccessful ());
128- assertEquals (re .get (5 ).getName (), "Dummy test set to fail" );
129- assertTrue (re .get (6 ).isSuccessful ());
130- assertEquals (re .get (6 ).getName (), "Matrix transpose with [[1,2]] works" );
131- assertTrue (re .get (7 ).isSuccessful ());
132- assertEquals (re .get (7 ).getName (), "Matrix transpose with [[1,2],[3,4]] works" );
133- assertTrue (re .get (8 ).isSuccessful ());
134- assertEquals (re .get (8 ).getName (), "Constant string works" );
135- for (int i = 1 ;i <= 13 ;i ++) {
136- assertEquals (re .get (8 + i ).getName (), "Exercise " + i + " is correct" );
137- assertTrue (re .get (8 + i ).isSuccessful ());
102+ public void runTestsCreatesJsonWithCorrectStatus () {
103+ Path testDir = TestUtils .getPath (getClass (), "passing" );
104+ RunResult res = plugin .runTests (testDir );
105+
106+ assertEquals (RunResult .Status .TESTS_FAILED , res .status );
107+ }
108+
109+ @ Test
110+ public void runTestsCreatesJsonWithCorrectNumberOfResults () {
111+ Path testDir = TestUtils .getPath (getClass (), "passing" );
112+ RunResult res = plugin .runTests (testDir );
113+
114+ assertEquals (19 , res .testResults .size ());
115+ }
138116
117+ @ Test
118+ public void testResultsFromRunTestsHaveCorrectStatuses () {
119+ Path testDir = TestUtils .getPath (getClass (), "passing" );
120+ RunResult res = plugin .runTests (testDir );
121+
122+ for (TestResult tr : res .testResults ) {
123+ if (!tr .getName ().equals ("Dummy test set to fail" )) {
124+ assertTrue (tr .isSuccessful ());
125+ } else {
126+ assertFalse (tr .isSuccessful ());
127+ }
139128 }
140- File resultsJson = new File ( testDir . toAbsolutePath (). toString () + "/.results.json" );
129+ }
141130
142- assertTrue (resultsJson .exists ());
131+ @ Test
132+ public void runTestsWorksWithErronousSourceCode () {
133+ Path testDir = TestUtils .getPath (getClass (), "simple_source_code_error" );
134+ RunResult res = plugin .runTests (testDir );
135+
136+ assertEquals (RunResult .Status .COMPILE_FAILED , res .status );
137+ assertEquals (1 , res .testResults .size ());
138+ }
139+
140+ @ Test
141+ public void runTestsHasCorrectStatusesWhenAllTestsPass () {
142+ Path testDir = TestUtils .getPath (getClass (), "simple_all_tests_pass" );
143+ RunResult res = plugin .runTests (testDir );
144+
145+ assertEquals (RunResult .Status .PASSED , res .status );
146+ for (TestResult tr : res .testResults ) {
147+ assertTrue (tr .isSuccessful ());
148+ }
143149 }
144150
145151 @ Test
0 commit comments