Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public DuplicateDeleter(T[] intArray) {
}

abstract public T[] removeDuplicates(int maxNumberOfDuplications);

abstract public T[] removeDuplicatesExactly(int exactNumberOfDuplications);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

/**
* Created by leon on 1/28/18.
*
* @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
*/
public interface DuplicateDeleterInterface<T> {
T[] removeDuplicates(int maxNumberOfDuplications);

T[] removeDuplicatesExactly(int exactNumberOfDuplications);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,77 @@
package com.zipcodewilmington.looplabs;

import java.util.Arrays;

/**
* Created by leon on 1/29/18.
*
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
*/
public final class IntegerDuplicateDeleter extends DuplicateDeleter<Integer> {


public IntegerDuplicateDeleter(Integer[] intArray) {
super(intArray);
}


@Override
public Integer[] removeDuplicatesExactly(int exactNumberOfDuplications) {

Integer[] finalArray = new Integer[0];

for (int i = 0; i < this.array.length; i++) {

if (getNumberOfOccurrences(this.array, this.array[i]) != exactNumberOfDuplications) {

int actualElements = finalArray.length;
finalArray = Arrays.copyOf(finalArray, finalArray.length + 1);
finalArray[actualElements] = this.array[i];

}

}

return finalArray;
}

public static int getNumberOfOccurrences(Integer[] inputArray, Integer value) {

int valueCounter = 0;

for (int arrayElement : inputArray) {

if (arrayElement == value) {

valueCounter++;
}

}

return valueCounter;
}


@Override
public Integer[] removeDuplicates(int maxNumberOfDuplications) {
Integer[] actualArray = new Integer[0];

for (int i = 0; i < this.array.length; i++) {

if (getNumberOfOccurrences(this.array, this.array[i]) < maxNumberOfDuplications) {

int arrayElements = actualArray.length;
actualArray = Arrays.copyOf(actualArray, actualArray.length + 1);
actualArray[arrayElements] = this.array[i];

}

}

return actualArray;

}

}


Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public final class RandomNumberFactory {

private RandomNumberFactory() {
}

/**
* @param min
* @param max
Expand Down Expand Up @@ -45,7 +46,7 @@ public static Integer createInteger(Integer min, Integer max) {
*/
public static Integer[] createIntegers(int min, int max, int length) {
Integer[] integers = new Integer[length];
for(int i=0; i<length; i++) {
for (int i = 0; i < length; i++) {
integers[i] = createInteger(min, max);
}
return integers;
Expand All @@ -72,7 +73,7 @@ public static String createString(char min, char max, int length) {
*/
public static String[] createStrings(char min, char max, int stringLength, int arrayLength) {
String[] array = new String[arrayLength];
for(int i=0; i<arrayLength; i++) {
for (int i = 0; i < arrayLength; i++) {
array[i] = createString(min, max, stringLength);
}
return array;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,72 @@
package com.zipcodewilmington.looplabs;

import java.util.Arrays;

/**
* Created by leon on 1/28/18.
*
* @ATTENTION_TO_STUDENTS You are forbidden from modifying the signature of this class.
*/
public final class StringDuplicateDeleter extends DuplicateDeleter<String> {

public StringDuplicateDeleter(String[] intArray) {
super(intArray);
}


@Override
public String[] removeDuplicatesExactly(int exactNumberOfDuplications) {

String[] noStringDupsArray = new String[0];

for (int i = 0; i < this.array.length; i++) {

if (getNumberOfOccurrences(this.array, this.array[i]) != exactNumberOfDuplications) {

int stringElements = noStringDupsArray.length;
noStringDupsArray = Arrays.copyOf(noStringDupsArray, noStringDupsArray.length + 1);
noStringDupsArray[stringElements] = this.array[i];

}

}

return noStringDupsArray;
}

public static int getNumberOfOccurrences(String[] inputArray, String value) {

int valueCounter = 0;

for (String arrayElement : inputArray) {

if (arrayElement.equalsIgnoreCase(value)) {

valueCounter++;
}

}

return valueCounter;
}


@Override
public String[] removeDuplicates(int maxNumberOfDuplications) {
String[] maxDupsArray = new String[0];

for (int i = 0; i < this.array.length; i++) {

if (getNumberOfOccurrences(this.array, this.array[i]) < maxNumberOfDuplications) {

int arrayElements = maxDupsArray.length;
maxDupsArray = Arrays.copyOf(maxDupsArray, maxDupsArray.length + 1);
maxDupsArray[arrayElements] = this.array[i];

}

}

return maxDupsArray;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* Created by leon on 1/25/18.
*
* @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
*/
public class IntegerDuplicateDeleterTest {
Expand Down Expand Up @@ -37,7 +38,6 @@ public void testRemoveDuplicatesExactly1() {
}



@Test
public void testRemoveDuplicatesExactly2() {
Integer[] expected = new Integer[]{0, 0, 0, 2, 2, 4, 4, 5, 5, 5, 9, 9, 9};
Expand All @@ -58,31 +58,6 @@ public void testRemoveDuplicatesExactly3() {
}



























@Test
public void testRemoveDuplicates0() {
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
Expand Down Expand Up @@ -117,7 +92,7 @@ public void testRemoveDuplicates2() {
public void testRemoveDuplicates3() {
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
Integer[] expected = new Integer[]{1,1,2,4,4};
Integer[] expected = new Integer[]{1, 1, 2, 4, 4};
Integer[] actual = deleter.removeDuplicates(3);
TestUtils.assertArrayEquality(expected, actual);
}
Expand All @@ -127,28 +102,15 @@ public void testRemoveDuplicates3() {
public void testRemoveDuplicates4() {
Integer[] array = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5};
DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(array);
Integer[] expected = new Integer[]{0,0,0,1,1,2,3,3,3,4,4};
Integer[] expected = new Integer[]{0, 0, 0, 1, 1, 2, 3, 3, 3, 4, 4};
Integer[] actual = deleter.removeDuplicates(4);
TestUtils.assertArrayEquality(expected, actual);
}















@Test
public void testRemoveDuplicatesExactlyIdempotence() {
Integer[] input = RandomNumberFactory.createIntegers(0,50,150);
Integer[] input = RandomNumberFactory.createIntegers(0, 50, 150);
DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(input);
Integer[] expected = deleter.removeDuplicatesExactly(5);

Expand All @@ -166,7 +128,7 @@ public void testRemoveDuplicatesExactlyIdempotence() {

@Test
public void testRemoveDuplicatesIdempotence() {
Integer[] input = RandomNumberFactory.createIntegers(0,50,150);
Integer[] input = RandomNumberFactory.createIntegers(0, 50, 150);
DuplicateDeleter<Integer> deleter = new IntegerDuplicateDeleter(input);
Integer[] expected = deleter.removeDuplicates(5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* Created by leon on 1/28/18.
*
* @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
*/
public class StringDuplicateDeleterTest {
Expand Down Expand Up @@ -63,18 +64,6 @@ public void testRemoveDuplicatesExactly5() {
}














@Test
public void testRemoveDuplicates0() {
String[] input = new String[]{"aa", "aa", "aa", "aa", "aa", "ab", "ba", "ba", "ba", "ba", "bb", "bb", "bb", "bb", "bb"};
Expand All @@ -85,7 +74,6 @@ public void testRemoveDuplicates0() {
}



@Test
public void testRemoveDuplicates1() {
String[] input = new String[]{"aa", "aa", "aa", "aa", "aa", "ab", "ba", "ba", "ba", "ba", "bb", "bb", "bb", "bb", "bb"};
Expand Down Expand Up @@ -115,24 +103,6 @@ public void testRemoveDuplicates3() {
}




















@Test
public void testRemoveDuplicatesExactlyIdempotence() {
String[] input = RandomNumberFactory.createStrings('a', 'c', 2, 15);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/**
* Created by leon on 1/28/18.
*
* @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
*/
@RunWith(Suite.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* Created by leon on 1/28/18.
*
* @ATTENTION_TO_STUDENTS You are forbidden from modifying this class.
*/
public class TestUtils {
Expand Down