11package com .github .refhumbold .algolib .text ;
22
3- import java .util .List ;
4- import java .util .stream .IntStream ;
53import java .util .stream .Stream ;
64import org .assertj .core .api .Assertions ;
75import org .junit .jupiter .api .BeforeEach ;
86import org .junit .jupiter .api .Test ;
97import org .junit .jupiter .params .ParameterizedTest ;
108import org .junit .jupiter .params .provider .Arguments ;
119import org .junit .jupiter .params .provider .MethodSource ;
10+ import org .junit .jupiter .params .provider .ValueSource ;
1211import com .github .refhumbold .algolib .tuples .Pair ;
1312
1413// Tests: Structure of basic factors map using Karp-Miller-Rosenberg algorithm.
@@ -23,7 +22,7 @@ public void setUp()
2322 }
2423
2524 @ ParameterizedTest
26- @ MethodSource ("paramsFor_GetCode_WhenRange " )
25+ @ MethodSource ("paramsFor_getCode_WhenRange " )
2726 public void getCode_WhenRange_ThenCode (
2827 int startIndex ,
2928 Integer endIndex ,
@@ -52,33 +51,35 @@ public void getCode_WhenStartIndexGreaterThanEndIndex_ThenIllegalArgumentExcepti
5251 .isInstanceOf (IllegalArgumentException .class );
5352 }
5453
55- @ Test
56- public void getCode_WhenInvalidStartIndex_ThenIndexOutOfRangeException ()
54+ @ ParameterizedTest
55+ @ ValueSource (ints = { -1 , 22 })
56+ public void getCode_WhenInvalidStartIndex_ThenIndexOutOfRangeException (int index )
5757 {
58- Assertions .assertThatThrownBy (() -> testObject .getCode (- 1 ))
58+ Assertions .assertThatThrownBy (() -> testObject .getCode (index ))
5959 .isInstanceOf (IndexOutOfBoundsException .class );
6060 }
6161
62- @ Test
63- public void getCode_WhenInvalidEndIndex_ThenIndexOutOfRangeException ()
62+ @ ParameterizedTest
63+ @ MethodSource ("paramsFor_getCode_WhenInvalidStartAndEndIndices" )
64+ public void getCode_WhenInvalidStartAndEndIndices_ThenIndexOutOfRangeException (
65+ int startIndex ,
66+ int endIndex )
6467 {
65- Assertions .assertThatThrownBy (() -> testObject .getCode (5 , 15 ))
68+ Assertions .assertThatThrownBy (() -> testObject .getCode (startIndex , endIndex ))
6669 .isInstanceOf (IndexOutOfBoundsException .class );
6770 }
6871
69- private static Stream <Arguments > paramsFor_GetCode_WhenRange ()
72+ private static Stream <Arguments > paramsFor_getCode_WhenInvalidStartAndEndIndices ()
7073 {
71- Integer [][] indices = {
72- { 0 , 1 }, { 0 , 3 }, { 0 , null }, { 1 , 2 }, { 3 , 4 }, { 3 , 7 }, { 4 , 6 },
73- { 7 , null }, { 8 , 9 }, { 8 , 10 }
74- };
75- List <Pair <Integer , Integer >> expectedResults =
76- Stream .of (Pair .of (2 , 0 ), Pair .of (7 , 6 ), Pair .of (20 , 21 ), Pair .of (1 , 0 ),
77- Pair .of (4 , 0 ), Pair .of (16 , 0 ), Pair .of (6 , 0 ), Pair .of (12 , 0 ), Pair .of (3 , 0 ),
78- Pair .of (9 , 0 )).toList ();
74+ return Stream .of (Arguments .of (5 , 15 ), Arguments .of (18 , 28 ), Arguments .of (-3 , 3 ));
75+ }
7976
80- return IntStream .range (0 , indices .length )
81- .mapToObj (i -> Arguments .of (indices [i ][0 ], indices [i ][1 ],
82- expectedResults .get (i )));
77+ private static Stream <Arguments > paramsFor_getCode_WhenRange ()
78+ {
79+ return Stream .of (Arguments .of (0 , 1 , Pair .of (2 , 0 )), Arguments .of (0 , 3 , Pair .of (7 , 6 )),
80+ Arguments .of (0 , null , Pair .of (20 , 21 )), Arguments .of (1 , 2 , Pair .of (1 , 0 )),
81+ Arguments .of (3 , 4 , Pair .of (4 , 0 )), Arguments .of (3 , 7 , Pair .of (16 , 0 )),
82+ Arguments .of (4 , 6 , Pair .of (6 , 0 )), Arguments .of (7 , null , Pair .of (12 , 0 )),
83+ Arguments .of (8 , 9 , Pair .of (3 , 0 )), Arguments .of (8 , 10 , Pair .of (9 , 0 )));
8384 }
8485}
0 commit comments