forked from Hithomelabs/Princeton1
Compare commits
No commits in common. "b8da0cb3b14e145ee3ea5718005e30863afd069a" and "c425ddb53e470a43024a7110cbbf05596911933b" have entirely different histories.
b8da0cb3b1
...
c425ddb53e
2
.idea/gradle.xml
generated
2
.idea/gradle.xml
generated
@ -9,10 +9,8 @@
|
|||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
<option value="$PROJECT_DIR$/clients" />
|
<option value="$PROJECT_DIR$/clients" />
|
||||||
<option value="$PROJECT_DIR$/common" />
|
|
||||||
<option value="$PROJECT_DIR$/module4" />
|
<option value="$PROJECT_DIR$/module4" />
|
||||||
<option value="$PROJECT_DIR$/module5" />
|
<option value="$PROJECT_DIR$/module5" />
|
||||||
<option value="$PROJECT_DIR$/module6" />
|
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
|
@ -14,9 +14,6 @@ dependencies {
|
|||||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||||
implementation project(':module4')
|
implementation project(':module4')
|
||||||
implementation project(':module5')
|
implementation project(':module5')
|
||||||
implementation project(':module6')
|
|
||||||
implementation project(':common')
|
|
||||||
testImplementation project(':common')
|
|
||||||
}
|
}
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.hithomelabs.clients.module5;
|
package com.hithomelabs.clients.module5;
|
||||||
|
|
||||||
import com.hithomelabs.princeton1.module5.Insertion;
|
import com.hithomelabs.princeton1.module5.Insertion;
|
||||||
import com.hithomelabs.princeton1.common.Apple;
|
import com.hithomelabs.princeton1.module5.Apple;
|
||||||
import com.hithomelabs.princeton1.common.Orange;
|
import com.hithomelabs.princeton1.module5.Orange;
|
||||||
|
|
||||||
public class InsertionClient {
|
public class InsertionClient {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.hithomelabs.clients.module5;
|
package com.hithomelabs.clients.module5;
|
||||||
|
|
||||||
import com.hithomelabs.princeton1.common.Apple;
|
import com.hithomelabs.princeton1.module5.Apple;
|
||||||
import com.hithomelabs.princeton1.module5.Shell;
|
import com.hithomelabs.princeton1.module5.Shell;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package com.hithomelabs.clients.module6;
|
|
||||||
|
|
||||||
import com.hithomelabs.princeton1.common.Apple;
|
|
||||||
import com.hithomelabs.princeton1.module6.Merge;
|
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class MergeClient {
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
int size = 100;
|
|
||||||
Apple[] apples = new Apple[size];
|
|
||||||
Merge<Apple> merge = new Merge<Apple>();
|
|
||||||
|
|
||||||
for (int i = 0; i < apples.length; i++) {
|
|
||||||
apples[i] = new Apple(new Random().nextInt(1000));
|
|
||||||
}
|
|
||||||
merge.sort(apples);
|
|
||||||
for (int i = 0; i < apples.length; i++)
|
|
||||||
System.out.println(apples[i]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
group = 'com.hithomelabs.princeton1.common'
|
|
||||||
version = 'unspecified'
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
|
||||||
toolchain {
|
|
||||||
languageVersion = JavaLanguageVersion.of(11)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
@ -12,7 +12,6 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||||
testImplementation project(':common')
|
|
||||||
}
|
}
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.hithomelabs.princeton1.common;
|
package com.hithomelabs.princeton1.module5;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.hithomelabs.princeton1.common;
|
package com.hithomelabs.princeton1.module5;
|
||||||
|
|
||||||
public class Orange {
|
public class Orange {
|
||||||
private int size;
|
private int size;
|
@ -49,7 +49,7 @@ public class Shell<E> extends AbstractCustomSorts<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Sample implementation of insertion sort as h-sort of h = 1
|
! sample implementation of insertion sort as h-sort of h = 1
|
||||||
* Will just be comparing the number of saps taken across both implementations
|
* Will just be comparing the number of saps taken across both implementations
|
||||||
*/
|
*/
|
||||||
public void insertionSort(E[] arr){
|
public void insertionSort(E[] arr){
|
||||||
|
@ -4,10 +4,12 @@ import org.junit.jupiter.api.AfterEach;
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import com.hithomelabs.princeton1.common.Apple;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class SortTest {
|
class SortTest {
|
||||||
|
|
||||||
private ArrayList<Apple> apples;
|
private ArrayList<Apple> apples;
|
||||||
@ -24,7 +26,11 @@ class SortTest {
|
|||||||
private void testSort(AbstractCustomSorts<Apple> sortingAlgorithm) {
|
private void testSort(AbstractCustomSorts<Apple> sortingAlgorithm) {
|
||||||
for (int i = 0; i < 100; i++)
|
for (int i = 0; i < 100; i++)
|
||||||
apples.add(new Apple(random.nextInt(100)));
|
apples.add(new Apple(random.nextInt(100)));
|
||||||
|
Apple[] arr = apples.toArray(new Apple[apples.size()]);
|
||||||
|
apples.sort(null);
|
||||||
|
Apple[] sorted = apples.toArray(new Apple[apples.size()]);
|
||||||
|
sortingAlgorithm.sort(arr);
|
||||||
|
assertArrayEquals(sorted, arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -48,6 +54,7 @@ class SortTest {
|
|||||||
testSort(sortingAlgorithm);
|
testSort(sortingAlgorithm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
void tearDown() {
|
void tearDown() {
|
||||||
sortingAlgorithm = null;
|
sortingAlgorithm = null;
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
group = 'com.hithomelabs.princeton1.module6'
|
|
||||||
version = 'unspecified'
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
|
||||||
implementation project(':module5')
|
|
||||||
testImplementation project(':common')
|
|
||||||
}
|
|
||||||
java {
|
|
||||||
toolchain {
|
|
||||||
languageVersion = JavaLanguageVersion.of(11)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package com.hithomelabs.princeton1.module6;
|
|
||||||
|
|
||||||
import com.hithomelabs.princeton1.module5.AbstractCustomSorts;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class Merge<E> extends AbstractCustomSorts<E> {
|
|
||||||
@Override
|
|
||||||
public void sort(E[] arr) {
|
|
||||||
merge_sort(arr, 0, arr.length-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void merge_sort(E[] arr, int low_index, int high_index){
|
|
||||||
if(high_index - low_index > 0) {
|
|
||||||
int mid_index = low_index + (high_index - low_index)/2;
|
|
||||||
merge_sort(arr, low_index, mid_index);
|
|
||||||
merge_sort(arr, mid_index + 1, high_index);
|
|
||||||
|
|
||||||
// Copy array
|
|
||||||
E[] auxArr = (E[]) new Object[high_index - low_index + 1];
|
|
||||||
int index = 0;
|
|
||||||
for(int i=low_index; i<= high_index; i++)
|
|
||||||
auxArr[index++] = arr[i];
|
|
||||||
|
|
||||||
// Sort
|
|
||||||
int low_index_ptr = 0;
|
|
||||||
int mid_index_ptr = (auxArr.length - 1)/2;
|
|
||||||
int high_index_ptr = mid_index_ptr + 1;
|
|
||||||
if(!less((Comparable<E>) auxArr[mid_index_ptr], auxArr[high_index_ptr])) {
|
|
||||||
for (int i = low_index; i <= high_index; i++) {
|
|
||||||
if (low_index_ptr > mid_index_ptr) {
|
|
||||||
arr[i] = auxArr[high_index_ptr];
|
|
||||||
high_index_ptr++;
|
|
||||||
} else if (high_index_ptr >= auxArr.length)
|
|
||||||
arr[i] = auxArr[low_index_ptr++];
|
|
||||||
else if (less((Comparable<E>) auxArr[low_index_ptr], auxArr[high_index_ptr]))
|
|
||||||
arr[i] = auxArr[low_index_ptr++];
|
|
||||||
else
|
|
||||||
arr[i] = auxArr[high_index_ptr++];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
|||||||
package com.hithomelabs.princeton1.module6;
|
|
||||||
|
|
||||||
import com.hithomelabs.princeton1.module5.AbstractCustomSorts;
|
|
||||||
import com.hithomelabs.princeton1.common.Apple;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class MergeTest {
|
|
||||||
|
|
||||||
private AbstractCustomSorts<Apple> sortingAlgorithm;
|
|
||||||
private ArrayList<Apple> apples;
|
|
||||||
private Random random;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
apples = new ArrayList<>();
|
|
||||||
random = new Random();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("Merge Sort test client")
|
|
||||||
public void testSort(){
|
|
||||||
sortingAlgorithm = new Merge<Apple>();
|
|
||||||
for(int i = 0; i < 10; i++)
|
|
||||||
apples.add(new Apple(random.nextInt(100)));
|
|
||||||
Apple[] arr = apples.toArray(new Apple[apples.size()]);
|
|
||||||
apples.sort(null);
|
|
||||||
Apple[] sorted = apples.toArray(new Apple[apples.size()]);
|
|
||||||
sortingAlgorithm.sort(arr);
|
|
||||||
assertArrayEquals(sorted, arr);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
void tearDown() {
|
|
||||||
sortingAlgorithm = null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,9 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = 'Pricenton1'
|
rootProject.name = 'Pricenton1'
|
||||||
include 'module4'
|
include('module4')
|
||||||
include 'clients'
|
include 'clients'
|
||||||
include 'module5'
|
include 'module5'
|
||||||
include 'module6'
|
|
||||||
include 'common'
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user