NightOwl888 commented on code in PR #1121: URL: https://github.com/apache/lucenenet/pull/1121#discussion_r1926400846
########## src/Lucene.Net.Facet/FacetResult.cs: ########## @@ -117,7 +117,7 @@ public string ToString(IFormatProvider? provider) sb.Append("dim="); sb.Append(Dim); sb.Append(" path="); - sb.Append(Arrays.ToString(Path, provider)); + sb.Append(Arrays.ToString(Path)); Review Comment: Please revert this. See my comment in `Arrays.ToString(T[], IFormatProvider)`. ########## src/Lucene.Net.Tests/Support/TestArrays.cs: ########## @@ -0,0 +1,912 @@ +// Some tests from Apache Harmony: +// https://github.com/apache/harmony/blob/02970cb7227a335edd2c8457ebdde0195a735733/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java + +using Lucene.Net.Attributes; +using Lucene.Net.Util; +using NUnit.Framework; +using System; +#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. + */ + [TestFixture] + public class TestArrays : LuceneTestCase + { + /// <summary> + /// Adapted from test_fill$BB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Byte() + { + // Test for method void Arrays.Fill(byte[], byte) + byte[] d = new byte[1000]; + Arrays.Fill(d, byte.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == byte.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$BIIB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Int32_Int32_Byte() + { + // Test for method void Arrays.Fill(byte[], int, int, byte) + const byte val = byte.MaxValue; + byte[] d = new byte[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == val); + } + + int result; + try + { + Arrays.Fill(new byte[2], 2, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception1", 2, result); + try + { + Arrays.Fill(new byte[2], -1, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception2", 1, result); + try + { + Arrays.Fill(new byte[2], 1, 4, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception", 1, result); + } + + /// <summary> + /// Adapted from test_fill$SS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int16() + { + // Test for method void Arrays.Fill(short[], short) + short[] d = new short[1000]; + Arrays.Fill(d, short.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == short.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$SIIS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int32_Int32_Int16() + { + // Test for method void Arrays.Fill(short[], int, int, short) + const short val = short.MaxValue; + short[] d = new short[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$CC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Char() + { + // Test for method void Arrays.Fill(char[], char) + char[] d = new char[1000]; + Arrays.Fill(d, 'V'); + for (int i = 0; i < d.Length; i++) + { + assertEquals("Failed to fill char array correctly", 'V', d[i]); + } + } + + /// <summary> + /// Adapted from test_fill$CIIC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Int32_Int32_Char() + { + // Test for method void Arrays.Fill(char[], int, int, char) + const char val = 'T'; + char[] d = new char[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill char array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$II() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32() + { + // Test for method void Arrays.Fill(int[], int) + int[] d = new int[1000]; + Arrays.Fill(d, int.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == int.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$IIII() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32_Int32_Int32() + { + // Test for method void Arrays.Fill(int[], int, int, int) + const int val = int.MaxValue; + int[] d = new int[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$JJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int64() + { + // Test for method void Arrays.Fill(long[], long) + long[] d = new long[1000]; + Arrays.Fill(d, long.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == long.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$JIIJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int32_Int32_Int64() + { + // Test for method void Arrays.Fill(long[], int, int, long) + const long val = long.MaxValue; + long[] d = new long[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$FF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Single() + { + // Test for method void Arrays.Fill(float[], float) + float[] d = new float[1000]; + Arrays.Fill(d, float.MaxValue); + for (int i = 0; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == float.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$FIIF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Int32_Int32_Single() + { + // Test for method void Arrays.Fill(float[], int, int, float) + const float val = float.MaxValue; + float[] d = new float[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly not this value + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$DD() in Harmony + /// </summary> + [Test] + public void TestFill_DoubleArray_Double() + { + // Test for method void Arrays.Fill(double[], double) + double[] d = new double[1000]; + Arrays.Fill(d, double.MaxValue); + for (int i = 0; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill double array correctly", d[i] == double.MaxValue); Review Comment: Due to how JIT screws this up on x86 in .NET Framework, we should compare raw bits. ```c# NumericUtils.DoubleToSortableInt64(d[i]) == NumericUtils.DoubleToSortableInt64(double.MaxValue) ``` ########## src/Lucene.Net.Tests/Support/TestArrays.cs: ########## @@ -0,0 +1,912 @@ +// Some tests from Apache Harmony: +// https://github.com/apache/harmony/blob/02970cb7227a335edd2c8457ebdde0195a735733/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java + +using Lucene.Net.Attributes; +using Lucene.Net.Util; +using NUnit.Framework; +using System; +#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. + */ + [TestFixture] + public class TestArrays : LuceneTestCase + { + /// <summary> + /// Adapted from test_fill$BB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Byte() + { + // Test for method void Arrays.Fill(byte[], byte) + byte[] d = new byte[1000]; + Arrays.Fill(d, byte.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == byte.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$BIIB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Int32_Int32_Byte() + { + // Test for method void Arrays.Fill(byte[], int, int, byte) + const byte val = byte.MaxValue; + byte[] d = new byte[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == val); + } + + int result; + try + { + Arrays.Fill(new byte[2], 2, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception1", 2, result); + try + { + Arrays.Fill(new byte[2], -1, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception2", 1, result); + try + { + Arrays.Fill(new byte[2], 1, 4, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception", 1, result); + } + + /// <summary> + /// Adapted from test_fill$SS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int16() + { + // Test for method void Arrays.Fill(short[], short) + short[] d = new short[1000]; + Arrays.Fill(d, short.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == short.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$SIIS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int32_Int32_Int16() + { + // Test for method void Arrays.Fill(short[], int, int, short) + const short val = short.MaxValue; + short[] d = new short[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$CC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Char() + { + // Test for method void Arrays.Fill(char[], char) + char[] d = new char[1000]; + Arrays.Fill(d, 'V'); + for (int i = 0; i < d.Length; i++) + { + assertEquals("Failed to fill char array correctly", 'V', d[i]); + } + } + + /// <summary> + /// Adapted from test_fill$CIIC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Int32_Int32_Char() + { + // Test for method void Arrays.Fill(char[], int, int, char) + const char val = 'T'; + char[] d = new char[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill char array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$II() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32() + { + // Test for method void Arrays.Fill(int[], int) + int[] d = new int[1000]; + Arrays.Fill(d, int.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == int.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$IIII() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32_Int32_Int32() + { + // Test for method void Arrays.Fill(int[], int, int, int) + const int val = int.MaxValue; + int[] d = new int[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$JJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int64() + { + // Test for method void Arrays.Fill(long[], long) + long[] d = new long[1000]; + Arrays.Fill(d, long.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == long.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$JIIJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int32_Int32_Int64() + { + // Test for method void Arrays.Fill(long[], int, int, long) + const long val = long.MaxValue; + long[] d = new long[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$FF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Single() + { + // Test for method void Arrays.Fill(float[], float) + float[] d = new float[1000]; + Arrays.Fill(d, float.MaxValue); + for (int i = 0; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == float.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$FIIF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Int32_Int32_Single() + { + // Test for method void Arrays.Fill(float[], int, int, float) + const float val = float.MaxValue; + float[] d = new float[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly not this value + assertTrue("Filled elements not in range", d[i] != val); Review Comment: Due to how JIT screws this up on x86 in .NET Framework, we should compare raw bits. ```c# NumericUtils.SingleToSortableInt32(d[i]) != NumericUtils.SingleToSortableInt32(val) ``` ########## src/Lucene.Net/Support/Arrays.cs: ########## @@ -622,34 +624,5 @@ public static string ToString<T>(T[] array) sb.Append(']'); return sb.ToString(); } - - /// <summary> - /// Creates a <see cref="string"/> representation of the array passed. - /// The result is surrounded by brackets <c>"[]"</c>, each - /// element is converted to a <see cref="string"/> via the - /// <paramref name="provider"/> and separated by <c>", "</c>. If - /// the array is <c>null</c>, then <c>"null"</c> is returned. - /// </summary> - /// <typeparam name="T">The type of array element.</typeparam> - /// <param name="array">The array to convert.</param> - /// <param name="provider">A <see cref="IFormatProvider"/> instance that supplies the culture formatting information.</param> - /// <returns>The converted array string.</returns> - public static string ToString<T>(T[] array, IFormatProvider provider) Review Comment: This is not a bug, it is a feature. In .NET, the default behavior is to use culture-sensitive formatting, but in Java the default is culture invariant. In most cases (`ToString()` methods), the output should be displayed in the culture of the current thread, as that is what .NET users expect to happen. So, technically, the default overload is the one that is broken by hard coding `J2N.Text.StringFormatter.InvariantCulture` instead of using `J2N.Text.StringFormatter.CurrentCulture`. But changing it is going to require a review and should probably be left to be done in another issue that considers culture-sensitivity as a whole after we have completed #924. There are cases where we need to override this behavior, such as when there are tests that check the output of `ToString()`. Since the test framework randomly chooses the culture of the current thread, we can specify to use the invariant culture in those tests. I would say that this is one of those cases. We can leave the proper formatting of specific cultures up to the J2N tests to catch and only check the basic formatting that these methods do in the Lucene.NET codebase. FYI - `J2N.Text.StringFormatter` is aware of collections and will do structural formatting on those if passed as the `IFormatProvider`. It also lowercases boolean `true` and `false` and ensures there is at least 1 zero in the decimal place position on floating point types. So, it is a closer match to Java behavior than using `CultureInfo.InvariantCulture`. But there is nothing at all in .NET or in Java like `J2N.Text.StringFormatter.CurrentCulture`. It is an attempt to make a Java-like format that is localized to the current thread. But we should leave testing of that for J2N to work out. ########## src/Lucene.Net.Tests/Support/TestArrays.cs: ########## @@ -0,0 +1,912 @@ +// Some tests from Apache Harmony: +// https://github.com/apache/harmony/blob/02970cb7227a335edd2c8457ebdde0195a735733/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java + +using Lucene.Net.Attributes; +using Lucene.Net.Util; +using NUnit.Framework; +using System; +#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. + */ + [TestFixture] + public class TestArrays : LuceneTestCase + { + /// <summary> + /// Adapted from test_fill$BB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Byte() + { + // Test for method void Arrays.Fill(byte[], byte) + byte[] d = new byte[1000]; + Arrays.Fill(d, byte.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == byte.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$BIIB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Int32_Int32_Byte() + { + // Test for method void Arrays.Fill(byte[], int, int, byte) + const byte val = byte.MaxValue; + byte[] d = new byte[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == val); + } + + int result; + try + { + Arrays.Fill(new byte[2], 2, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception1", 2, result); + try + { + Arrays.Fill(new byte[2], -1, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception2", 1, result); + try + { + Arrays.Fill(new byte[2], 1, 4, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception", 1, result); + } + + /// <summary> + /// Adapted from test_fill$SS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int16() + { + // Test for method void Arrays.Fill(short[], short) + short[] d = new short[1000]; + Arrays.Fill(d, short.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == short.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$SIIS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int32_Int32_Int16() + { + // Test for method void Arrays.Fill(short[], int, int, short) + const short val = short.MaxValue; + short[] d = new short[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$CC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Char() + { + // Test for method void Arrays.Fill(char[], char) + char[] d = new char[1000]; + Arrays.Fill(d, 'V'); + for (int i = 0; i < d.Length; i++) + { + assertEquals("Failed to fill char array correctly", 'V', d[i]); + } + } + + /// <summary> + /// Adapted from test_fill$CIIC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Int32_Int32_Char() + { + // Test for method void Arrays.Fill(char[], int, int, char) + const char val = 'T'; + char[] d = new char[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill char array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$II() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32() + { + // Test for method void Arrays.Fill(int[], int) + int[] d = new int[1000]; + Arrays.Fill(d, int.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == int.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$IIII() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32_Int32_Int32() + { + // Test for method void Arrays.Fill(int[], int, int, int) + const int val = int.MaxValue; + int[] d = new int[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$JJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int64() + { + // Test for method void Arrays.Fill(long[], long) + long[] d = new long[1000]; + Arrays.Fill(d, long.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == long.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$JIIJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int32_Int32_Int64() + { + // Test for method void Arrays.Fill(long[], int, int, long) + const long val = long.MaxValue; + long[] d = new long[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$FF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Single() + { + // Test for method void Arrays.Fill(float[], float) + float[] d = new float[1000]; + Arrays.Fill(d, float.MaxValue); + for (int i = 0; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == float.MaxValue); Review Comment: Due to how JIT screws this up on x86 in .NET Framework, we should compare raw bits. ```c# NumericUtils.SingleToSortableInt32(d[i]) == NumericUtils.SingleToSortableInt32(float.MaxValue) ``` ########## src/Lucene.Net.Tests/Support/TestArrays.cs: ########## @@ -0,0 +1,912 @@ +// Some tests from Apache Harmony: +// https://github.com/apache/harmony/blob/02970cb7227a335edd2c8457ebdde0195a735733/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java + +using Lucene.Net.Attributes; +using Lucene.Net.Util; +using NUnit.Framework; +using System; +#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. + */ + [TestFixture] + public class TestArrays : LuceneTestCase + { + /// <summary> + /// Adapted from test_fill$BB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Byte() + { + // Test for method void Arrays.Fill(byte[], byte) + byte[] d = new byte[1000]; + Arrays.Fill(d, byte.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == byte.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$BIIB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Int32_Int32_Byte() + { + // Test for method void Arrays.Fill(byte[], int, int, byte) + const byte val = byte.MaxValue; + byte[] d = new byte[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == val); + } + + int result; + try + { + Arrays.Fill(new byte[2], 2, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception1", 2, result); + try + { + Arrays.Fill(new byte[2], -1, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception2", 1, result); + try + { + Arrays.Fill(new byte[2], 1, 4, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception", 1, result); + } + + /// <summary> + /// Adapted from test_fill$SS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int16() + { + // Test for method void Arrays.Fill(short[], short) + short[] d = new short[1000]; + Arrays.Fill(d, short.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == short.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$SIIS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int32_Int32_Int16() + { + // Test for method void Arrays.Fill(short[], int, int, short) + const short val = short.MaxValue; + short[] d = new short[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$CC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Char() + { + // Test for method void Arrays.Fill(char[], char) + char[] d = new char[1000]; + Arrays.Fill(d, 'V'); + for (int i = 0; i < d.Length; i++) + { + assertEquals("Failed to fill char array correctly", 'V', d[i]); + } + } + + /// <summary> + /// Adapted from test_fill$CIIC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Int32_Int32_Char() + { + // Test for method void Arrays.Fill(char[], int, int, char) + const char val = 'T'; + char[] d = new char[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill char array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$II() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32() + { + // Test for method void Arrays.Fill(int[], int) + int[] d = new int[1000]; + Arrays.Fill(d, int.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == int.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$IIII() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32_Int32_Int32() + { + // Test for method void Arrays.Fill(int[], int, int, int) + const int val = int.MaxValue; + int[] d = new int[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$JJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int64() + { + // Test for method void Arrays.Fill(long[], long) + long[] d = new long[1000]; + Arrays.Fill(d, long.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == long.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$JIIJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int32_Int32_Int64() + { + // Test for method void Arrays.Fill(long[], int, int, long) + const long val = long.MaxValue; + long[] d = new long[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$FF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Single() + { + // Test for method void Arrays.Fill(float[], float) + float[] d = new float[1000]; + Arrays.Fill(d, float.MaxValue); + for (int i = 0; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == float.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$FIIF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Int32_Int32_Single() + { + // Test for method void Arrays.Fill(float[], int, int, float) + const float val = float.MaxValue; + float[] d = new float[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly not this value + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$DD() in Harmony + /// </summary> + [Test] + public void TestFill_DoubleArray_Double() + { + // Test for method void Arrays.Fill(double[], double) + double[] d = new double[1000]; + Arrays.Fill(d, double.MaxValue); + for (int i = 0; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill double array correctly", d[i] == double.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$DIID() in Harmony + /// </summary> + [Test] + public void TestFill_DoubleArray_Int32_Int32_Double() + { + // Test for method void Arrays.Fill(double[], int, int, double) + const double val = double.MaxValue; + double[] d = new double[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly not this value + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill double array correctly", d[i] == val); Review Comment: Due to how JIT screws this up on x86 in .NET Framework, we should compare raw bits. ```c# NumericUtils.DoubleToSortableInt64(d[i]) == NumericUtils.DoubleToSortableInt64(val) ########## src/Lucene.Net.Tests/Support/TestArrays.cs: ########## @@ -0,0 +1,912 @@ +// Some tests from Apache Harmony: +// https://github.com/apache/harmony/blob/02970cb7227a335edd2c8457ebdde0195a735733/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java + +using Lucene.Net.Attributes; +using Lucene.Net.Util; +using NUnit.Framework; +using System; +#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. + */ + [TestFixture] + public class TestArrays : LuceneTestCase + { + /// <summary> + /// Adapted from test_fill$BB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Byte() + { + // Test for method void Arrays.Fill(byte[], byte) + byte[] d = new byte[1000]; + Arrays.Fill(d, byte.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == byte.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$BIIB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Int32_Int32_Byte() + { + // Test for method void Arrays.Fill(byte[], int, int, byte) + const byte val = byte.MaxValue; + byte[] d = new byte[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == val); + } + + int result; + try + { + Arrays.Fill(new byte[2], 2, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception1", 2, result); + try + { + Arrays.Fill(new byte[2], -1, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception2", 1, result); + try + { + Arrays.Fill(new byte[2], 1, 4, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception", 1, result); + } + + /// <summary> + /// Adapted from test_fill$SS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int16() + { + // Test for method void Arrays.Fill(short[], short) + short[] d = new short[1000]; + Arrays.Fill(d, short.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == short.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$SIIS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int32_Int32_Int16() + { + // Test for method void Arrays.Fill(short[], int, int, short) + const short val = short.MaxValue; + short[] d = new short[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$CC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Char() + { + // Test for method void Arrays.Fill(char[], char) + char[] d = new char[1000]; + Arrays.Fill(d, 'V'); + for (int i = 0; i < d.Length; i++) + { + assertEquals("Failed to fill char array correctly", 'V', d[i]); + } + } + + /// <summary> + /// Adapted from test_fill$CIIC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Int32_Int32_Char() + { + // Test for method void Arrays.Fill(char[], int, int, char) + const char val = 'T'; + char[] d = new char[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill char array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$II() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32() + { + // Test for method void Arrays.Fill(int[], int) + int[] d = new int[1000]; + Arrays.Fill(d, int.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == int.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$IIII() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32_Int32_Int32() + { + // Test for method void Arrays.Fill(int[], int, int, int) + const int val = int.MaxValue; + int[] d = new int[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$JJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int64() + { + // Test for method void Arrays.Fill(long[], long) + long[] d = new long[1000]; + Arrays.Fill(d, long.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == long.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$JIIJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int32_Int32_Int64() + { + // Test for method void Arrays.Fill(long[], int, int, long) + const long val = long.MaxValue; + long[] d = new long[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$FF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Single() + { + // Test for method void Arrays.Fill(float[], float) + float[] d = new float[1000]; + Arrays.Fill(d, float.MaxValue); + for (int i = 0; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == float.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$FIIF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Int32_Int32_Single() + { + // Test for method void Arrays.Fill(float[], int, int, float) + const float val = float.MaxValue; + float[] d = new float[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly not this value + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$DD() in Harmony + /// </summary> + [Test] + public void TestFill_DoubleArray_Double() + { + // Test for method void Arrays.Fill(double[], double) + double[] d = new double[1000]; + Arrays.Fill(d, double.MaxValue); + for (int i = 0; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill double array correctly", d[i] == double.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$DIID() in Harmony + /// </summary> + [Test] + public void TestFill_DoubleArray_Int32_Int32_Double() + { + // Test for method void Arrays.Fill(double[], int, int, double) + const double val = double.MaxValue; + double[] d = new double[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly not this value + assertTrue("Filled elements not in range", d[i] != val); Review Comment: Due to how JIT screws this up on x86 in .NET Framework, we should compare raw bits. ```c# NumericUtils.DoubleToSortableInt64(d[i]) != NumericUtils.DoubleToSortableInt64(val) ########## src/Lucene.Net.Tests/Support/TestArrays.cs: ########## @@ -0,0 +1,912 @@ +// Some tests from Apache Harmony: +// https://github.com/apache/harmony/blob/02970cb7227a335edd2c8457ebdde0195a735733/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/ArraysTest.java + +using Lucene.Net.Attributes; +using Lucene.Net.Util; +using NUnit.Framework; +using System; +#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. + */ + [TestFixture] + public class TestArrays : LuceneTestCase + { + /// <summary> + /// Adapted from test_fill$BB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Byte() + { + // Test for method void Arrays.Fill(byte[], byte) + byte[] d = new byte[1000]; + Arrays.Fill(d, byte.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == byte.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$BIIB() in Harmony + /// </summary> + [Test] + public void TestFill_ByteArray_Int32_Int32_Byte() + { + // Test for method void Arrays.Fill(byte[], int, int, byte) + const byte val = byte.MaxValue; + byte[] d = new byte[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill byte array correctly", d[i] == val); + } + + int result; + try + { + Arrays.Fill(new byte[2], 2, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception1", 2, result); + try + { + Arrays.Fill(new byte[2], -1, 1, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception2", 1, result); + try + { + Arrays.Fill(new byte[2], 1, 4, (byte)27); + result = 0; + } + catch (Exception e) when (e.IsArrayIndexOutOfBoundsException()) + { + result = 1; + } + catch (Exception e) when (e.IsIllegalArgumentException()) + { + result = 2; + } + + assertEquals("Wrong exception", 1, result); + } + + /// <summary> + /// Adapted from test_fill$SS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int16() + { + // Test for method void Arrays.Fill(short[], short) + short[] d = new short[1000]; + Arrays.Fill(d, short.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == short.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$SIIS() in Harmony + /// </summary> + [Test] + public void TestFill_Int16Array_Int32_Int32_Int16() + { + // Test for method void Arrays.Fill(short[], int, int, short) + const short val = short.MaxValue; + short[] d = new short[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill short array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$CC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Char() + { + // Test for method void Arrays.Fill(char[], char) + char[] d = new char[1000]; + Arrays.Fill(d, 'V'); + for (int i = 0; i < d.Length; i++) + { + assertEquals("Failed to fill char array correctly", 'V', d[i]); + } + } + + /// <summary> + /// Adapted from test_fill$CIIC() in Harmony + /// </summary> + [Test] + public void TestFill_CharArray_Int32_Int32_Char() + { + // Test for method void Arrays.Fill(char[], int, int, char) + const char val = 'T'; + char[] d = new char[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill char array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$II() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32() + { + // Test for method void Arrays.Fill(int[], int) + int[] d = new int[1000]; + Arrays.Fill(d, int.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == int.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$IIII() in Harmony + /// </summary> + [Test] + public void TestFill_Int32Array_Int32_Int32_Int32() + { + // Test for method void Arrays.Fill(int[], int, int, int) + const int val = int.MaxValue; + int[] d = new int[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill int array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$JJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int64() + { + // Test for method void Arrays.Fill(long[], long) + long[] d = new long[1000]; + Arrays.Fill(d, long.MaxValue); + for (int i = 0; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == long.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$JIIJ() in Harmony + /// </summary> + [Test] + public void TestFill_Int64Array_Int32_Int32_Int64() + { + // Test for method void Arrays.Fill(long[], int, int, long) + const long val = long.MaxValue; + long[] d = new long[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + assertTrue("Failed to fill long array correctly", d[i] == val); + } + } + + /// <summary> + /// Adapted from test_fill$FF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Single() + { + // Test for method void Arrays.Fill(float[], float) + float[] d = new float[1000]; + Arrays.Fill(d, float.MaxValue); + for (int i = 0; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == float.MaxValue); + } + } + + /// <summary> + /// Adapted from test_fill$FIIF() in Harmony + /// </summary> + [Test] + public void TestFill_SingleArray_Int32_Int32_Single() + { + // Test for method void Arrays.Fill(float[], int, int, float) + const float val = float.MaxValue; + float[] d = new float[1000]; + Arrays.Fill(d, 400, d.Length, val); + + for (int i = 0; i < 400; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly not this value + assertTrue("Filled elements not in range", d[i] != val); + } + + for (int i = 400; i < d.Length; i++) + { + // ReSharper disable once CompareOfFloatsByEqualityOperator - we're looking for exactly this value + assertTrue("Failed to fill float array correctly", d[i] == val); Review Comment: Due to how JIT screws this up on x86 in .NET Framework, we should compare raw bits. ```c# NumericUtils.SingleToSortableInt32(d[i]) == NumericUtils.SingleToSortableInt32(val) ``` -- 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-unsubscr...@lucenenet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org