static void Main(string[] args) { OneDimArray oneDimArray = new OneDimArray(2); oneDimArray[0] = 5; Console.WriteLine(oneDimArray[0]); Console.ReadLine(); }
public void IndexException_ArrayWithSize5TryToGetGiven_IndexExceptionReturn() { OneDimArray <string> arrayString = new OneDimArray <string>(-10, -5); arrayString[-10] = "-10"; string actual; Assert.Throws <IndexException>(() => { actual = arrayString[500]; }); }
public void SizeException_ArrayWithNegativeSizeGiven_SizeExceptionReturn() { try { OneDimArray <string> arrayString = new OneDimArray <string>(5, -5); } catch (SizeException exception) { Assert.Equal("Array's size must be > 0", exception.Message); } }
public void GetWithIndexer_AppealArrMinus1_10Return() { // arrange int expected = 10; OneDimArray <int> arrInt = new OneDimArray <int>(-2, 2); arrInt[-2] = 1; arrInt[-1] = 10; arrInt[0] = 3; // act int actual = arrInt[-1]; // assert Assert.Equal(expected, actual); }
static void Main() { //byte step = 2; OneDimArray arr = new OneDimArray(50, 1, 15); PrintData.ArrPrint(arr.GetArr(), 15); Console.WriteLine(); PrintData.ArrPrint(arr.GetArrReversed(), 15); Console.WriteLine(); arr.Multi(5); PrintData.ArrPrint(arr.GetArr(), 5); Console.WriteLine($"\n{arr.ToString()}"); Console.WriteLine(); PrintData.DictPrint(arr.EachElCount); Console.ReadLine(); }
public void Length_ArrayWith5SizeAnd4ElementsGiven_5Return() { //arrange int expected = 5; OneDimArray <string> arrayString = new OneDimArray <string>(-10, -5); arrayString[-10] = "-10"; arrayString[-9] = "-9"; arrayString[-8] = "-8"; arrayString[-7] = "-7"; //act int actual = arrayString.Length(); //assert Assert.Equal(expected, actual); }
public void Clear_ArrayWith5SizeAnd4ElementsGiven_555Return() { //arrange string expected = "555"; OneDimArray <string> arrayString = new OneDimArray <string>(-10, -5); arrayString[-10] = "-10"; arrayString[-9] = "-9"; arrayString[-8] = "-8"; arrayString[-7] = "-7"; arrayString.Clear(); arrayString[-10] = "400"; arrayString[-9] = "555"; //act string actual = arrayString[-9]; //assert Assert.Equal(expected, actual); }
public void CopyTo_OneDimArrayTypeStringToStringArrayAndCompareElements() { //arrange string expected = "-8"; OneDimArray <string> arrayString = new OneDimArray <string>(-10, 5); arrayString[-10] = "-10"; arrayString[-9] = "-9"; arrayString[-8] = "-8"; arrayString[-7] = "-7"; arrayString[-6] = "-6"; //act string[] arr = new string[5]; arrayString.CopyTo(arr, 0); string actual = arr[2]; //assert Assert.Equal(expected, actual); }
static void Main() { int arrLen = 50; int devider = 3; int min = -10000; int max = 10000; int[] arr = new int[arrLen]; Random rnd = new Random(); string str = @"..\..\..\SampleData.txt"; arr = new OneDimArray(arr.Length, min, max).GetArr(); PrintData.ArrPrint(arr, 5); Console.WriteLine($"\nПары, в которых только одно число делится на: {devider}"); ArrHandle.SearchPair(arr, devider); Console.WriteLine(); Array.Clear(arr, 0, arrLen); arr = new OneDimArray(rnd.Next(1, arrLen / 2), min, max).GetArr(); FileIO.AppendToFile(str, arr); FileIO.ReadFromFile(str); Console.ReadLine(); }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return(OneDimArray.GetEnumerator()); }
static void Main(string[] args) { Console.WriteLine("The fourth homework in geekbrains. Task 3a"); int number = 1; int key = 1; int size = 0; OneDimArray array = new OneDimArray(20); while ((number > 0 || number < 4) && key == 1) { key = 0; WriteBeautiful("the method of input:\n1)Randomazer;\n2)From file\n3)With step", ConsoleColor.Red); number = Convert.ToInt32(Console.ReadLine()); switch (number) { case 1: WriteBeautiful("Input the size", ConsoleColor.Blue); size = Convert.ToInt32(Console.ReadLine()); array = new OneDimArray(size); array.InitArray(); break; case 2: string filename = @"C:\Users\Dasha\Desktop\GEEKBRAINS\GBrainCsharp\Homework4\Task2\Homework4\data.txt"; array = new OneDimArray(filename); break; case 3: WriteBeautiful("Input the size", ConsoleColor.Blue); size = Convert.ToInt32(Console.ReadLine()); WriteBeautiful("Input first element", ConsoleColor.Blue); int first = Convert.ToInt32(Console.ReadLine()); WriteBeautiful("Input the step", ConsoleColor.Blue); int step = Convert.ToInt32(Console.ReadLine()); array = new OneDimArray(size, step, first); //array.Output(); break; default: Console.WriteLine("Have a nice day!"); //TASK_6 Environment.Exit(0); break; } Console.WriteLine("It's your array"); array.Output(); WriteBeautiful("what should i do?", ConsoleColor.Red); WriteBeautiful("the method of input:\n1)Sum;\n2)Inverse\n3)Multi\n4)MaxCount", ConsoleColor.Red); number = Convert.ToInt32(Console.ReadLine()); switch (number) { case 1: int N = array.Sum; Console.WriteLine(N); break; case 2: OneDimArray new_array = array.Invers(); WriteBeautiful("The new array:", ConsoleColor.DarkGreen); new_array.Output(); WriteBeautiful("The old array:", ConsoleColor.DarkGreen); array.Output(); break; case 3: WriteBeautiful("Input the number to multiply:", ConsoleColor.Blue); array.Multi(Convert.ToInt32(Console.ReadLine())); array.Output(); break; case 4: WriteBeautiful($"MaxCount:{array.MaxCount}", ConsoleColor.DarkGreen); break; default: Console.WriteLine("Have a nice day!"); //TASK_6 Environment.Exit(0); break; } WriteBeautiful("To continue?(yes/no)", ConsoleColor.Blue); if (Console.ReadLine() == "yes") { key = 1; } } }
static void Main(string[] args) { #region TASK_2 , _1 TESTS int[] arr = new int[5] { 6, 2, 9, -3, 6 }; int actualValue = StaticClass.DividedByNumber(arr); int expectedValue = 2; AssertEquals(expectedValue, actualValue); int[] actual = StaticClass.ArrayFromTextFile(); int[] expected = new int[15] { 16, 123, 23, 123, 12334, 34, 5634, 123, 0, 123, 0, 343, 0, 43, 42 }; AssertEquals(actual, expected); #endregion #region TASK_3 TESTS //Class constructor test int[] expectedArray = new int[5] { 2, 5, 8, 11, 14 }; int[] actualArray = new OneDimArray(5, 2, 3).GetArr; AssertEquals(expectedArray, actualArray); expectedArray = new int[10] { 8, 6, 4, 2, 0, -2, -4, -6, -8, -10 }; actualArray = new OneDimArray(10, 8, -2).GetArr; AssertEquals(expectedArray, actualArray); // // // //INVERSE METHOD TESTS expectedArray = new int[5] { -2, -5, -8, -11, -14 }; actualArray = new OneDimArray(5, 2, 3).Inverse(); AssertEquals(expectedArray, actualArray); expectedArray = new int[10] { -8, -6, -4, -2, 0, 2, 4, 6, 8, 10 }; actualArray = new OneDimArray(10, 8, -2).Inverse(); AssertEquals(expectedArray, actualArray); // // // //MULTI METHOD TESTS expectedArray = new int[10] { 24, 18, 12, 6, 0, -6, -12, -18, -24, -30 }; actualArray = new OneDimArray(10, 8, -2).Multi(3); AssertEquals(expectedArray, actualArray); // // // //SUMMARY PROPERTY TESTS expectedValue = 40; actualValue = new OneDimArray(5, 2, 3).Summary; AssertEquals(expectedValue, actualValue); expectedValue = -10; actualValue = new OneDimArray(10, 8, -2).Summary; AssertEquals(expectedValue, actualValue); // // //CLASS DICTIONARY TEST //GET_ELEM_FREQ TEST Dictionary <int, int> testColl = new Dictionary <int, int>(4); testColl.Add(4, 1); testColl.Add(1, 1); testColl.Add(5, 1); testColl.Add(0, 1); Dictionary <int, double> expectedDict = new Dictionary <int, double>(4); expectedDict.Add(4, 0.25); expectedDict.Add(1, 0.25); expectedDict.Add(5, 0.25); expectedDict.Add(0, 0.25); Dictionary <int, double> actualDict = _Dictionary.GetElemFreq(testColl); AssertEquals(expectedDict, actualDict); #endregion #region TASK_4 Demonstration //Account.AccountCheck(Account.GetAccountDataBase()); #endregion #region TASK_5_a demonstration TwoDimArray dimArray = new TwoDimArray(2, 2); int[,] testArr = dimArray.GetArr; for (int i = 0; i < dimArray.GetStringCount; i++) { for (int j = 0; j < dimArray.GetColCount; j++) { Console.Write($"{testArr[i, j]} "); } Console.Write("\n"); } //ALL_SUMM METHOD Console.WriteLine($"{dimArray.AllSumm()}"); //MORE_THAN METHOD Console.WriteLine($"{dimArray.MoreThanSum(58000)}"); //INDEX_OF METHOD foreach (int index in dimArray.IndexOf(dimArray.GetArrMax)) { Console.Write($"[{index}], "); } #endregion }