コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: Sk1f0/TestArrayApp
        public void Invalid_Array_For_Rotate()
        {
            using (var mock = AutoMock.GetStrict())
            {
                //Arrange
                mock.Mock <IArrayOperations>();
                var array = new CustomArray(
                    new int[, ]
                {
                    { 1, 2, 3 },
                    { 4, 5, 6 }
                });
                var sut = mock.Create <ArrayOperations>();

                //Act
                var actual = sut.Rotate(array);

                //Assert
                Assert.AreEqual(1, actual.Value[0, 0]);
                Assert.AreEqual(2, actual.Value[0, 1]);
                Assert.AreEqual(3, actual.Value[0, 2]);
                Assert.AreEqual(4, actual.Value[1, 0]);
                Assert.AreEqual(5, actual.Value[1, 1]);
                Assert.AreEqual(6, actual.Value[1, 2]);
                Assert.AreEqual(-1, actual.Size);
            }
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: JadeBerg/TP_2C_2S
        public void TestOp3()
        {
            CustomArray MyArray = new CustomArray();

            int[] array = { 2597, 3282, -2383, -1602, 4221, -2327, -4084, -4794, 3523, -2933 };
            int[] test  = { 4221, 1 };
            CollectionAssert.AreEqual(test, MyArray.Sum_3(array));
        }
コード例 #3
0
ファイル: ArrayTests.cs プロジェクト: Demihov/Task2
        public void Iterator_Set12To3Element_12Returned()
        {
            CustomArray <int> arr = new CustomArray <int>(-2, 10, 0, 1, 2, 3, 4, 5, 6, 7);

            arr[3] = 12;

            Assert.AreEqual(12, arr[3]);
        }
コード例 #4
0
 public void Indexer_GetElementOutOfRange_ShouldThrowArgumentException(int first, int length, int index)
 {
     //Arrange
     var custom = new CustomArray <int>(first, length);
     int result = 0;
     //Act -Assert
     var actEx = Assert.Throws <ArgumentException>(() => result = custom[index], message: "Set indexer works incorrect");
 }
コード例 #5
0
        public void Length_Get_ShouldReturnCorrectValue(int first, int length)
        {
            // Act
            var custom = new CustomArray <string>(first, length);

            //Assert
            Assert.AreEqual(length, custom.Length, message: "Length get  property works incorrectly ");
        }
コード例 #6
0
        public void Last_Get_ShouldReturnCorrectValue(int first, int length, int last)
        {
            //Act
            var custom = new CustomArray <bool>(first, length);

            //Assert
            Assert.AreEqual(last, custom.Last, message: "Last get property works incorrectly ");
        }
コード例 #7
0
ファイル: UnitTest1.cs プロジェクト: JadeBerg/TP_2C_2S
        public void TestOp1()
        {
            CustomArray MyArray = new CustomArray();

            int[] array = { -13, -1692, 110, 1283, -1127, 3420, -951 };
            int[] test  = { 3420, 1283, 110, -13, -951, -1127, -1692 };
            CollectionAssert.AreEqual(test, MyArray.ReverseArray(array));
        }
コード例 #8
0
 static void Main(string[] args)
 {
     var array   = new CustomArray <int>(2);
     var list    = new CustomList <int>();
     var queue   = new CustomQueue <int>();
     var stack   = new CustomStack <int>();
     var hashset = new CustomHashSet <int>();
 }
コード例 #9
0
 public void Initialize()
 {
     array    = new CustomArray <int>(5);
     array[0] = 10;
     array[1] = 20;
     array[2] = 30;
     array[3] = 40;
     array[4] = 50;
 }
コード例 #10
0
        public IHttpActionResult Export(CustomArray array)
        {
            if (array?.Value == null)
            {
                return(BadRequest());
            }

            return(Ok(_array.Export(array)));
        }
コード例 #11
0
        public IHttpActionResult RotateArray(CustomArray array)
        {
            if (array?.Value == null)
            {
                return(BadRequest());
            }

            return(Ok(_array.Rotate(array)));
        }
コード例 #12
0
        public void Indexer_GetElementAtPosition_ShouldReturnValue(int first, int length, int n, int element)
        {
            //Act
            var custom = new CustomArray <int>(first, length);

            custom[n] = element;
            //Assert
            Assert.AreEqual(element, custom[n], message: "Index get property works incorrectly");
        }
コード例 #13
0
        public void Array_TryInsertElementByInvalidIndex_ThrowIndexOutOfRangeException()
        {
            //Arrange
            string valueToInsert      = null;
            CustomArray <string> list = new CustomArray <string>(0, 1);

            //Act
            Assert.Throws <IndexOutOfRangeException>(() => list.InsertByIndex(valueToInsert, 6));
        }
コード例 #14
0
ファイル: UnitTest1.cs プロジェクト: JadeBerg/TP_2C_2S
        public void TestOp4()
        {
            CustomArray MyArray = new CustomArray();

            int[] array = { 4195, 20, -4514, 1717, 4951, -1964, 4072, 4115, -204, 28 };
            int   test  = 1;

            Assert.AreEqual(test, MyArray.CountPrimes(array));
        }
コード例 #15
0
        /// <summary>
        /// Makes a new <typeparamref name="CustomArray"/> with the values of <typeparamref name="CustomList"/>.
        /// </summary>
        /// <returns><typeparamref name="CustomArray"/> with the values.</returns>
        public CustomArray <T> ToArray()
        {
            var newlyArray = new CustomArray <T>(this.Count);

            for (int i = 0; i < Count; i++)
            {
                newlyArray[i] = array[i];
            }
            return(newlyArray);
        }
コード例 #16
0
        public void Constructor_ChecArrayIndexValue(int value)
        {
            CustomArray <int> arTests = new CustomArray <int>(-4, 2);

            for (int i = arTests.Start; i < arTests.End; i++)
            {
                arTests[i] = i * 2;
            }
            Assert.AreEqual(value, arTests[arTests.Start]);
        }
コード例 #17
0
        public void Indexer_SetElementOutOfRange_ShouldThrowArgumentException(int first, int length, int index)
        {
            //Arrange
            int value = -5;
            //Act
            var custom = new CustomArray <int>(first, length);

            //Assert
            Assert.Throws <ArgumentException>(() => custom[index] = value, message: "Indexer  should throw ArgumentException ,if index parameter  out of array range");
        }
コード例 #18
0
        public void Array_TryPopFrontFromEmptyArray_ThrowEmptyArrayException()
        {
            //Arrange

            CustomArray <string> list = new CustomArray <string>(0, 0);

            list.First = null;
            //Act
            Assert.Throws <EmptyArrayException>(() => list.PopFront());
        }
コード例 #19
0
        public SudokuStruct SwapSudokuCols(SudokuStruct OldMatrix)

        {
            SudokuStruct             NewMatrix = new SudokuStruct();
            CustomArray <SudokuCell> myArray   = new CustomArray <SudokuCell>();

            SudokuCell[] CurrCol = new SudokuCell[]
            {
                new SudokuCell(),
                new SudokuCell(),
                new SudokuCell(),
                new SudokuCell(),
                new SudokuCell(),
                new SudokuCell(),
                new SudokuCell(),
                new SudokuCell(),
                new SudokuCell(),
            };

            int[] FixedIndex = new int[3] {
                0, 1, 2
            };
            Random RandomGen = new Random();
            //int[] Indexes = FixedIndex;
            int indx, ind1 = 0, ind2 = 1, ind3 = 2;
            int TotalCols = 0;

            for (int Block = 0; Block < 3; Block++)
            {
                int[] Indexes = FixedIndex;
                for (int Cols = 0; Cols < 3; Cols++)
                {
                    indx = RandomGen.Next(Indexes.Length);
                    int NumIndx = Indexes[indx];

                    CurrCol = myArray.GetColumn(OldMatrix.SudokuCells, NumIndx);
                    for (int WorkCol = 0; WorkCol < 9; WorkCol++)
                    {
                        NewMatrix.SudokuCells[TotalCols, WorkCol] = CurrCol[WorkCol];
                    }
                    //Array.Copy(OldMatrix, (NumIndx * 9), NewMatrix, (9 * TotalCols), 9);
                    Indexes = UpdateIndxArray(Indexes, indx);
                    TotalCols++;
                }
                ind1 += 3;
                ind2 += 3;
                ind3 += 3;

                FixedIndex[0] = ind1;
                FixedIndex[1] = ind2;
                FixedIndex[2] = ind3;
            }

            return(NewMatrix);
        }
コード例 #20
0
        public void ConstructorRecivesArrayAndInitializeTheArrayAndSetValuesFromTheInput()
        {
            var customArr = new CustomArray <int>(2);

            customArr[0] = 1;
            customArr[1] = 2;
            var cutomList      = new CustomList <int>(customArr);
            var expextedResult = 2;

            Assert.AreEqual(expextedResult, cutomList.Count);
        }
コード例 #21
0
        public void ToArrayShouldReturnCustomArrayWithValuesCopied()
        {
            //Arrange
            var expectedResult = new CustomArray <int>(6);
            //Act
            var actualResult = stack.ToArray();

            //Assert
            Assert.AreEqual(expectedResult.GetType().Name, actualResult.GetType().Name);
            Assert.AreEqual(expectedResult.Length, actualResult.Length);
        }
コード例 #22
0
        public void Constructor_ChecArrayLenght(int len)
        {
            CustomArray <int> arTests = new CustomArray <int>(-4, 2);

            for (int i = arTests.Start; i < arTests.End; i++)
            {
                arTests[i] = i * 2;
            }

            Assert.AreEqual(len, arTests.Lenght);
        }
コード例 #23
0
        public void Indexer_WithNullValue_ShouldThrowArgumentNullException()
        {
            //arrange
            int    first  = 1;
            int    length = 7;
            string value  = null;
            int    index  = 5;
            var    custom = new CustomArray <string>(first, length);

            //act &assert
            Assert.Throws <ArgumentNullException>(() => custom[index] = value, message: "Indexer set not throw exception if value is null ");
        }
コード例 #24
0
        public void Length_SetElementLessThan0_ShouldThrowArgumentException(int length)
        {
            //Arrange
            int first      = 3;
            var expectedEx = typeof(ArgumentException);
            //Act
            var actEx = Assert.Catch(() => { var custom = new CustomArray <int>(first, length); });

            //Assert
            Assert.AreEqual(expectedEx, actEx.GetType(),
                            message: "Set property in Length should throw ArgumentException in case of length parameter smaller or equal 0  ");
        }
コード例 #25
0
        public static void Run()
        {
            var arr     = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            var numbers = new CustomArray(arr);

            new ArraySubscriber(numbers);
            new ArraySubscriber2(numbers);

            numbers.ScanArray();

            Console.ReadLine();
        }
コード例 #26
0
        static void Main(string[] args)
        {
            int leftBorder         = 4;
            int rightBorder        = 9;
            CustomArray <int> data = new CustomArray <int>(leftBorder, rightBorder);
            Random            rand = new Random();

            for (int i = leftBorder; i <= rightBorder; i++)
            {
                data[i] = rand.Next(0, 100);
            }
        }
コード例 #27
0
ファイル: UnitTest1.cs プロジェクト: JadeBerg/TP_2C_2S
        public void TestOp2()
        {
            CustomArray MyArray = new CustomArray();

            int[] array = { 1695, -2571, -436, -796, 1001, 2962, -392, 1634, 1454, 1939 };
            int   k     = 3;
            int   min   = -5000;
            int   max   = 5000;

            int[] test = { 1, 6, 3 };
            CollectionAssert.AreEqual(test, MyArray.Sub_intervals(array, k, min, max));
        }
コード例 #28
0
ファイル: UnitTest1.cs プロジェクト: KoroVaik/HomeWork
        public void CustomArrayTest_11andArrayAnd12_2()
        {
            int indexOfFirstElem = 11;
            int indexOfExpectedElem = 12;
            int[] array = new int[] { 1, 2, 3, 4, 5 };

            CustomArray customArray = new CustomArray(indexOfFirstElem, array);
            int actualResult = customArray[indexOfExpectedElem];

            Assert.AreEqual(2, actualResult);
            
        }
コード例 #29
0
        public void CopyToShouldThrowArgumentExceptionIfGivenIndexIsTooBig()
        {
            //Arange
            var queue = new CustomQueue <int>();
            var array = new CustomArray <int>(queue.Count);

            //Act
            queue.Enqueue(1);
            var ex = Assert.ThrowsException <ArgumentException>(() => queue.CopyTo(array, 2));

            //Assert
            Assert.AreEqual(theGivenParametarWasTooBig, ex.Message);
        }
コード例 #30
0
        public void CopyToShouldThrowIndexOutOfRangeExceptionIfGivenIndexIsLessThanZero()
        {
            //Arange
            var queue = new CustomQueue <int>();
            var array = new CustomArray <int>(queue.Count);

            //Act
            queue.Enqueue(1);
            var ex = Assert.ThrowsException <IndexOutOfRangeException>(() => queue.CopyTo(array, -1));

            //Assert
            Assert.AreEqual(givenParametarWasOutOfRange, ex.Message);
        }
コード例 #31
0
        static void Main(string[] args)
        {
            Console.WriteLine("---------------------------------");
            
            double[] elements = new double[] { 7, 1.3, 2.99, 76, 5, 89, 2.5, 3.8, 6.1, 0.3, 8.4 };
            CustomArray<double> array = new CustomArray<double>(elements);

            #region Full Array Print
            {
                Console.WriteLine("CustomArray: ");
                int i = 0;
                foreach (double d in array)
                {
                    Console.WriteLine(String.Format("Index {0}: {1}", i, d));
                    i++;
                }
            }
            Console.WriteLine();
            #endregion

            #region Filter Items
            {   // Using FilterItems extension method 
                Console.WriteLine("Items that satisfy the condition: item < 5");
                foreach (double d in array.FilterItems((double x) => { return x < 5; }))
                {
                    Console.WriteLine(d);
                }
            }
            Console.WriteLine();
            #endregion

            #region Filter Indexes
            {   // Using FilterIndexes instance method
                Console.WriteLine("Items with indexes, that satisfy the condition: x % 2 == 0");
                foreach (double d in array.FilterIndexes((int x) => { return x % 2 == 0; }))
                {
                    Console.WriteLine(d);
                }
            }
            Console.WriteLine();
            #endregion             

            #region Filter Items and Indexes
            {   // Using FilterItems extension method with inxese filtering
                Console.WriteLine("Items that satisfy the condition: item < 5, index < 8");
                foreach (double d in array.FilterItems((double x) => { return x < 5; }, (int x) => {return x % 2 == 0; }))
                {
                    Console.WriteLine(d);
                }
            }
            Console.WriteLine();
            #endregion

            Console.WriteLine("---------------------------------");
            Console.WriteLine("Fibonacci series:");

            foreach(long i in FibonacciNumbers.Find(int.MaxValue / 4))
            {
                Console.WriteLine(i);
            }

            Console.ReadLine();
            

        }