-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Required and Science command #97
Required and Science command #97
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job in general man, the logic is sound and the approach really makes sense, but just a few comments/suggestions :D
And also some general comments/suggestions:
- We can consider abstracting out all the storage access logic in
RequiredCommand
into a separate class likeRequiredCommandStorage
. This way,RequiredCommand
becomes more lean since it doesn't need to store storage fields and their setters/getters. It also adheres to the single-responsibility and open-closed principle cosRequiredCommand
doesn't need to care abt how it gets the data, and we are free to change the storage logic without touchingRequiredCommand
next time.RequiredCommand
can then call stuff like.getFoundationModules()
- We can't store the JSON files in the
main/data
directory cos they won't be bundled by ShadowJar and the smoke tests won't work properly. They need to be put in the resources folder instead. BUT ITS OK I also just realised this cos themodules.json
in Nusmods needs to move too oooops
src/main/java/seedu/address/logic/commands/RequiredCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/seedu/address/logic/commands/RequiredCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/seedu/address/logic/commands/RequiredCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/seedu/address/logic/commands/RequiredCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/seedu/address/logic/commands/RequiredCommand.java
Outdated
Show resolved
Hide resolved
src/main/java/seedu/address/logic/commands/RequiredCommand.java
Outdated
Show resolved
Hide resolved
public void setFoundationStorageInvalidPath_returnsEmptyOptional() throws IOException, DataConversionException { | ||
requiredCommand.setFoundationStorage(INVALID_PATH); | ||
Optional<ReadOnlyGradPad> actual = requiredCommand.getFoundationStorage(); | ||
assertEquals(actual, Optional.empty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can consider using this instead:
assertEquals(actual, Optional.empty()); | |
assertTrue(actual.isEmpty()); |
As mentioned in the java API, it's generally not recommended to do equality checks for Optionals cos they produce unpredictable results 😁 Same applies for the other tests below and also ScienceCommandTest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay roger doger! changed accordingly
As per Sam's reviews, I have made some changes to the PR. The major changes are as such: RequiredCommandStorage Added this class to deal with all the pulling of modules from the respective JSON files. RequiredCommandMessages Added this class to store all the standard messages and paths that the RequiredCommand will use. RequiredCommand
ScienceCommand
RequiredCommandTest Changed the tests to suit the new methods RequiredCommandStorageTest Added the test class to test the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Nice one Yan! 💯💯💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the previous comments! The code looks great :D Just a few more clarifications cos I got confused at some parts ><
for (Module module : requiredScience) { | ||
if (doesModuleAlreadyExist(module, currentModules)) { | ||
leftOverModules += MESSAGE_SUCCESS_SCIENCE + "\n"; | ||
areModulesCleared = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't areModulesCleared
become true when we find out that the user has taken a science module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidentally flipped the booleans HAHAH changed the conditions and booleans accordingly
} if (areModulesCleared) { | ||
leftOverModules += MESSAGE_SCIENCE + "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise if areModulesCleared
is true then shouldn't we be showing MESSAGE_SUCCESS_SCIENCE instead since the user has cleared this basket HAHA
if (doesModuleAlreadyExist(module, currentModules)) { | ||
int modularCredits = Integer.parseInt(module.getModularCredits().toString()); | ||
modularScore += modularCredits; | ||
areModulesCleared = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come taking a single internship module means that areModulesCleared
is false ahh? I tot it should only be false if total MCs < 12 since we need >= 12 in order to clear the internship basket ><
I FEEL LIKE IM MISSING SOMETHING OBVIOUS LOL SO PLS FORGIVE ME IF I AM HAHA IM DAMN CONFUSED
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for the misleading boolean names AHAHHA changed the whole code, so no more booleans, just an If-else block to settle if the module is present or not
boolean areModulesCleared = true; | ||
if (doesModuleAlreadyExist(module, currentModules)) { | ||
int modularCredits = Integer.parseInt(module.getModularCredits().toString()); | ||
modularScore += modularCredits; | ||
areModulesCleared = false; | ||
} | ||
if (areModulesCleared) { | ||
String moduleToAdd = module.getModuleCode() + " (" + module.getModularCredits() + " MCs)"; | ||
leftOverInternship.append("\n").append(moduleToAdd); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually how come we need the areModulesCleared
flag instead of using an if-else statement ahhh?
Just to clarify, is this code saying: if a module is taken, then add its MCs to modularScore
. If it's not, add the module title/mc to the result to display instead.
PAISEH I'm very confused here ><
boolean areModulesCleared = true; | |
if (doesModuleAlreadyExist(module, currentModules)) { | |
int modularCredits = Integer.parseInt(module.getModularCredits().toString()); | |
modularScore += modularCredits; | |
areModulesCleared = false; | |
} | |
if (areModulesCleared) { | |
String moduleToAdd = module.getModuleCode() + " (" + module.getModularCredits() + " MCs)"; | |
leftOverInternship.append("\n").append(moduleToAdd); | |
} | |
if (doesModuleAlreadyExist(module, currentModules)) { | |
int modularCredits = Integer.parseInt(module.getModularCredits().toString()); | |
modularScore += modularCredits; | |
} else { | |
String moduleToAdd = module.getModuleCode() + " (" + module.getModularCredits() + " MCs)"; | |
leftOverInternship.append("\n").append(moduleToAdd); | |
} |
Codecov Report
@@ Coverage Diff @@
## master #97 +/- ##
============================================
+ Coverage 73.31% 73.70% +0.39%
- Complexity 424 460 +36
============================================
Files 76 79 +3
Lines 1274 1392 +118
Branches 123 141 +18
============================================
+ Hits 934 1026 +92
+ Misses 302 293 -9
- Partials 38 73 +35 Continue to review full report at Codecov.
|
RequiredCommand
ScienceCommand
-Added Science command that displays all the available Science modules.
-Can be accessed by typing 'science'
General Design Approach
-The RequiredCommand and ScienceCommand have various attributes to help store the modules, namely a ReadOnlyGradPad for storage of modules and an actual ObservableList to do the comparisons with.
-Each module category will have a method to set up the module storage(eg. setFoundationStorage) and compare that storage against the user's currents modules (compareFoundation) to see if the user is missing anything out.
-The execute method then invokes all the various methods to set up the storages and does the comparisons, keeping track of all the undone modules, before displaying it to the user.
Notes
Since the command works by retrieving the stored modules in a JSON file and that the RequiredCommand extends the Command class, I had to change the execute method, to allow it to throw IOExceptions and DataConversionExceptions so that it can handle exceptions if the JSON file is not found. As a result, I changed a couple methods to throw IOExceptions and DataConversionExceptions, but this should not affect the general flow of the app.