File tree Expand file tree Collapse file tree 4 files changed +11
-5
lines changed Expand file tree Collapse file tree 4 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 11package me .kimihiqq ;
22
3+ import me .kimihiqq .model .History ;
4+
35public 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}
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 22
33import me .kimihiqq .io .Input ;
44import me .kimihiqq .io .Output ;
5+ import me .kimihiqq .model .History ;
56import org .junit .jupiter .api .Test ;
67import org .mockito .Mockito ;
78import 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
You can’t perform that action at this time.
0 commit comments