44
55import java .io .*;
66import java .util .ArrayList ;
7- import java .util .Arrays ;
87import java .util .List ;
9- import java .util .stream .Collectors ;
108
9+ import static algorithms .sprint0 .Utils .readInt ;
10+ import static algorithms .sprint0 .Utils .readList ;
1111import static org .junit .jupiter .api .Assertions .assertEquals ;
1212
1313public class SlidingAverage {
@@ -40,18 +40,6 @@ public static void main(String[] args) throws IOException {
4040 }
4141 }
4242
43-
44- private static int readInt (BufferedReader reader ) throws IOException {
45- return Integer .parseInt (reader .readLine ());
46- }
47-
48- private static List <Integer > readList (BufferedReader reader ) throws IOException {
49- return Arrays .asList (reader .readLine ().split (" " ))
50- .stream ()
51- .map (elem -> Integer .parseInt (elem ))
52- .collect (Collectors .toList ());
53- }
54-
5543 private static void assertListDoubles (List <Double > actual , double ... expected ) {
5644 assertEquals (expected .length , actual .size (), "size" );
5745 for (int i = 0 ; i < expected .length ; i ++) {
@@ -67,31 +55,31 @@ void test1() {
6755
6856 @ Test
6957 void w1_returnsOriginalValues () {
70- List <Double > actual = movingAverage (7 , List .of (1 ,2 , 3 , 4 , 5 , 6 , 7 ), 1 );
71- assertListDoubles (actual , 1 ,2 , 3 , 4 , 5 , 6 , 7 );
58+ List <Double > actual = movingAverage (7 , List .of (1 , 2 , 3 , 4 , 5 , 6 , 7 ), 1 );
59+ assertListDoubles (actual , 1 , 2 , 3 , 4 , 5 , 6 , 7 );
7260 }
7361
7462 @ Test
7563 void wEqMin_singleAverage () {
76- List <Double > actual = movingAverage (7 , List .of (1 ,2 , 3 , 4 , 5 , 6 , 7 ), 7 );
64+ List <Double > actual = movingAverage (7 , List .of (1 , 2 , 3 , 4 , 5 , 6 , 7 ), 7 );
7765 assertListDoubles (actual , 4.0 );
7866 }
7967
8068 @ Test
8169 void wGreaterThanMin_empty () {
82- List <Double > actual = movingAverage (5 , List .of (1 ,2 , 3 , 4 , 5 , 6 , 7 ), 6 );
70+ List <Double > actual = movingAverage (5 , List .of (1 , 2 , 3 , 4 , 5 , 6 , 7 ), 6 );
8371 assertEquals (List .of (), actual );
8472 }
8573
8674 @ Test
8775 void wZeroOrNegative_empty () {
88- assertEquals (List .of (), movingAverage (5 , List .of (1 ,2 , 3 , 4 , 5 ), 0 ));
89- assertEquals (List .of (), movingAverage (5 , List .of (1 ,2 , 3 , 4 , 5 ), -3 ));
76+ assertEquals (List .of (), movingAverage (5 , List .of (1 , 2 , 3 , 4 , 5 ), 0 ));
77+ assertEquals (List .of (), movingAverage (5 , List .of (1 , 2 , 3 , 4 , 5 ), -3 ));
9078 }
9179
9280 @ Test
9381 void cutByN_truncatesAndAverages () {
94- List <Double > actual = movingAverage (5 , List .of (1 ,2 , 3 , 4 , 5 , 6 , 7 ), 3 );
82+ List <Double > actual = movingAverage (5 , List .of (1 , 2 , 3 , 4 , 5 , 6 , 7 ), 3 );
9583 // окна по первым 5 элементам: [1,2,3],[2,3,4],[3,4,5]
9684 assertListDoubles (actual , 2.0 , 3.0 , 4.0 );
9785 }
0 commit comments