-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Harmony Support_ unit tests, #1117
- Loading branch information
Showing
5 changed files
with
312 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Adapted from Apache Harmony tests via J2N: https://github.com/NightOwl888/J2N/blob/main/tests/NUnit/J2N.Tests/Collections/Support_CollectionTest.cs | ||
using Lucene.Net.Util; | ||
using System.Collections.Generic; | ||
using JCG = J2N.Collections.Generic; | ||
|
||
namespace Lucene.Net | ||
{ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
public class Support_CollectionTest : LuceneTestCase | ||
{ | ||
readonly ICollection<int> col; // must contain the Integers 0 to 99 | ||
|
||
// LUCENENET: removed unused string argument and overload | ||
public Support_CollectionTest(/*String p1,*/ ICollection<int> c) | ||
//: base(p1) | ||
{ | ||
col = c; | ||
} | ||
|
||
public void RunTest() | ||
{ | ||
new Support_UnmodifiableCollectionTest(col).RunTest(); | ||
|
||
// setup | ||
ICollection<int> myCollection = new JCG.SortedSet<int>(); | ||
myCollection.Add(101); | ||
myCollection.Add(102); | ||
myCollection.Add(103); | ||
|
||
// add | ||
//assertTrue("CollectionTest - a) add did not work", col.Add(new Integer( | ||
// 101))); | ||
col.Add(101); // Does not return in .NET | ||
assertTrue("CollectionTest - b) add did not work", col | ||
.Contains(101)); | ||
|
||
// remove | ||
assertTrue("CollectionTest - a) remove did not work", col | ||
.Remove(101)); | ||
assertTrue("CollectionTest - b) remove did not work", !col | ||
.Contains(101)); | ||
|
||
if (col is ISet<int> set) | ||
{ | ||
// addAll | ||
//assertTrue("CollectionTest - a) addAll failed", set | ||
// .UnionWith(myCollection)); | ||
set.UnionWith(myCollection); // Does not return in .NET | ||
assertTrue("CollectionTest - b) addAll failed", set | ||
.IsSupersetOf(myCollection)); | ||
|
||
// containsAll | ||
assertTrue("CollectionTest - a) containsAll failed", set | ||
.IsSupersetOf(myCollection)); | ||
col.Remove(101); | ||
assertTrue("CollectionTest - b) containsAll failed", !set | ||
.IsSupersetOf(myCollection)); | ||
|
||
// removeAll | ||
//assertTrue("CollectionTest - a) removeAll failed", set | ||
// .ExceptWith(myCollection)); | ||
//assertTrue("CollectionTest - b) removeAll failed", !set | ||
// .ExceptWith(myCollection)); // should not change the colletion | ||
// // the 2nd time around | ||
|
||
set.ExceptWith(myCollection); // Does not return in .NET | ||
assertTrue("CollectionTest - c) removeAll failed", !set | ||
.Contains(102)); | ||
assertTrue("CollectionTest - d) removeAll failed", !set | ||
.Contains(103)); | ||
|
||
// retianAll | ||
set.UnionWith(myCollection); | ||
//assertTrue("CollectionTest - a) retainAll failed", set | ||
// .IntersectWith(myCollection)); | ||
//assertTrue("CollectionTest - b) retainAll failed", !set | ||
// .IntersectWith(myCollection)); // should not change the colletion | ||
// // the 2nd time around | ||
|
||
set.IntersectWith(myCollection); // Does not return in .NET | ||
assertTrue("CollectionTest - c) retainAll failed", set | ||
.IsSupersetOf(myCollection)); | ||
assertTrue("CollectionTest - d) retainAll failed", !set | ||
.Contains(0)); | ||
assertTrue("CollectionTest - e) retainAll failed", !set | ||
.Contains(50)); | ||
|
||
} | ||
|
||
// clear | ||
col.Clear(); | ||
assertTrue("CollectionTest - a) clear failed", col.Count == 0); | ||
assertTrue("CollectionTest - b) clear failed", !col | ||
.Contains(101)); | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Adapted from Apache Harmony tests: https://github.com/apache/harmony/blob/trunk/classlib/support/src/test/java/tests/support/Support_SetTest.java | ||
using Lucene.Net.Util; | ||
using System.Collections.Generic; | ||
|
||
namespace Lucene.Net | ||
{ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
public class Support_SetTest : LuceneTestCase | ||
{ | ||
ISet<int> set; // must contain the Integers 0 to 99 | ||
|
||
// LUCENENET: removed unused string argument and overload | ||
public Support_SetTest(/*String p1,*/ ISet<int> s) | ||
//: base(p1) | ||
{ | ||
set = s; | ||
} | ||
|
||
public void RunTest() { | ||
// add | ||
assertTrue("Set Test - Adding a duplicate element changed the set", | ||
!set.Add(50)); | ||
assertTrue("Set Test - Removing an element did not change the set", set | ||
.Remove(50)); | ||
assertTrue( | ||
"Set Test - Adding and removing a duplicate element failed to remove it", | ||
!set.Contains(50)); | ||
set.Add(50); | ||
new Support_CollectionTest(set).RunTest(); | ||
} | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
src/Lucene.Net.Tests/Support/Support_UnmodifiableCollectionTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Adapted from Apache Harmony tests via J2N: https://github.com/NightOwl888/J2N/blob/main/tests/NUnit/J2N.Tests/Collections/Support_UnmodifiableCollectionTest.cs | ||
|
||
using Lucene.Net.Util; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Lucene.Net | ||
{ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
public class Support_UnmodifiableCollectionTest : LuceneTestCase | ||
{ | ||
readonly ICollection<int> col; | ||
|
||
// must be a collection containing the Integers 0 to 99 (which will iterate | ||
// in order) | ||
|
||
// LUCENENET: removed unused string argument and overload | ||
public Support_UnmodifiableCollectionTest(/*String p1,*/ ICollection<int> c) | ||
//: base(p1) | ||
{ | ||
col = c; | ||
} | ||
|
||
public void RunTest() | ||
{ | ||
|
||
// contains | ||
assertTrue("UnmodifiableCollectionTest - should contain 0", col | ||
.Contains(0)); | ||
assertTrue("UnmodifiableCollectionTest - should contain 50", col | ||
.Contains(50)); | ||
assertTrue("UnmodifiableCollectionTest - should not contain 100", !col | ||
.Contains(100)); | ||
|
||
// containsAll | ||
HashSet<int> hs = new HashSet<int>(); | ||
hs.Add(0); | ||
hs.Add(25); | ||
hs.Add(99); | ||
assertTrue( | ||
"UnmodifiableCollectionTest - should contain set of 0, 25, and 99", | ||
col.Intersect(hs).Count() == hs.Count); // Contains all | ||
hs.Add(100); | ||
assertTrue( | ||
"UnmodifiableCollectionTest - should not contain set of 0, 25, 99 and 100", | ||
col.Intersect(hs).Count() != hs.Count); // Doesn't contain all | ||
|
||
// isEmpty | ||
assertTrue("UnmodifiableCollectionTest - should not be empty", col.Count > 0); | ||
|
||
// iterator | ||
IEnumerator<int> it = col.GetEnumerator(); | ||
SortedSet<int> ss = new SortedSet<int>(); | ||
while (it.MoveNext()) | ||
{ | ||
ss.Add(it.Current); | ||
} | ||
it = ss.GetEnumerator(); | ||
for (int counter = 0; it.MoveNext(); counter++) | ||
{ | ||
int nextValue = it.Current; | ||
assertTrue( | ||
"UnmodifiableCollectionTest - Iterator returned wrong value. Wanted: " | ||
+ counter + " got: " + nextValue, | ||
nextValue == counter); | ||
} | ||
|
||
// size | ||
assertTrue( | ||
"UnmodifiableCollectionTest - returned wrong size. Wanted 100, got: " | ||
+ col.Count, col.Count == 100); | ||
|
||
// toArray | ||
object[] objArray; | ||
objArray = col.Cast<object>().ToArray(); | ||
it = ss.GetEnumerator(); // J2N: Bug in Harmony, this needs to be reset to run | ||
for (int counter = 0; it.MoveNext(); counter++) | ||
{ | ||
assertTrue( | ||
"UnmodifiableCollectionTest - toArray returned incorrect array", | ||
(int)objArray[counter] == it.Current); | ||
} | ||
|
||
// toArray (Object[]) | ||
var intArray = new int[100]; | ||
col.CopyTo(intArray, 0); | ||
it = ss.GetEnumerator(); // J2N: Bug in Harmony, this needs to be reset to run | ||
for (int counter = 0; it.MoveNext(); counter++) | ||
{ | ||
assertTrue( | ||
"UnmodifiableCollectionTest - CopyTo(object[], int) filled array incorrectly", | ||
intArray[counter] == it.Current); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters