-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Santiago Hyun
committed
May 2, 2023
1 parent
a13d1a0
commit 661a93b
Showing
7 changed files
with
249 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.unicauca</groupId> | ||
<artifactId>practice.junit_git</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.6.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>12</maven.compiler.source> | ||
<maven.compiler.target>12</maven.compiler.target> | ||
</properties> | ||
</project> |
24 changes: 24 additions & 0 deletions
24
maven/j_unit/src/main/java/com/unicauca/practice/junit_git/src/main/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.unicauca.practice.junit_git.src.main; | ||
|
||
import com.unicauca.practice.junit_git.src.sorting.SortingPractice; | ||
import com.unicauca.practice.junit_git.src.sorting.util.SortingUtil; | ||
/** | ||
* | ||
* @author sahydo | ||
*/ | ||
public class Main { | ||
|
||
/** | ||
* @param args the command line arguments | ||
*/ | ||
public static void main(String[] args) { | ||
SortingPractice practice = new SortingPractice(new int[] {3,25,6,8,83,32,5,7,1}, SortingUtil.BUBBLE_SORT); | ||
practice.sort(); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
maven/j_unit/src/main/java/com/unicauca/practice/junit_git/src/sorting/SortingPractice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.unicauca.practice.junit_git.src.sorting; | ||
|
||
import com.unicauca.practice.junit_git.src.sorting.util.BubbleSort; | ||
import com.unicauca.practice.junit_git.src.sorting.util.InsertionSort; | ||
import com.unicauca.practice.junit_git.src.sorting.util.QuickSort; | ||
import com.unicauca.practice.junit_git.src.sorting.util.SelectionSort; | ||
import com.unicauca.practice.junit_git.src.sorting.util.SortingUtil; | ||
|
||
/** | ||
* | ||
* @author sahydo | ||
*/ | ||
public class SortingPractice { | ||
|
||
private int[] array; | ||
private String sortingType = SortingUtil.BUBBLE_SORT; | ||
|
||
public SortingPractice(int[] array, String sortingType) { | ||
this.array = array; | ||
this.sortingType = sortingType; | ||
} | ||
|
||
public SortingPractice(int[] array) { | ||
this.array = array; | ||
} | ||
|
||
public int[] getArray() { | ||
return array; | ||
} | ||
|
||
public void setArray(int[] array) { | ||
this.array = array; | ||
} | ||
|
||
public String getSortingType() { | ||
return sortingType; | ||
} | ||
|
||
public void setSortingType(String sortingType) { | ||
this.sortingType = sortingType; | ||
} | ||
|
||
public void sort() { | ||
SortingUtil sortingMethod; | ||
switch (this.getSortingType()) { | ||
case SortingUtil.BUBBLE_SORT: | ||
sortingMethod = new BubbleSort(this.getSortingType()); | ||
// parameter by reference | ||
sortingMethod.sort(this.getArray()); | ||
break; | ||
case SortingUtil.INSERTION_SORT: | ||
// sortingMethod = new InsertionSort(this.getSortingType()); | ||
// sortingMethod.sort(this.getArray()); | ||
System.err.println("Insertion sorting pending"); | ||
break; | ||
case SortingUtil.QUICK_SORT: | ||
// sortingMethod = new QuickSort(this.getSortingType()); | ||
// sortingMethod.sort(this.getArray()); | ||
System.err.println("Quick sorting pending"); | ||
break; | ||
case SortingUtil.SELECTION_SORT: | ||
// sortingMethod = new SelectionSort(this.getSortingType()); | ||
// sortingMethod.sort(this.getArray()); | ||
System.err.println("Selection sorting pending"); | ||
break; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
maven/j_unit/src/main/java/com/unicauca/practice/junit_git/src/sorting/util/BubbleSort.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.unicauca.practice.junit_git.src.sorting.util; | ||
|
||
/** | ||
* | ||
* @author sahydo | ||
*/ | ||
public class BubbleSort extends SortingUtil { | ||
|
||
public BubbleSort(String type) { | ||
super(type); | ||
System.out.println("Ordering with " + this.getClass().getSimpleName()); | ||
} | ||
|
||
@Override | ||
public int[] sort(int[] array) { | ||
int lastIndex = array.length - 1; | ||
for (int j = 0; j < lastIndex; j++) { | ||
for (int i = 0; i < lastIndex - j; i++) { | ||
if (array[i] > array[i + 1]) { | ||
int tmp = array[i]; | ||
array[i] = array[i + 1]; | ||
array[i + 1] = tmp; | ||
} | ||
} | ||
} | ||
return array; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
maven/j_unit/src/main/java/com/unicauca/practice/junit_git/src/sorting/util/SortingUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.unicauca.practice.junit_git.src.sorting.util; | ||
|
||
/** | ||
* | ||
* @author sahydo | ||
*/ | ||
public abstract class SortingUtil { | ||
public static final String BUBBLE_SORT = "bubble"; | ||
public static final String INSERTION_SORT = "insertion"; | ||
public static final String QUICK_SORT = "quick"; | ||
public static final String SELECTION_SORT = "selection"; | ||
|
||
protected String type; | ||
|
||
public SortingUtil(String type) { | ||
this.type = type; | ||
} | ||
|
||
protected String getType() { | ||
return type; | ||
} | ||
|
||
protected void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public abstract int[] sort(int[] array); | ||
} |
59 changes: 59 additions & 0 deletions
59
...j_unit/src/test/java/com/unicauca/practice/junit_git/src/sorting/SortingPracticeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.unicauca.practice.junit_git.src.sorting; | ||
|
||
import com.unicauca.practice.junit_git.src.sorting.util.SortingUtil; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* | ||
* @author sahydo | ||
*/ | ||
public class SortingPracticeTest { | ||
|
||
private final int[] testArray = new int[]{4, 5, 2, 3, 1}; | ||
private final int[] orderedArray = new int[]{1, 2, 3, 4, 5}; | ||
|
||
public SortingPracticeTest() { | ||
} | ||
|
||
/** | ||
* Test of sort method, of class SortingPractice. | ||
*/ | ||
@Test | ||
@DisplayName("Bubble sorting test") | ||
public void testBubbleSort() { | ||
SortingPractice sortingPractice = new SortingPractice(testArray.clone(), SortingUtil.BUBBLE_SORT); | ||
sortingPractice.sort(); | ||
assertArrayEquals(orderedArray, sortingPractice.getArray()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Insertion sorting test") | ||
public void testInsertionSort() { | ||
SortingPractice sortingPractice = new SortingPractice(testArray.clone(), SortingUtil.INSERTION_SORT); | ||
sortingPractice.sort(); | ||
assertArrayEquals(orderedArray, sortingPractice.getArray()); | ||
fail("The test has failed"); | ||
} | ||
|
||
@Test | ||
@DisplayName("Selection sorting test") | ||
public void testSelectionSort() { | ||
SortingPractice sortingPractice = new SortingPractice(testArray.clone(), SortingUtil.SELECTION_SORT); | ||
sortingPractice.sort(); | ||
assertArrayEquals(orderedArray, sortingPractice.getArray()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Quick sorting test") | ||
public void testQuickSort() { | ||
// Not implemented yet | ||
} | ||
|
||
} |