Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit by DucNASe00292x #194

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-13"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/bin/
.idea
/build/
12 changes: 12 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
10 changes: 10 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=13
org.eclipse.jdt.core.compiler.compliance=13
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=13
4 changes: 4 additions & 0 deletions .settings/org.eclipse.wst.common.project.facet.core.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="13"/>
</faceted-project>
23 changes: 23 additions & 0 deletions src/main/java/unitTest/ContainsDuplicate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package unitTest;

import java.util.HashMap;

//Given an array of integers, find if the array contains any duplicates.
//Your function should return
//true if any value appears at least twice in the array,
//and it should return false if every element is distinct.

class ContainsDuplicate {
public boolean containsDuplicate(int[] nums) {
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i: nums) {
if(map.containsKey(i)) {
return true;
} else {
map.put(i, 1);
}
}

return false;
}
}
35 changes: 35 additions & 0 deletions src/main/java/unitTest/ContainsDuplicateUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package unitTest;

import static org.junit.Assert.*;

import org.junit.Test;

public class ContainsDuplicateUnitTest {

ContainsDuplicate cd = new ContainsDuplicate();
//Test case where the same elements in the array are contiguous
@Test
public void testNextDuplicate() {
int[] nums = {2,2,4,4};

assertTrue(cd.containsDuplicate(nums));
}

//Test case where the positions of the same elements
//in the array are not contiguous
@Test
public void testDuplicate() {
int[] nums = {2,4,2,5,8,9};

assertTrue(cd.containsDuplicate(nums));
}

//Test case all elements in the array are not the same
@Test
public void testNotDuplicate() {
int[] nums = {3,4,7,8,9};

assertFalse(cd.containsDuplicate(nums));
}

}
61 changes: 61 additions & 0 deletions src/main/java/unitTest/ReverseVowelsOfAString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package unitTest;



//Write a function that takes a string as input and reverse only the vowels of a string.

//Example 1:
//Given s = "hello", return "holle".

//Example 2:
//Given s = "leetcode", return "leotcede".

//Note:
//The vowels does not include the letter "y".

/**
* This is the class containing the function in the
* project used to apply the UnitTest technique.
* It's in the company's google directory
* @author DucNA-SE00292x
*
*/
public class ReverseVowelsOfAString {
/**
* Below is the vowel inversion function.
* @param s - This is a String input to method.
* @return s - This is return.
*/
public String reverseVowels(String s) {
if (s == null || s.length() == 0) {
return s;
}

String vowels = "aeiouAEIOU";

char[] chars = s.toCharArray();

int start = 0;
int end = s.length() - 1;

while (start < end) {
while (start < end && !vowels.
contains(chars[start] + "")) {
start++;
}

while (start < end && !vowels.
contains(chars[end] + "")) {
end--;
}

char temp = chars[start];
chars[start] = chars[end];
chars[end] = temp;

start++;
end--;
}
return new String(chars);
}
}
47 changes: 47 additions & 0 deletions src/main/java/unitTest/ReverseVowelsOfAStringUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package unitTest;

import static org.junit.Assert.*;

import org.junit.Test;

public class ReverseVowelsOfAStringUnitTest {

ReverseVowelsOfAString rs = new ReverseVowelsOfAString();

//True test case of the inverse function-1
@Test
public void testTrueReverseVowels1() {
String startString = "learn funix";

String actualRs = rs.reverseVowels(startString);
assertEquals(actualRs, rs.reverseVowels(startString));
}

//False test case of the inverse function-1
@Test
public void testNotEqualsReverseVowels1() {
String startString = "learn FU";
String expectResults = "fu learn";

assertNotEquals(expectResults, rs.reverseVowels(startString));
}

//true test case of the inverse function-2
@Test
public void testTrueReverseVowels2() {
String startString = "lUarn Fe";
String expectResults = "learn FU";

assertEquals(expectResults, rs.reverseVowels(startString));
}

//False test case of the inverse function-2
@Test
public void testNotEqualsReverseWords2() {
String starString = "learn funix";
String expectResults = "learn funix";

assertNotEquals(expectResults, rs.reverseVowels(starString));
}

}