public void testToString() { CharArraySet set = CharArraySet.copy(TEST_VERSION_CURRENT, Collections.singleton("test")); assertEquals("[test]", set.toString()); set.add("test2"); assertTrue(set.toString().contains(", ")); set = CharArraySet.copy(Version.LUCENE_3_0, Collections.singleton("test")); assertEquals("[test]", set.toString()); set.add("test2"); assertTrue(set.toString().contains(", ")); }
/** Test the static #copy() function with a JDK {@link Set} as a source */ public void testCopyJDKSet() { Set<String> set = new HashSet<>(); List<String> stopwords = Arrays.asList(TEST_STOP_WORDS); List<String> stopwordsUpper = new ArrayList<>(); for (String string : stopwords) { stopwordsUpper.add(string.toUpperCase(Locale.ROOT)); } set.addAll(Arrays.asList(TEST_STOP_WORDS)); CharArraySet copy = CharArraySet.copy(TEST_VERSION_CURRENT, set); assertEquals(set.size(), copy.size()); assertEquals(set.size(), copy.size()); assertTrue(copy.containsAll(stopwords)); for (String string : stopwordsUpper) { assertFalse(copy.contains(string)); } List<String> newWords = new ArrayList<>(); for (String string : stopwords) { newWords.add(string + "_1"); } copy.addAll(newWords); assertTrue(copy.containsAll(stopwords)); assertTrue(copy.containsAll(newWords)); // new added terms are not in the source set for (String string : newWords) { assertFalse(set.contains(string)); } }
@SuppressWarnings("deprecated") public void testCopyCharArraySetBWCompat() { CharArraySet setIngoreCase = new CharArraySet(TEST_VERSION_CURRENT, 10, true); CharArraySet setCaseSensitive = new CharArraySet(TEST_VERSION_CURRENT, 10, false); List<String> stopwords = Arrays.asList(TEST_STOP_WORDS); List<String> stopwordsUpper = new ArrayList<>(); for (String string : stopwords) { stopwordsUpper.add(string.toUpperCase(Locale.ROOT)); } setIngoreCase.addAll(Arrays.asList(TEST_STOP_WORDS)); setIngoreCase.add(Integer.valueOf(1)); setCaseSensitive.addAll(Arrays.asList(TEST_STOP_WORDS)); setCaseSensitive.add(Integer.valueOf(1)); CharArraySet copy = CharArraySet.copy(TEST_VERSION_CURRENT, setIngoreCase); CharArraySet copyCaseSens = CharArraySet.copy(TEST_VERSION_CURRENT, setCaseSensitive); assertEquals(setIngoreCase.size(), copy.size()); assertEquals(setCaseSensitive.size(), copy.size()); assertTrue(copy.containsAll(stopwords)); assertTrue(copy.containsAll(stopwordsUpper)); assertTrue(copyCaseSens.containsAll(stopwords)); for (String string : stopwordsUpper) { assertFalse(copyCaseSens.contains(string)); } // test adding terms to the copy List<String> newWords = new ArrayList<>(); for (String string : stopwords) { newWords.add(string + "_1"); } copy.addAll(newWords); assertTrue(copy.containsAll(stopwords)); assertTrue(copy.containsAll(stopwordsUpper)); assertTrue(copy.containsAll(newWords)); // new added terms are not in the source set for (String string : newWords) { assertFalse(setIngoreCase.contains(string)); assertFalse(setCaseSensitive.contains(string)); } }
/** * Tests a special case of {@link CharArraySet#copy(Version, Set)} where the set to copy is the * {@link CharArraySet#EMPTY_SET} */ public void testCopyEmptySet() { assertSame( CharArraySet.EMPTY_SET, CharArraySet.copy(TEST_VERSION_CURRENT, CharArraySet.EMPTY_SET)); }