1
+ package com .baeldung .algorithms .smallestinteger ;
2
+
3
+ import org .junit .jupiter .api .Test ;
4
+
5
+ import static org .assertj .core .api .Assertions .assertThat ;
6
+
7
+ class SmallestMissingPositiveIntegerUnitTest {
8
+ @ Test
9
+ void givenArrayWithThreeMissing_whenSearchInSortedArray_thenThree () {
10
+ int [] input = new int [] {0 , 1 , 2 , 4 , 5 };
11
+
12
+ int result = SmallestMissingPositiveInteger .searchInSortedArray (input );
13
+
14
+ assertThat (result ).isEqualTo (3 );
15
+ }
16
+
17
+ @ Test
18
+ void givenArrayWithOneAndThreeMissing_whenSearchInSortedArray_thenOne () {
19
+ int [] input = new int [] {0 , 2 , 4 , 5 };
20
+
21
+ int result = SmallestMissingPositiveInteger .searchInSortedArray (input );
22
+
23
+ assertThat (result ).isEqualTo (1 );
24
+ }
25
+
26
+ @ Test
27
+ void givenArrayWithoutMissingInteger_whenSearchInSortedArray_thenArrayLength () {
28
+ int [] input = new int [] {0 , 1 , 2 , 3 , 4 , 5 };
29
+
30
+ int result = SmallestMissingPositiveInteger .searchInSortedArray (input );
31
+
32
+ assertThat (result ).isEqualTo (input .length );
33
+ }
34
+
35
+ @ Test
36
+ void givenArrayWithThreeMissing_whenSearchInUnsortedArraySortingFirst_thenThree () {
37
+ int [] input = new int [] {1 , 4 , 0 , 5 , 2 };
38
+
39
+ int result = SmallestMissingPositiveInteger .searchInUnsortedArraySortingFirst (input );
40
+
41
+ assertThat (result ).isEqualTo (3 );
42
+ }
43
+
44
+ @ Test
45
+ void givenArrayWithOneAndThreeMissing_whenSearchInUnsortedArraySortingFirst_thenOne () {
46
+ int [] input = new int [] {4 , 2 , 0 , 5 };
47
+
48
+ int result = SmallestMissingPositiveInteger .searchInUnsortedArraySortingFirst (input );
49
+
50
+ assertThat (result ).isEqualTo (1 );
51
+ }
52
+
53
+ @ Test
54
+ void givenArrayWithoutMissingInteger_whenSearchInUnsortedArraySortingFirst_thenArrayLength () {
55
+ int [] input = new int [] {4 , 5 , 1 , 3 , 0 , 2 };
56
+
57
+ int result = SmallestMissingPositiveInteger .searchInUnsortedArraySortingFirst (input );
58
+
59
+ assertThat (result ).isEqualTo (input .length );
60
+ }
61
+
62
+ @ Test
63
+ void givenArrayWithThreeMissing_whenSearchInUnsortedArrayBooleanArray_thenThree () {
64
+ int [] input = new int [] {1 , 4 , 0 , 5 , 2 };
65
+
66
+ int result = SmallestMissingPositiveInteger .searchInUnsortedArrayBooleanArray (input );
67
+
68
+ assertThat (result ).isEqualTo (3 );
69
+ }
70
+
71
+ @ Test
72
+ void givenArrayWithOneAndThreeMissing_whenSearchInUnsortedArrayBooleanArray_thenOne () {
73
+ int [] input = new int [] {4 , 2 , 0 , 5 };
74
+
75
+ int result = SmallestMissingPositiveInteger .searchInUnsortedArrayBooleanArray (input );
76
+
77
+ assertThat (result ).isEqualTo (1 );
78
+ }
79
+
80
+ @ Test
81
+ void givenArrayWithoutMissingInteger_whenSearchInUnsortedArrayBooleanArray_thenArrayLength () {
82
+ int [] input = new int [] {4 , 5 , 1 , 3 , 0 , 2 };
83
+
84
+ int result = SmallestMissingPositiveInteger .searchInUnsortedArrayBooleanArray (input );
85
+
86
+ assertThat (result ).isEqualTo (input .length );
87
+ }
88
+ }
0 commit comments