Skip to content

Commit

Permalink
Merge pull request #85 from Geinzit/master
Browse files Browse the repository at this point in the history
update text-ui-test content for Java CI tests and more fixes
  • Loading branch information
Geinzit authored Apr 10, 2024
2 parents 84c2251 + 3e1f517 commit b445e38
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 45 deletions.
5 changes: 2 additions & 3 deletions src/main/java/seedu/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public static void solveProbSet(Test test, Ui ui, boolean retry, int id) {
double speed = (double) test.getNumber() / checker.getTime() * 60;
if (retry) {
Storage.addRecord(new Record(LocalDateTime.now(), speed, checker.getAccuracy(), test.getProblem(), id));
}
else {
} else {
Storage.addRecord(new Record(LocalDateTime.now(), speed, checker.getAccuracy(), test.getProblem()));
}
Storage.writeFile();
Expand Down Expand Up @@ -141,4 +140,4 @@ public static void parse(String command, Ui ui) {
break;
}
}
}
}
23 changes: 13 additions & 10 deletions src/main/java/seedu/duke/ProblemGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import static java.lang.Character.isDigit;

public class ProblemGenerator {
public static final int MAXIMUM_LENGTH = 10;
static final String DEFAULT_NUMBER = "10";
static final String DEFAULT_MAX_DIGITS = "2";
static final String DEFAULT_OPERATORS = VALID_OPERATORS;
static final String DEFAULT_LENGTH = "2";
public static final int MINIMUM_NUMBER = 0;
public static final int MAXIMUM_NUMBER = 100;

private static final int MINIMUM_NUMBER = 0;
private static final int MAXIMUM_NUMBER = 100;
private static final int MINIMUM_DIGIT = 0 ;
public static final int MAXIMUM_DIGITS = 9;
public static final int MINIMUM_LENGTH = 2;
public static final String VALID_OPERATORS = "+-*/";
private static final int MAXIMUM_DIGITS = 9;
private static final int MINIMUM_LENGTH = 2;
private static final String VALID_OPERATORS = "+-*/";
private static final int MAXIMUM_LENGTH = 10;
private static final String DEFAULT_NUMBER = "10";
private static final String DEFAULT_MAX_DIGITS = "2";
private static final String DEFAULT_OPERATORS = VALID_OPERATORS;
private static final String DEFAULT_LENGTH = "2";

public static HashMap<String, String> parseCommand(String command) {
HashMap<String, String> options = new HashMap<>();
Expand All @@ -39,6 +40,8 @@ public static HashMap<String, String> parseCommand(String command) {
case "-l":
options.put("length", tokens[i + 1]);
break;
default:
break;
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/test/java/seedu/duke/ProblemGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ private HashMap<String, String> parseCommand(String command) {

private ArrayList<Integer> parseNumbers(String problem) {

// 使用正则表达式匹配数字和运算符
Pattern pattern = Pattern.compile("-?\\d+");
Matcher matcher = pattern.matcher(problem);

// 提取匹配到的数字

ArrayList<Integer> numbers = new ArrayList<>();
while (matcher.find()) {
numbers.add(Integer.parseInt(matcher.group()));
Expand Down
8 changes: 0 additions & 8 deletions src/test/java/seedu/duke/StorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,42 @@ public static void testSortRecords() {
Storage.addRecord(record2);
Storage.addRecord(record3);

// 根据日期排序
ArrayList<Record> sortedByDate = Storage.sortRecords(1, 0, 0, 0);
assertEquals(record1, sortedByDate.get(0));
assertEquals(record2, sortedByDate.get(1));
assertEquals(record3, sortedByDate.get(2));

// 根据日期倒序排序
ArrayList<Record> reverseSortedByDate = Storage.sortRecords(2, 0, 0, 0);
assertEquals(record3, reverseSortedByDate.get(0));
assertEquals(record2, reverseSortedByDate.get(1));
assertEquals(record1, reverseSortedByDate.get(2));

// 根据速度排序
ArrayList<Record> sortedBySpeed = Storage.sortRecords(0, 1, 0, 0);
assertEquals(record1, sortedBySpeed.get(0));
assertEquals(record2, sortedBySpeed.get(1));
assertEquals(record3, sortedBySpeed.get(2));

// 根据速度倒序排序
ArrayList<Record> reverseSortedBySpeed = Storage.sortRecords(0, 2, 0, 0);
assertEquals(record3, reverseSortedBySpeed.get(0));
assertEquals(record2, reverseSortedBySpeed.get(1));
assertEquals(record1, reverseSortedBySpeed.get(2));

// 根据准确率排序
ArrayList<Record> sortedByAccuracy = Storage.sortRecords(0, 0, 1, 0);

assertEquals(record2, sortedByAccuracy.get(0));
assertEquals(record1, sortedByAccuracy.get(1));
assertEquals(record3, sortedByAccuracy.get(2));

// 根据准确率倒序排序
ArrayList<Record> reverseSortedByAccuracy = Storage.sortRecords(0, 0, 2, 0);
assertEquals(record3, reverseSortedByAccuracy.get(0));
assertEquals(record1, reverseSortedByAccuracy.get(1));
assertEquals(record2, reverseSortedByAccuracy.get(2));

// 根据问题集索引排序
ArrayList<Record> sortedByProblemIndex = Storage.sortRecords(0, 0, 0, 1);
assertEquals(record1, sortedByProblemIndex.get(0));
assertEquals(record2, sortedByProblemIndex.get(1));
assertEquals(record3, sortedByProblemIndex.get(2));

// 根据问题集索引倒序排序
ArrayList<Record> reverseSortedByProblemIndex = Storage.sortRecords(0, 0, 0, 2);
assertEquals(record3, reverseSortedByProblemIndex.get(0));
assertEquals(record2, reverseSortedByProblemIndex.get(1));
Expand Down
28 changes: 16 additions & 12 deletions src/test/java/seedu/duke/UiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,32 @@ public void setUp() {
@Test
public void helpTest() {
ui.help("gen");
String expectedOutput = "Generate problem sets: \tgen -t [type] -n [number] -d [maximum digits]\n" +
"Input Instructions:\n" +
"[operators]: can be + - * /, you can combine any of them.\n" +
"[number]: number of problem set generated\n" +
"[maximum digit]: how big can the calculation be\n\n" +
"For example: generate -t + -n 10 -d 2 -l 2\n" +
"-> generate 10 problems with + and - operator, each has 2 numbers taking operations\n" +
"and the maximum number of digits is 2 (99 max)\n" +
"=========================\n";
assertEquals(expectedOutput, output.toString());
String expectedOutput = "Generate problem sets: gen -t [type] -n [number] -d [maximum digits]" +
"Input Instructions:" +
"[operators]: can be + - * /, you can combine any of them." +
"[number]: number of problem set generated" +
"[maximum digit]: how big can the calculation be" +
"For example: generate -t + -n 10 -d 2 -l 2" +
"-> generate 10 problems with + and - operator, each has 2 numbers taking operations" +
"and the maximum number of digits is 2 (99 max)" +
"=========================";
String cleanOutput = output.toString().replaceAll("\n", "").replaceAll("\t", "");

assertEquals(expectedOutput, cleanOutput);
}


@Test
public void invalidCommandTest() {
ui.invalidCommand();
assertEquals("Invalid command! Please try again.\n", output.toString());
String cleanOutput = output.toString().replaceAll("\n", "").replaceAll("\t", "");
assertEquals("Invalid command! Please try again.=========================", cleanOutput);
}

@Test
public void exitTest() {
ui.exit();
assertEquals("Bye. Hope to see you again soon!\n=========================\n", output.toString());
String cleanOutput = output.toString().replaceAll("\n", "").replaceAll("\t", "");
assertEquals("Bye. Hope to see you again soon!=========================", cleanOutput);
}
}
22 changes: 14 additions & 8 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
=========================
__ __ _ _ ____ _
| \/ | __ _| |_| |__ / ___| ___ _ __ (_)_ _ ___
| |\/| |/ _` | __| '_ \| | _ / _ \ '_ \| | | | / __|
| | | | (_| | |_| | | | |_| | __/ | | | | |_| \__ \
|_| |_|\__,_|\__|_| |_|\____|\___|_| |_|_|\__,_|___/

What is your name?
Hello James Gosling
Hello! I'm MathGenius!
Type 'help' to see the instructions.

=========================
Storage: No past records found. Starting anew!
=========================
Bye. Hope to see you again soon!
=========================
2 changes: 1 addition & 1 deletion text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
James Gosling
exit

0 comments on commit b445e38

Please sign in to comment.