Skip to content

Commit

Permalink
Improve user guide & code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamHaiweiGu committed Feb 19, 2023
1 parent ae1a840 commit 34946cf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 24 deletions.
8 changes: 6 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Meggy is a command-line interactive task management `jar` program with GUI. It supports task addition, deletion, and
lookup.
![Ui](Ui.png)

## Getting started

Expand Down Expand Up @@ -235,8 +236,11 @@ need to save manually.

Meggy data are saved as a text file `MeggyData.txt`. Advanced users are welcome to update data directly by editing that
data file.

If your changes to the data file makes its format invalid, Meggy will stop loading upon the first syntax error, give you
<br>
Changes to the data file during a Meggy session will not be kept once Meggy successfully executes a command that changes
task list.
<br>
If your changes to the data file make its format invalid, Meggy will stop loading upon the first syntax error, give you
a warning message, and only load the tasks already read.

## Command summary
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/MeggyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

import org.junit.jupiter.api.Test;

import meggy.*;
import meggy.Meggy;
import meggy.MeggyTime;
import meggy.Resource;
import meggy.TaskList;
import meggy.Util;
import meggy.exception.Function;
import meggy.exception.MeggyException;
import meggy.task.DdlTask;
Expand All @@ -21,10 +25,11 @@
public class MeggyTest {
private static final Random RAND = new Random();
/** Roughly 400 loops per second */
private static final int N_LOOP = 60 * 400;
private static final int N_LOOP = 120 * 400;
private static final int N_CORE = Runtime.getRuntime().availableProcessors();
private static final Consumer<String> DROP = s -> {
};
private static final File TEST_DIR = new File("test");

private static final Supplier<String> todoInput = MeggyTest::randString;
private static final Supplier<String> ddlInput = () -> {
Expand Down Expand Up @@ -57,6 +62,7 @@ public class MeggyTest {
newTasks[0] = Util.TODO_NEW;
newTasks[1] = Util.DDL_NEW;
newTasks[2] = Util.EVENT_NEW;
TEST_DIR.mkdir();
}

/** @return String that will never be entirely whitespace. */
Expand All @@ -82,7 +88,8 @@ private static MeggyTime randMeggyTime() {
: LocalDateTime.ofEpochSecond(RAND.nextInt(), 0, ZoneOffset.UTC).format(MeggyTime.OUT_FMT));
}

private static <T extends UserTask> void taskIntegrityTest(Supplier<String> randInput, Function<String, T> newTask) {
private static <T extends UserTask> void taskIntegrityTest(
Supplier<String> randInput, Function<String, T> newTask) {
final String s = randInput.get();
try {
final T a = newTask.apply(s);
Expand All @@ -94,11 +101,8 @@ private static <T extends UserTask> void taskIntegrityTest(Supplier<String> rand
}
}

private static void randStorageTest(int iTest) throws MeggyException {
private static void randStorageTest(File storageFile) throws MeggyException {
final int listLenMax = 50;
final File testDir = new File("test");
testDir.mkdir();
final File storageFile = new File(testDir, iTest + ".txt");
final Meggy m1 = new Meggy(storageFile);
m1.bindUi(DROP);

Expand Down Expand Up @@ -165,20 +169,21 @@ public void bulkIntegrityTest() {
});
}


@Test
public void bulkStorageTest() {
final int nTest = N_LOOP / 200 * N_CORE;
IntStream.range(0, nTest).parallel().forEach(iTest -> {
try {
randStorageTest(iTest);
randStorageTest(new File(TEST_DIR, iTest + ".txt"));
} catch (MeggyException e) {
throw new RuntimeException(e);
}
});
}

@Test
public void randStorageTest() throws MeggyException {
randStorageTest(-1);
public void storageTest() throws MeggyException {
randStorageTest(new File(TEST_DIR, ".txt"));
}
}
10 changes: 5 additions & 5 deletions src/main/java/meggy/MeggyTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ public static LocalDateTime parseDateTime(String dateTime) {
return null;
}

/** @return User-customized time string in square brackets or formatted date-time. */
public String toString() {
return formatted == null ? '[' + customized + ']' : formatted.format(OUT_FMT);
}

/**
* Two {@link MeggyTime} objects are equal iff they have same (equal or both null) formatted time and customized
* time.
Expand All @@ -103,4 +98,9 @@ public boolean equals(Object o) {
final MeggyTime other = (MeggyTime) o;
return Objects.equals(formatted, other.formatted) && Objects.equals(customized, other.customized);
}

/** @return User-customized time string in square brackets or formatted date-time. */
public String toString() {
return formatted == null ? '[' + customized + ']' : formatted.format(OUT_FMT);
}
}
12 changes: 6 additions & 6 deletions src/main/java/meggy/task/DdlTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public String recreateCmd() {
return Resource.CMD_DDL + ' ' + args;
}

/** @inheritDoc */
@Override
public String toString() {
return LABEL + super.toString() + " (by: " + due + ')';
}

/** Two {@link DdlTask} objects are equal iff they have same (non-null) description and due time. */
@Override
public boolean equals(Object o) {
Expand All @@ -62,10 +68,4 @@ public boolean equals(Object o) {
final DdlTask other = (DdlTask) o;
return due.equals(other.due) && desc.equals(other.desc);
}

/** @inheritDoc */
@Override
public String toString() {
return LABEL + super.toString() + " (by: " + due + ')';
}
}
3 changes: 2 additions & 1 deletion src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity"
prefHeight="600.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.171"
Expand Down

0 comments on commit 34946cf

Please sign in to comment.