Skip to content

Commit 9e74dcb

Browse files
committed
정규식 및 테스트 파일 수정
1 parent 92ebeca commit 9e74dcb

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package me.kimihiqq;
22

3+
import me.kimihiqq.model.History;
4+
35
public class Application {
46
public static void main(String[] args) {
57
Console console = new Console();
6-
new Calculator(console, console).run();
8+
History history = new History();
9+
new Calculator(console, console, history).run();
710
}
811
}

src/main/java/me/kimihiqq/Calculator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Calculator implements Runnable {
1313

1414
private final Input scanner;
1515
private final Output printer;
16-
private final History history = new History();
16+
private final History history;
1717

1818
public void run() {
1919

@@ -81,7 +81,6 @@ public void calculate() {
8181
.append(terms.get(0))
8282
.toString();
8383
history.add(result);
84-
8584
}
8685

8786
public void list() {

src/main/java/me/kimihiqq/Pretreatment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static List<String> parseFormula(String formula) {
1212
}
1313

1414
public static boolean validateFormula(String formula) {
15-
if (!formula.matches("^(\\d\\s[+\\-*/]\\s)+\\d$")) {
15+
if (!formula.matches("^(-*\\d\\s[+\\-*/]\\s)+\\d$")) {
1616
System.out.println("Invalid formula!");
1717
return false;
1818
}

src/test/java/me/kimihiqq/CalculatorTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import me.kimihiqq.io.Input;
44
import me.kimihiqq.io.Output;
5+
import me.kimihiqq.model.History;
56
import org.junit.jupiter.api.Test;
67
import org.mockito.Mockito;
78
import static org.mockito.Mockito.*;
@@ -10,25 +11,27 @@ public class CalculatorTest {
1011

1112
@Test
1213
public void testCalculate() {
14+
History history = new History();
1315
Input mockInput = Mockito.mock(Input.class);
1416
Output mockOutput = Mockito.mock(Output.class);
1517

1618
when(mockInput.nextLine()).thenReturn("1 + 2 * 3");
1719

18-
Calculator calculator = new Calculator(mockInput, mockOutput);
20+
Calculator calculator = new Calculator(mockInput, mockOutput, history);
1921
calculator.calculate();
2022

2123
verify(mockOutput).println("7");
2224
}
2325

2426
@Test
2527
public void testList() {
28+
History history = new History();
2629
Input mockInput = Mockito.mock(Input.class);
2730
Output mockOutput = Mockito.mock(Output.class);
2831

2932
when(mockInput.nextLine()).thenReturn("5 + 6", "4 * 2");
3033

31-
Calculator calculator = new Calculator(mockInput, mockOutput);
34+
Calculator calculator = new Calculator(mockInput, mockOutput, history);
3235
calculator.calculate();
3336
calculator.calculate();
3437

0 commit comments

Comments
 (0)