You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "paulirwin (via GitHub)" <gi...@apache.org> on 2025/01/23 05:01:03 UTC
[PR] Add Support unit tests for CollectionExtensions, #1115 [lucenenet]
paulirwin opened a new pull request, #1122:
URL: https://github.com/apache/lucenenet/pull/1122
- [X] You've read the [Contributor Guide](https://github.com/apache/lucenenet/blob/main/CONTRIBUTING.md) and [Code of Conduct](https://www.apache.org/foundation/policies/conduct.html).
- [X] You've included unit or integration tests for your change, where applicable.
- [X] You've included inline docs for your change, where applicable.
- [X] There's an open issue for the PR that you are making. If you'd like to propose a change, please [open an issue](https://github.com/apache/lucenenet/issues/new/choose) to discuss the change or find an existing issue.
Add Support unit tests for CollectionExtensions, #1115
Fixes #1115
## Description
This adds some basic unit tests for CollectionExtensions, covering the set, list, and other-collection cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Support unit tests for CollectionExtensions, #1115 [lucenenet]
Posted by "paulirwin (via GitHub)" <gi...@apache.org>.
paulirwin merged PR #1122:
URL: https://github.com/apache/lucenenet/pull/1122
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Support unit tests for CollectionExtensions, #1115 [lucenenet]
Posted by "NightOwl888 (via GitHub)" <gi...@apache.org>.
NightOwl888 commented on code in PR #1122:
URL: https://github.com/apache/lucenenet/pull/1122#discussion_r1926466875
##########
src/Lucene.Net.Tests/Support/TestCollectionExtensions.cs:
##########
@@ -0,0 +1,160 @@
+using Lucene.Net.Attributes;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System.Collections;
+using System.Collections.Generic;
+using JCG = J2N.Collections.Generic;
+#nullable enable
+
+namespace Lucene.Net.Support
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /// <summary>
+ /// Tests for <see cref="CollectionExtensions"/>
+ /// </summary>
+ [TestFixture]
+ [LuceneNetSpecific]
+ public class TestCollectionExtensions : LuceneTestCase
+ {
+ [Test]
+ public void RetainAll_EmptySource()
+ {
+ ISet<int> set = new JCG.HashSet<int>(); // empty
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsFalse(result);
+ Assert.AreEqual(0, set.Count);
+ }
+
+ [Test]
+ public void RetainAll_Set()
+ {
+ ISet<int> set = new JCG.HashSet<int> { 1, 2, 3, 4, 5 };
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
Review Comment:
We should probably test some values that are not in the `set`, also.
```c#
bool result = set.RetainAll(new[] { 1, 2, 3, 100, 101 });
```
##########
src/Lucene.Net.Tests/Support/TestCollectionExtensions.cs:
##########
@@ -0,0 +1,160 @@
+using Lucene.Net.Attributes;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System.Collections;
+using System.Collections.Generic;
+using JCG = J2N.Collections.Generic;
+#nullable enable
+
+namespace Lucene.Net.Support
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /// <summary>
+ /// Tests for <see cref="CollectionExtensions"/>
+ /// </summary>
+ [TestFixture]
+ [LuceneNetSpecific]
+ public class TestCollectionExtensions : LuceneTestCase
+ {
+ [Test]
+ public void RetainAll_EmptySource()
+ {
+ ISet<int> set = new JCG.HashSet<int>(); // empty
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsFalse(result);
+ Assert.AreEqual(0, set.Count);
+ }
+
+ [Test]
+ public void RetainAll_Set()
+ {
+ ISet<int> set = new JCG.HashSet<int> { 1, 2, 3, 4, 5 };
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, set.Count);
+ Assert.IsTrue(set.Contains(1));
+ Assert.IsTrue(set.Contains(2));
+ Assert.IsTrue(set.Contains(3));
+ Assert.IsFalse(set.Contains(4));
+ Assert.IsFalse(set.Contains(5));
+ }
+
+ [Test]
+ public void RetainAll_List()
+ {
+ IList<int> list = new JCG.List<int> { 1, 2, 3, 4, 5 };
+ bool result = list.RetainAll(new[] { 1, 2, 3 });
Review Comment:
We should probably test some values that are not in the `list`, also.
```c#
bool result = list.RetainAll(new[] { 1, 2, 3, 100, 101 });
```
##########
src/Lucene.Net.Tests/Support/TestCollectionExtensions.cs:
##########
@@ -0,0 +1,160 @@
+using Lucene.Net.Attributes;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System.Collections;
+using System.Collections.Generic;
+using JCG = J2N.Collections.Generic;
+#nullable enable
+
+namespace Lucene.Net.Support
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /// <summary>
+ /// Tests for <see cref="CollectionExtensions"/>
+ /// </summary>
+ [TestFixture]
+ [LuceneNetSpecific]
+ public class TestCollectionExtensions : LuceneTestCase
+ {
+ [Test]
+ public void RetainAll_EmptySource()
+ {
+ ISet<int> set = new JCG.HashSet<int>(); // empty
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsFalse(result);
+ Assert.AreEqual(0, set.Count);
+ }
+
+ [Test]
+ public void RetainAll_Set()
+ {
+ ISet<int> set = new JCG.HashSet<int> { 1, 2, 3, 4, 5 };
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, set.Count);
+ Assert.IsTrue(set.Contains(1));
+ Assert.IsTrue(set.Contains(2));
+ Assert.IsTrue(set.Contains(3));
+ Assert.IsFalse(set.Contains(4));
+ Assert.IsFalse(set.Contains(5));
+ }
+
+ [Test]
+ public void RetainAll_List()
+ {
+ IList<int> list = new JCG.List<int> { 1, 2, 3, 4, 5 };
+ bool result = list.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, list.Count);
+ Assert.AreEqual(1, list[0]);
+ Assert.AreEqual(2, list[1]);
+ Assert.AreEqual(3, list[2]);
+ }
+
+ [Test]
+ public void RetainAll_Collection()
+ {
+ ICollection<int> collection = new TestCollection<int> { 1, 2, 3, 4, 5 };
+ bool result = collection.RetainAll(new[] { 1, 2, 3 });
Review Comment:
We should probably test some values that are not in the `collection`, also.
```c#
bool result = collection.RetainAll(new[] { 1, 2, 3, 100, 101 });
```
##########
src/Lucene.Net.Tests/Support/TestCollectionExtensions.cs:
##########
@@ -0,0 +1,160 @@
+using Lucene.Net.Attributes;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System.Collections;
+using System.Collections.Generic;
+using JCG = J2N.Collections.Generic;
+#nullable enable
+
+namespace Lucene.Net.Support
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /// <summary>
+ /// Tests for <see cref="CollectionExtensions"/>
+ /// </summary>
+ [TestFixture]
+ [LuceneNetSpecific]
+ public class TestCollectionExtensions : LuceneTestCase
+ {
+ [Test]
+ public void RetainAll_EmptySource()
+ {
+ ISet<int> set = new JCG.HashSet<int>(); // empty
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsFalse(result);
+ Assert.AreEqual(0, set.Count);
+ }
+
+ [Test]
+ public void RetainAll_Set()
+ {
+ ISet<int> set = new JCG.HashSet<int> { 1, 2, 3, 4, 5 };
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, set.Count);
+ Assert.IsTrue(set.Contains(1));
+ Assert.IsTrue(set.Contains(2));
+ Assert.IsTrue(set.Contains(3));
+ Assert.IsFalse(set.Contains(4));
+ Assert.IsFalse(set.Contains(5));
+ }
+
+ [Test]
+ public void RetainAll_List()
+ {
+ IList<int> list = new JCG.List<int> { 1, 2, 3, 4, 5 };
+ bool result = list.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, list.Count);
+ Assert.AreEqual(1, list[0]);
+ Assert.AreEqual(2, list[1]);
+ Assert.AreEqual(3, list[2]);
+ }
+
+ [Test]
+ public void RetainAll_Collection()
+ {
+ ICollection<int> collection = new TestCollection<int> { 1, 2, 3, 4, 5 };
+ bool result = collection.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, collection.Count);
+ Assert.IsTrue(collection.Contains(1));
+ Assert.IsTrue(collection.Contains(2));
+ Assert.IsTrue(collection.Contains(3));
+ Assert.IsFalse(collection.Contains(4));
+ Assert.IsFalse(collection.Contains(5));
+ }
+
+ [Test]
+ public void RemoveAll_EmptySource()
+ {
+ ISet<int> set = new JCG.HashSet<int>(); // empty
+ bool result = set.RemoveAll(new[] { 1, 2, 3 });
+ Assert.IsFalse(result);
+ Assert.AreEqual(0, set.Count);
+ }
+
+ [Test]
+ public void RemoveAll_Set()
+ {
+ ISet<int> set = new JCG.HashSet<int> { 1, 2, 3, 4, 5 };
+ bool result = set.RemoveAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(2, set.Count);
+ Assert.IsFalse(set.Contains(1));
+ Assert.IsFalse(set.Contains(2));
+ Assert.IsFalse(set.Contains(3));
+ Assert.IsTrue(set.Contains(4));
+ Assert.IsTrue(set.Contains(5));
+ }
+
+ [Test]
+ public void RemoveAll_List()
+ {
+ IList<int> list = new JCG.List<int> { 1, 2, 3, 4, 5 };
+ bool result = list.RemoveAll(new[] { 1, 2, 3 });
Review Comment:
We should probably test some values that are not in the `list`, also.
```c#
bool result = list.RemoveAll(new[] { 1, 2, 3, 100, 101 });
```
##########
src/Lucene.Net.Tests/Support/TestCollectionExtensions.cs:
##########
@@ -0,0 +1,160 @@
+using Lucene.Net.Attributes;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System.Collections;
+using System.Collections.Generic;
+using JCG = J2N.Collections.Generic;
+#nullable enable
+
+namespace Lucene.Net.Support
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /// <summary>
+ /// Tests for <see cref="CollectionExtensions"/>
+ /// </summary>
+ [TestFixture]
+ [LuceneNetSpecific]
+ public class TestCollectionExtensions : LuceneTestCase
+ {
+ [Test]
+ public void RetainAll_EmptySource()
+ {
+ ISet<int> set = new JCG.HashSet<int>(); // empty
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsFalse(result);
+ Assert.AreEqual(0, set.Count);
+ }
+
+ [Test]
+ public void RetainAll_Set()
+ {
+ ISet<int> set = new JCG.HashSet<int> { 1, 2, 3, 4, 5 };
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, set.Count);
+ Assert.IsTrue(set.Contains(1));
+ Assert.IsTrue(set.Contains(2));
+ Assert.IsTrue(set.Contains(3));
+ Assert.IsFalse(set.Contains(4));
+ Assert.IsFalse(set.Contains(5));
+ }
+
+ [Test]
+ public void RetainAll_List()
+ {
+ IList<int> list = new JCG.List<int> { 1, 2, 3, 4, 5 };
+ bool result = list.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, list.Count);
+ Assert.AreEqual(1, list[0]);
+ Assert.AreEqual(2, list[1]);
+ Assert.AreEqual(3, list[2]);
+ }
+
+ [Test]
+ public void RetainAll_Collection()
+ {
+ ICollection<int> collection = new TestCollection<int> { 1, 2, 3, 4, 5 };
+ bool result = collection.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, collection.Count);
+ Assert.IsTrue(collection.Contains(1));
+ Assert.IsTrue(collection.Contains(2));
+ Assert.IsTrue(collection.Contains(3));
+ Assert.IsFalse(collection.Contains(4));
+ Assert.IsFalse(collection.Contains(5));
+ }
+
+ [Test]
+ public void RemoveAll_EmptySource()
+ {
+ ISet<int> set = new JCG.HashSet<int>(); // empty
+ bool result = set.RemoveAll(new[] { 1, 2, 3 });
+ Assert.IsFalse(result);
+ Assert.AreEqual(0, set.Count);
+ }
+
+ [Test]
+ public void RemoveAll_Set()
+ {
+ ISet<int> set = new JCG.HashSet<int> { 1, 2, 3, 4, 5 };
+ bool result = set.RemoveAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(2, set.Count);
+ Assert.IsFalse(set.Contains(1));
+ Assert.IsFalse(set.Contains(2));
+ Assert.IsFalse(set.Contains(3));
+ Assert.IsTrue(set.Contains(4));
+ Assert.IsTrue(set.Contains(5));
+ }
+
+ [Test]
+ public void RemoveAll_List()
+ {
+ IList<int> list = new JCG.List<int> { 1, 2, 3, 4, 5 };
+ bool result = list.RemoveAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual(4, list[0]);
+ Assert.AreEqual(5, list[1]);
+ }
+
+ [Test]
+ public void RemoveAll_Collection()
+ {
+ ICollection<int> collection = new TestCollection<int> { 1, 2, 3, 4, 5 };
+ bool result = collection.RemoveAll(new[] { 1, 2, 3 });
Review Comment:
We should probably test some values that are not in the `collection`, also.
```c#
bool result = collection.RemoveAll(new[] { 1, 2, 3, 100, 101 });
```
##########
src/Lucene.Net.Tests/Support/TestCollectionExtensions.cs:
##########
@@ -0,0 +1,160 @@
+using Lucene.Net.Attributes;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System.Collections;
+using System.Collections.Generic;
+using JCG = J2N.Collections.Generic;
+#nullable enable
+
+namespace Lucene.Net.Support
+{
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ /// <summary>
+ /// Tests for <see cref="CollectionExtensions"/>
+ /// </summary>
+ [TestFixture]
+ [LuceneNetSpecific]
+ public class TestCollectionExtensions : LuceneTestCase
+ {
+ [Test]
+ public void RetainAll_EmptySource()
+ {
+ ISet<int> set = new JCG.HashSet<int>(); // empty
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsFalse(result);
+ Assert.AreEqual(0, set.Count);
+ }
+
+ [Test]
+ public void RetainAll_Set()
+ {
+ ISet<int> set = new JCG.HashSet<int> { 1, 2, 3, 4, 5 };
+ bool result = set.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, set.Count);
+ Assert.IsTrue(set.Contains(1));
+ Assert.IsTrue(set.Contains(2));
+ Assert.IsTrue(set.Contains(3));
+ Assert.IsFalse(set.Contains(4));
+ Assert.IsFalse(set.Contains(5));
+ }
+
+ [Test]
+ public void RetainAll_List()
+ {
+ IList<int> list = new JCG.List<int> { 1, 2, 3, 4, 5 };
+ bool result = list.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, list.Count);
+ Assert.AreEqual(1, list[0]);
+ Assert.AreEqual(2, list[1]);
+ Assert.AreEqual(3, list[2]);
+ }
+
+ [Test]
+ public void RetainAll_Collection()
+ {
+ ICollection<int> collection = new TestCollection<int> { 1, 2, 3, 4, 5 };
+ bool result = collection.RetainAll(new[] { 1, 2, 3 });
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, collection.Count);
+ Assert.IsTrue(collection.Contains(1));
+ Assert.IsTrue(collection.Contains(2));
+ Assert.IsTrue(collection.Contains(3));
+ Assert.IsFalse(collection.Contains(4));
+ Assert.IsFalse(collection.Contains(5));
+ }
+
+ [Test]
+ public void RemoveAll_EmptySource()
+ {
+ ISet<int> set = new JCG.HashSet<int>(); // empty
+ bool result = set.RemoveAll(new[] { 1, 2, 3 });
+ Assert.IsFalse(result);
+ Assert.AreEqual(0, set.Count);
+ }
+
+ [Test]
+ public void RemoveAll_Set()
+ {
+ ISet<int> set = new JCG.HashSet<int> { 1, 2, 3, 4, 5 };
+ bool result = set.RemoveAll(new[] { 1, 2, 3 });
Review Comment:
We should probably test some values that are not in the `set`, also.
```c#
bool result = set.RemoveAll(new[] { 1, 2, 3, 100, 101 });
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org