From f1dcbece2cb118d206e4b157665b79bb4567a49c Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Sat, 28 Oct 2023 01:15:55 -0400 Subject: [PATCH] CODEBANK-4 EmptyQuickTest error fix --- .../codebank/tests/EmptyQuickTest.java | 78 ++----------------- 1 file changed, 8 insertions(+), 70 deletions(-) diff --git a/toolkits/codebank/src/test/java/com/ossez/toolkits/codebank/tests/EmptyQuickTest.java b/toolkits/codebank/src/test/java/com/ossez/toolkits/codebank/tests/EmptyQuickTest.java index 20faca97c4..35d09fd9fb 100644 --- a/toolkits/codebank/src/test/java/com/ossez/toolkits/codebank/tests/EmptyQuickTest.java +++ b/toolkits/codebank/src/test/java/com/ossez/toolkits/codebank/tests/EmptyQuickTest.java @@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,80 +38,17 @@ public class EmptyQuickTest { @Test public void testMain() { - Integer[] nums = {2, 7, 11, 15}; + List testList = new ArrayList<>(); - Integer target = 9; - String s1 = "Question, what kind of bear is best?"; - String s2 = "That's a ridiculous question!"; - String s3 = "False."; - String s4 = "Black bear is the best bear."; + testList.add(String.valueOf(1L)); + testList.add("iSharkFly"); + testList.add(String.valueOf(2)); + testList.forEach(e -> log.debug("{}", e)); - List inputStr = new ArrayList<>(); - inputStr.add(RegExUtils.replaceAll(s1, "[^a-zA-Z\\s]", "").toLowerCase()); - inputStr.add(RegExUtils.replaceAll(s2, "[^a-zA-Z\\s]", "").toLowerCase()); - inputStr.add(RegExUtils.replaceAll(s3, "[^a-zA-Z\\s]", "").toLowerCase()); - inputStr.add(RegExUtils.replaceAll(s4, "[^a-zA-Z\\s]", "").toLowerCase()); - HashMap> wordsMap = new HashMap<>(); - - for (int i = 0; i < inputStr.size(); i++) { - String words = inputStr.get(i); - List wordsList = List.of(StringUtils.split(inputStr.get(i))); - for (int j = 0; j < wordsList.size(); j++) { - String word = wordsList.get(j); - List inStr = new ArrayList<>(); - if (wordsMap.get(word) != null) { - inStr = wordsMap.get(word); - } - inStr.add("" + (i + 1)); - wordsMap.put(word, inStr); - - } - } - - TreeMap> countMap = new TreeMap<>(Collections.reverseOrder()); - for (Map.Entry> stringListEntry : wordsMap.entrySet()) { - Integer wordCount = stringListEntry.getValue().size(); - List wordsList = new ArrayList<>(); - if (countMap.get(wordCount) != null) { - wordsList = countMap.get(wordCount); - - } - wordsList.add(stringListEntry.getKey()); - countMap.put(wordCount, wordsList); - } - - for (Map.Entry> integerListEntry : countMap.entrySet()) { - List outputList = integerListEntry.getValue(); - for (int i = 0; i < outputList.size(); i++) { - List sList = wordsMap.get(outputList.get(i)); - log.debug("{}[{}:{}]", outputList.get(i), integerListEntry.getKey(), sList.stream().distinct().collect(Collectors.toList())); - } - - } - - } - - private Boolean hasVowels(String str) { - - str = StringUtils.trimToEmpty(str); - str = StringUtils.lowerCase(str); - str = StringUtils.remove(str, " "); - - if (StringUtils.contains(str, VOWEL_A)) { - return Boolean.TRUE; - } else if (StringUtils.contains(str, VOWEL_E)) { - return Boolean.TRUE; - } else if (StringUtils.contains(str, VOWEL_I)) { - return Boolean.TRUE; - } else if (StringUtils.contains(str, VOWEL_O)) { - return Boolean.TRUE; - } else if (StringUtils.contains(str, VOWEL_U)) { - return Boolean.TRUE; - } - - return Boolean.FALSE; + String index0 = (String) testList.get(0); + String index1 = (String) testList.get(1); } }