paulirwin commented on code in PR #1121:
URL: https://github.com/apache/lucenenet/pull/1121#discussion_r1928889326


##########
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:
   As far as I know, there aren't any issues with special values like MaxValue 
and MinValue, since those have well-defined binary representations, but it 
can't hurt to be consistent, and it avoids having to do the ReSharper 
suppression. I also like this better than doing an epsilon difference 
comparison. Updated.



-- 
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

Reply via email to