diff --git a/.classpath b/.classpath new file mode 100644 index 00000000..2712ade5 --- /dev/null +++ b/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.gitignore b/.gitignore index 972f6a3d..dcc60f41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /bin/ .idea +/build/ diff --git a/.project b/.project index 76b39aeb..304af316 100644 --- a/.project +++ b/.project @@ -5,7 +5,19 @@ + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..8b9e3c71 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 00000000..d37b85ff --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/src/main/java/unitTest/ContainsDuplicate.java b/src/main/java/unitTest/ContainsDuplicate.java new file mode 100644 index 00000000..ce6be11c --- /dev/null +++ b/src/main/java/unitTest/ContainsDuplicate.java @@ -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 map = new HashMap(); + for(int i: nums) { + if(map.containsKey(i)) { + return true; + } else { + map.put(i, 1); + } + } + + return false; + } +} diff --git a/src/main/java/unitTest/ContainsDuplicateUnitTest.java b/src/main/java/unitTest/ContainsDuplicateUnitTest.java new file mode 100644 index 00000000..85c62fb4 --- /dev/null +++ b/src/main/java/unitTest/ContainsDuplicateUnitTest.java @@ -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)); + } + +} \ No newline at end of file diff --git a/src/main/java/unitTest/ReverseVowelsOfAString.java b/src/main/java/unitTest/ReverseVowelsOfAString.java new file mode 100644 index 00000000..53cf6241 --- /dev/null +++ b/src/main/java/unitTest/ReverseVowelsOfAString.java @@ -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); + } +} \ No newline at end of file diff --git a/src/main/java/unitTest/ReverseVowelsOfAStringUnitTest.java b/src/main/java/unitTest/ReverseVowelsOfAStringUnitTest.java new file mode 100644 index 00000000..087df496 --- /dev/null +++ b/src/main/java/unitTest/ReverseVowelsOfAStringUnitTest.java @@ -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)); + } + +}