Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @TestFactory Stream<org.junit.jupiter.api.DynamicTest> shouldHandleSomeRandomSetAndGet()
        internal virtual Stream <DynamicTest> ShouldHandleSomeRandomSetAndGet()
        {
            ThrowingConsumer <NumberArrayFactory> arrayFactoryConsumer = factory =>
            {
                int  length       = _random.Next(100_000) + 100;
                long defaultValue = _random.Next(2) - 1;                   // 0 or -1
                using (LongArray array = factory.newLongArray(length, defaultValue))
                {
                    long[] expected = new long[length];
                    Arrays.Fill(expected, defaultValue);

                    // WHEN
                    int operations = _random.Next(1_000) + 10;
                    for (int i = 0; i < operations; i++)
                    {
                        // THEN
                        int  index = _random.Next(length);
                        long value = _random.nextLong();
                        switch (_random.Next(3))
                        {
                        case 0:                           // set
                            array.Set(index, value);
                            expected[index] = value;
                            break;

                        case 1:                           // get
                            assertEquals(expected[index], array.Get(index), "Seed:" + _seed);
                            break;

                        default:                           // swap
                            int toIndex = _random.Next(length);
                            array.Swap(index, toIndex);
                            Swap(expected, index, toIndex);
                            break;
                        }
                    }
                }
            };

            return(stream(ArrayFactories(), NumberArrayFactoryName, arrayFactoryConsumer));
        }