Merge remote-tracking branch 'upstream/practice' into kruti-working-branch
This commit is contained in:
commit
a409bce387
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@ -13,6 +13,7 @@
|
|||||||
<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" />
|
<option value="$PROJECT_DIR$/module6" />
|
||||||
|
<option value="$PROJECT_DIR$/module7" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
|
@ -15,6 +15,7 @@ dependencies {
|
|||||||
implementation project(':module4')
|
implementation project(':module4')
|
||||||
implementation project(':module5')
|
implementation project(':module5')
|
||||||
implementation project(':module6')
|
implementation project(':module6')
|
||||||
|
implementation project(':module7')
|
||||||
implementation project(':common')
|
implementation project(':common')
|
||||||
testImplementation project(':common')
|
testImplementation project(':common')
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.hithomelabs.clients.module7;
|
||||||
|
|
||||||
|
import com.hithomelabs.princeton1.common.Apple;
|
||||||
|
import com.hithomelabs.princeton1.module7.Quick;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class QuickSortClient {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int size = 100;
|
||||||
|
Apple[] apples = new Apple[size];
|
||||||
|
Quick<Apple> quick = new Quick<Apple>();
|
||||||
|
|
||||||
|
for (int i = 0; i < apples.length; i++) {
|
||||||
|
apples[i] = new Apple(new Random().nextInt(1000));
|
||||||
|
}
|
||||||
|
quick.sort(apples);
|
||||||
|
for (int i = 0; i < apples.length; i++)
|
||||||
|
System.out.println(apples[i]);
|
||||||
|
}
|
||||||
|
}
|
@ -6,9 +6,6 @@ public abstract class AbstractCustomSorts<E> {
|
|||||||
|
|
||||||
// TODO: Implement this method
|
// TODO: Implement this method
|
||||||
public void exch(E[] arr, int j, int i) {
|
public void exch(E[] arr, int j, int i) {
|
||||||
E temp = arr[i];
|
|
||||||
arr[i] = arr[j];
|
|
||||||
arr[j] = temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Implement this method
|
// TODO: Implement this method
|
||||||
|
21
module7/build.gradle
Normal file
21
module7/build.gradle
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.hithomelabs.princeton1.module7'
|
||||||
|
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')
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.hithomelabs.princeton1.module7;
|
||||||
|
|
||||||
|
import com.hithomelabs.princeton1.module5.AbstractCustomSorts;
|
||||||
|
|
||||||
|
|
||||||
|
public class Quick<E> extends AbstractCustomSorts<E> {
|
||||||
|
@Override
|
||||||
|
public void sort(E[] arr) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package com.hithomelabs.princeton1.module7;
|
||||||
|
|
||||||
|
import com.hithomelabs.princeton1.common.Apple;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class QuickTest {
|
||||||
|
|
||||||
|
private Quick<Apple> quick;
|
||||||
|
private ArrayList<Apple> apples;
|
||||||
|
private Random random;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
quick = new Quick<Apple>();
|
||||||
|
apples = new ArrayList<Apple>();
|
||||||
|
random = new Random();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("testing Quick sort default implementation")
|
||||||
|
public void testSort(){
|
||||||
|
|
||||||
|
for(int i = 0; i < 100; i++)
|
||||||
|
apples.add(new Apple(random.nextInt(1000)));
|
||||||
|
Apple[] arr = apples.toArray(new Apple[apples.size()]);
|
||||||
|
quick.sort(arr);
|
||||||
|
apples.sort(null);
|
||||||
|
Apple[] sorted = apples.toArray(new Apple[apples.size()]);
|
||||||
|
Assertions.assertArrayEquals(sorted, arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// * * Optional test for alternate sort implmentation
|
||||||
|
/*
|
||||||
|
@Test
|
||||||
|
@DisplayName("testing Quick sort default implementation")
|
||||||
|
public void testAltSort(){
|
||||||
|
|
||||||
|
for(int i = 0; i < 100; i++)
|
||||||
|
apples.add(new Apple(random.nextInt(1000)));
|
||||||
|
Apple[] arr = apples.toArray(new Apple[apples.size()]);
|
||||||
|
quick.altSort(arr);
|
||||||
|
apples.sort(null);
|
||||||
|
Apple[] sorted = apples.toArray(new Apple[apples.size()]);
|
||||||
|
Assertions.assertArrayEquals(sorted, arr);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
void tearDown() {
|
||||||
|
quick = null;
|
||||||
|
apples = null;
|
||||||
|
random = null;
|
||||||
|
}
|
||||||
|
}
|
@ -16,4 +16,5 @@ include 'clients'
|
|||||||
include 'module5'
|
include 'module5'
|
||||||
include 'module6'
|
include 'module6'
|
||||||
include 'common'
|
include 'common'
|
||||||
|
include 'module7'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user