forked from nus-cs2113-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ryanlohyr/ryan-paceFeature
Add pace feature
- Loading branch information
Showing
3 changed files
with
182 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package seedu.duke.utils; | ||
|
||
public class Parser { | ||
|
||
//we need to consider if | ||
public boolean isValidAcademicYear(String userInput ) { | ||
try { | ||
String[] parts = userInput.split("/"); | ||
if(parts.length != 2){ | ||
throw new IllegalArgumentException("Needs to be in format of Y2/S1"); | ||
} | ||
String year = parts[0].toUpperCase(); | ||
String semester = parts[1].toUpperCase(); | ||
|
||
//last year | ||
if(year.equals("Y4") && semester.equals("S2")){ | ||
throw new IllegalArgumentException("Its your last sem!! A bit too late ya...."); | ||
} | ||
//validate semester | ||
if(!semester.equals("S1") && !semester.equals("S2")){ | ||
throw new IllegalArgumentException("Invalid Semester"); | ||
} | ||
|
||
//validate year | ||
if (!(year.equals("Y1") || year.equals("Y2") || year.equals("Y3") || year.equals("Y4"))) { | ||
// The input is not "Y1," "Y2," "Y3," or "Y4" | ||
throw new IllegalArgumentException("Invalid Year"); | ||
} | ||
return true; | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
return false; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} |
85 changes: 85 additions & 0 deletions
85
src/test/java/seedu/duke/controllers/ModulePlannerControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package seedu.duke.controllers; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
class ModulePlannerControllerTest { | ||
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
private final PrintStream originalOut = System.out; | ||
|
||
@BeforeEach | ||
public void setUpStreams() { | ||
System.setOut(new PrintStream(outputStream)); | ||
} | ||
|
||
@AfterEach | ||
public void restoreStreams() { | ||
System.setOut(originalOut); | ||
} | ||
|
||
|
||
@Test | ||
void computePaceWithoutArgument() { | ||
ModulePlannerController controller = new ModulePlannerController(); | ||
String[] userInput = {"pace"}; | ||
int creditsLeft = 60; | ||
controller.computePace(userInput,creditsLeft); | ||
// Capture the printed output | ||
String printedOutput = outputStream.toString().trim(); | ||
// Assert the printed output matches the expected value | ||
assertEquals(String.format("You currently have %s MCs till graduation",creditsLeft), printedOutput); | ||
} | ||
|
||
@Test | ||
void computePaceInvalidArgument() { | ||
ModulePlannerController controller = new ModulePlannerController(); | ||
String[] userInput = {"pace","y2s1"}; | ||
int creditsLeft = 60; | ||
controller.computePace(userInput,creditsLeft); | ||
// Capture the printed output | ||
String printedOutput = outputStream.toString().trim(); | ||
// Assert the printed output matches the expected value | ||
assertEquals("Needs to be in format of Y2/S1", printedOutput); | ||
} | ||
|
||
@Test | ||
void computePaceInvalidSemester() { | ||
ModulePlannerController controller = new ModulePlannerController(); | ||
String[] userInput = {"pace","y2/s10"}; | ||
int creditsLeft = 60; | ||
controller.computePace(userInput,creditsLeft); | ||
// Capture the printed output | ||
String printedOutput = outputStream.toString().trim(); | ||
// Assert the printed output matches the expected value | ||
assertEquals("Invalid Semester", printedOutput); | ||
} | ||
|
||
@Test | ||
void computePaceInvalidYear() { | ||
ModulePlannerController controller = new ModulePlannerController(); | ||
String[] userInput = {"pace","y20/s1"}; | ||
int creditsLeft = 60; | ||
controller.computePace(userInput,creditsLeft); | ||
// Capture the printed output | ||
String printedOutput = outputStream.toString().trim(); | ||
// Assert the printed output matches the expected value | ||
assertEquals("Invalid Year", printedOutput); | ||
} | ||
@Test | ||
void computePaceValidYear() { | ||
ModulePlannerController controller = new ModulePlannerController(); | ||
String[] userInput = {"pace","y2/s1"}; | ||
int creditsLeft = 60; | ||
controller.computePace(userInput,creditsLeft); | ||
String test = "hi"; | ||
// Capture the printed output | ||
String printedOutput = outputStream.toString().trim(); | ||
String line = "You have 60MCs for 5 semesters. Recommended Pace: 12MCs per sem until graduation"; | ||
// Assert the printed output matches the expected value | ||
assertEquals(printedOutput, line); | ||
} | ||
} |