Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b9b4aa

Browse filesBrowse files
committed
Refactor to utils class
1 parent 61ca2c7 commit 2b9b4aa
Copy full SHA for 2b9b4aa

2 files changed

+30-12Lines changed: 30 additions & 12 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/test/java/sort/SelectionSort.java‎

Copy file name to clipboardExpand all lines: src/test/java/sort/SelectionSort.java
+2-12Lines 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
}
Collapse file

‎src/test/java/utils/Utils.java‎

Copy file name to clipboard
+28Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.