Skip to content

Commit

Permalink
Bugs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
YangYue128-helen committed Sep 6, 2020
1 parent 2d795cd commit 741ef88
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test {
}

application {
mainClassName = "duke.Duke"
mainClassName = "duke.Launcher"
}

shadowJar {
Expand Down
3 changes: 2 additions & 1 deletion data/tasks.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
T | 0 | i
T | 1 | 1
D | 1 | e | Dec 12 2020 12:12
19 changes: 9 additions & 10 deletions src/main/java/duke/tool/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ public Storage(String filePath) {
* @throws IOException
*/
public ArrayList<Task> loadData() throws IOException {
DateTimeFormatter validFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
DateTimeFormatter validFormat = DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm");
ArrayList<Task> orderList = new ArrayList<>();

try {
File dataStorage = new File(filePath);
Scanner s = new Scanner(dataStorage);
while (s.hasNext()) {
String curr = s.nextLine();
String[] currTask = curr.split("|");
Boolean isDone = currTask[1] == "1";
if (currTask[0] == "T") {
String[] currTask = curr.split(" \\| ");
Boolean isDone = currTask[1].equals("1");
if (currTask[0].equals("T")) {
orderList.add(new Todo(currTask[2], isDone));
} else if (currTask[0] == "D") {
} else if (currTask[0].equals("D")) {
orderList.add(new Deadline(currTask[2],
LocalDateTime.parse(currTask[3], validFormat), isDone));
} else if (currTask[0] == "E") {
} else if (currTask[0].equals("E")) {
orderList.add(new Event(currTask[2],
LocalDateTime.parse(currTask[3], validFormat), isDone));
}
Expand All @@ -59,19 +59,18 @@ public ArrayList<Task> loadData() throws IOException {
System.out.println("File duke.txt does not exist yet.");
}
}

return orderList;

}

/**
* Write the changed message into the file.
* @param orderlist
* @param orderList
*/
public void writeData(ArrayList<Task> orderlist) {
public void writeData(ArrayList<Task> orderList) {
try {
FileWriter fw = new FileWriter(filePath, false);
for (Task task : orderlist) {
for (Task task : orderList) {
fw.write(task.fileFormattedString() + "\n");
}
fw.close();
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/duke/LoadDataTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package duke;

import duke.tool.Storage;
import duke.tool.TaskList;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class LoadDataTest {
@Test
public void LoadDataTest() throws IOException {
Storage storage = new Storage("data/tasks.txt");
TaskList l = new TaskList(storage.loadData());
assertEquals(l.getTask(0).toString(), 1);

}
}

0 comments on commit 741ef88

Please sign in to comment.