Skip to content

Commit 2b9b4aa

Browse files
committed
Refactor to utils class
1 parent 61ca2c7 commit 2b9b4aa

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/test/java/sort/SelectionSort.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sort;
22

33
import org.junit.Test;
4+
import utils.Utils;
45

56
import static org.hamcrest.CoreMatchers.is;
67
import static org.junit.Assert.assertThat;
@@ -23,10 +24,6 @@ public void test() {
2324
int[] arr3 = {1};
2425
int[] sortedArr3 = {1};
2526
assertThat(solution(arr3), is(sortedArr3));
26-
27-
int[] arr = {1,2,3};
28-
int[] chagedArr = {1,3,2};
29-
assertThat(swapValue(arr, 1,2), is(chagedArr));
3027
}
3128

3229
public int[] solution(int[] arr) {
@@ -41,15 +38,8 @@ public int[] solution(int[] arr) {
4138
maxPos = k;
4239
}
4340
}
44-
result = swapValue(result, i, maxPos);
41+
result = Utils.swapValue(result, i, maxPos);
4542
}
4643
return result;
4744
}
48-
49-
private int[] swapValue(int[] arr, int a, int b) {
50-
int temp = arr[a];
51-
arr[a] = arr[b];
52-
arr[b] = temp;
53-
return arr;
54-
}
5545
}

src/test/java/utils/Utils.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package utils;
2+
3+
import org.junit.Test;
4+
5+
import static org.hamcrest.CoreMatchers.is;
6+
import static org.junit.Assert.assertThat;
7+
8+
public class Utils {
9+
10+
/*
11+
TASK
12+
swap util 분리
13+
*/
14+
15+
@Test
16+
public void test() {
17+
int[] arr = {1,2,3};
18+
int[] chagedArr = {1,3,2};
19+
assertThat(swapValue(arr, 1,2), is(chagedArr));
20+
}
21+
22+
public static int[] swapValue(int[] arr, int a, int b) {
23+
int temp = arr[a];
24+
arr[a] = arr[b];
25+
arr[b] = temp;
26+
return arr;
27+
}
28+
}

0 commit comments

Comments
 (0)