public void EdgeTest_Null() { var A = new int[0]; int result = new ArrayLib().Max_Consecutive_Ones(A); Assert.Equal(0, result); }
/// <summary> /// Based on CPF input deletes a client. /// </summary> /// <param name="clientsArray"></param> /// <returns></returns> public static string[,] RemoveClient(string[,] clientsArray) { MenuLib.PrintSubmenu("REMOVER CLIENTE"); int clientPosition = Verifications.ReadCPF(clientsArray, "Qual o CPF do cliente que deseja remover?"); if (clientPosition != -1) { Console.Clear(); PrintClient(clientsArray, clientPosition, "Cliente que será removido:"); if (MenuLib.ConfirmationMenu("\nTem certeza que deseja deletar o cliente?")) { if (clientsArray.GetLength(0) - 1 != clientPosition) { clientsArray = ArrayLib.SwapLines(clientsArray, clientPosition, clientsArray.GetLength(0) - 1); } clientsArray = ArrayLib.RemoveLast(clientsArray); MenuLib.PrintMessage("\nO cliente foi deletado. Pressione ENTER para retornar ao menu principal:"); Console.ReadKey(); return(clientsArray); } MenuLib.PrintMessage("\nOperação cancelada.\n\n" + "Pressione ENTER para retornar ao menu principal:"); Console.ReadKey(); } return(clientsArray); }
static void Max_Consecutive_Ones() { var A = new int[7] { 1, 1, 1, 1, 0, 1, 1 }; int result = new ArrayLib().Max_Consecutive_Ones(A); }
/// <summary> /// Prints account number, name of the client and CPF. /// </summary> /// <param name="accountsArray"></param> /// <param name="clientsArray"></param> /// <param name="accountIndex"></param> public static void PrintAccountNameAndCPF(decimal[,] accountsArray, string[,] clientsArray, int accountIndex) { string cpf = CPFDecimalToString(accountsArray[accountIndex, 0]); int clientIndex = ArrayLib.Find_Binary(clientsArray, cpf, 0); Console.WriteLine("\nNúmero da conta: {0}\nNome do cliente: {1:C}\nCPF:{2}", accountsArray[accountIndex, 1], clientsArray[clientIndex, 1], ClientsLib.CPFFormat(cpf)); }
public void EdgeTest_SingleOne() { var A = new int[1] { 1 }; int result = new ArrayLib().Max_Consecutive_Ones(A); Assert.Equal(1, result); }
public void EdgeTest_AllOnes() { var A = new int[10] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; int result = new ArrayLib().Max_Consecutive_Ones(A); Assert.Equal(A.Length, result); }
public void EdgeTest_AllZeros() { var A = new int[7] { 0, 0, 0, 0, 0, 0, 0 }; int result = new ArrayLib().Max_Consecutive_Ones(A); Assert.Equal(0, result); }
public void SimpleTest_1sInMiddle_StartsAndEndsWith1s() { var A = new int[14] { 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1 }; int result = new ArrayLib().Max_Consecutive_Ones(A); Assert.Equal(5, result); }
public void SimpleTest_EndWith1s() { var A = new int[8] { 0, 1, 0, 1, 1, 1, 1, 1 }; int result = new ArrayLib().Max_Consecutive_Ones(A); Assert.Equal(5, result); }
public void SimpleTest_StartsWith1s() { var A = new int[7] { 1, 1, 1, 1, 0, 1, 1 }; int result = new ArrayLib().Max_Consecutive_Ones(A); Assert.Equal(4, result); }
/// <summary> /// Checks if CPF exists on the array. True if it does. /// </summary> /// <param name="clientsArray"></param> /// <param name="cpf"></param> /// <returns></returns> public static bool CPFAlreadyExists(string[,] clientsArray, string cpf) { if (ArrayLib.Find_Ordinary(clientsArray, cpf, 0) == -1) { return(true); } else { return(false); } }
static void Main() { int[] array1 = { 1, 8, 9, 10, 1, 30, 1, 32, 3 }; int[] array2 = { -4, -2, -3 }; int[] array3 = { -1, 1, -2 }; Console.WriteLine( String.Format("{0, 25} {1, 25} {2, 25}\n", "Method Called", "Expected Value", "Actual Value") + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "Display(array1)", "1 8 9 10 1 30 1 32 3 ", ArrayLib.Display(array1)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "Display(array2)", "-4 -2 -3 ", ArrayLib.Display(array2)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "Display(array3)", "-1 1 -2 ", ArrayLib.Display(array3)) + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "FindMax(array1)", "32", ArrayLib.FindMax(array1)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "FindMax(array2)", "-2", ArrayLib.FindMax(array2)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "FindMax(array3)", "1", ArrayLib.FindMax(array3)) + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "FindMin(array1)", "1", ArrayLib.FindMin(array1)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "FindMin(array2)", "-4", ArrayLib.FindMin(array2)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "FindMin(array3)", "-2", ArrayLib.FindMin(array3)) + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "Average(array1)", "10.5555555555556", ArrayLib.Average(array1)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "Average(array2)", "-3", ArrayLib.Average(array2)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "Average(array3)", "-0.666666666666667", ArrayLib.Average(array3)) + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "Occurs(array1, 1)", "True", ArrayLib.Occurs(array1, 1)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "Occurs(array1, 32)", "True", ArrayLib.Occurs(array1, 32)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "Occurs(array1, 2)", "False", ArrayLib.Occurs(array1, 2)) + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "FirstIndexOf(array1, 1)", "0", ArrayLib.FirstIndexOf(array1, 1)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "FirstIndexOf(array1, 32)", "7", ArrayLib.FirstIndexOf(array1, 32)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "FirstIndexOf(array1, 2)", "-1", ArrayLib.FirstIndexOf(array1, 2)) + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "LastIndexOf(array1, 1)", "6", ArrayLib.LastIndexOf(array1, 1)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "LastIndexOf(array1, 32)", "7", ArrayLib.LastIndexOf(array1, 32)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "LastIndexOf(array1, 2)", "-1", ArrayLib.LastIndexOf(array1, 2)) + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "SameSize(array1, array2)", "False", ArrayLib.SameSize(array1, array2)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "SameSize(array2, array3)", "True", ArrayLib.SameSize(array2, array3)) + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "Common(array1, array2)", "False", ArrayLib.Common(array1, array2)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "Common(array1, array3)", "True", ArrayLib.Common(array1, array3)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "Common(array2, array3)", "True", ArrayLib.Common(array2, array3)) + "-------------------------------------------------------------------------------------------\n" + String.Format("{0, 25} {1, 25} {2, 25}\n", "OccursOnce(array1, 1)", "False", ArrayLib.OccursOnce(array1, 1)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "OccursOnce(array1, 32)", "True", ArrayLib.OccursOnce(array1, 32)) + String.Format("{0, 25} {1, 25} {2, 25}\n", "OccursOnce(array1, 2)", "False", ArrayLib.OccursOnce(array1, 2)) + "-------------------------------------------------------------------------------------------\n"); }
/// <summary> /// Adds a new client. /// </summary> /// <param name="clientsArray">The string[,] that contains the clients.</param> /// <returns>The string[,] with all clients it had plus the added one, or not, if the CPF already existed.</returns> public static string[,] AddNewClient(string[,] clientsArray) { MenuLib.PrintSubmenu("ADICIONANDO NOVO CLIENTE"); int i = clientsArray.GetLength(0); clientsArray = ArrayLib.AddOneLength(clientsArray); if (ReadAndRecordCPF(clientsArray, i)) { ReadAndRecordName(clientsArray, i); clientsArray = ReadAndRecordBirthDate(clientsArray, i); return(clientsArray); } return(clientsArray); }
public void EdgeTest_LongArray() { var A = new int[10000]; int sequence = 45; for (int i = 1863; i < 1863 + sequence; i++) { A[i] = 1; } int result = new ArrayLib().Max_Consecutive_Ones(A); Assert.Equal(sequence, result); }
static void Main(string[] args) { Dictionary <int, int> diction = new Dictionary <int, int>(); ArrayClass array = new ArrayClass(15, -5, 4); array.Print(); Console.WriteLine(); Console.WriteLine($"Количество максимальных = {array.MaxCount}"); Console.WriteLine($"Сумма всех чисел = {array.Sum}"); Console.WriteLine(); ArrayClass array_2 = array.Inverse(); array_2.Print(); ArrayClass array_3 = array.Multi(5); array_3.Print(); Console.WriteLine("----------------------"); diction = array.KeyValuePa(); foreach (KeyValuePair <int, int> item in diction) { Console.WriteLine($"Key = {item.Key}, Value = {item.Value}"); } Console.WriteLine("----------------------"); //Тоже самое, но ссылаясь на библиотеку Console.WriteLine(Environment.NewLine + "Методы созданные при помощи библиотеки."); ArrayLib arrayLib = new ArrayLib(10, 15, 2); arrayLib.Print(); Console.WriteLine(); Console.WriteLine($"Количество максимальных = {arrayLib.MaxCount}"); Console.WriteLine($"Сумма всех чисел = {arrayLib.Sum}"); Console.WriteLine(); ArrayLib arrayLib_2 = arrayLib.Inverse(); arrayLib_2.Print(); ArrayLib arrayLib_3 = arrayLib.Multi(5); arrayLib_3.Print(); }
/// <summary> /// Adds a new account for the CPF input. Sets it's number to previous + 1 and balance to 50. /// </summary> /// <param name="accountsArray"></param> /// <param name="cpf"></param> /// <returns></returns> public static decimal[,] AddNewAccount(decimal[,] accountsArray, decimal cpf) { MenuLib.PrintSubmenu("CRIANDO NOVA CONTA"); if (MenuLib.ConfirmationMenu("Tem certeza que deseja criar uma nova conta?", "Criar nova conta", "Cancelar")) { int newAccountPosition = accountsArray.GetLength(0); accountsArray = ArrayLib.AddOneLength(accountsArray); accountsArray[newAccountPosition, 0] = cpf; accountsArray[newAccountPosition, 1] = accountsArray[newAccountPosition - 1, 1] + 1; accountsArray[newAccountPosition, 2] = 50; PrintAccount(accountsArray, newAccountPosition, "\nA conta foi criada com sucesso! Confira:"); MenuLib.PrintMessage("\nPressione qualquer tecla para retornar ao menu de contas."); Console.ReadKey(); } return(accountsArray); }
/// <summary> /// Removes account from input cpf. /// </summary> /// <param name="accountsArray"></param> /// <param name="cpf"></param> /// <returns></returns> public static decimal[,] RemoveAccount(decimal[,] accountsArray, decimal cpf) { MenuLib.PrintSubmenu("REMOVER CONTA"); int accountPosition = Verifications.ReadAccount(accountsArray, "Qual o número da conta a ser removida?"); if (accountPosition != -1) { if (Verifications.IsAccountFromCPF(accountsArray, accountPosition, cpf)) { Console.Clear(); PrintAccount(accountsArray, accountPosition, "Conta que será removida:"); if (Verifications.IsAccountZeroed(accountsArray, accountPosition)) { if (MenuLib.ConfirmationMenu("Tem certeza que deseja deletar a conta?")) { if (accountsArray.GetLength(0) - 1 != accountPosition) { accountsArray = ArrayLib.SwapLines(accountsArray, accountPosition, accountsArray.GetLength(0) - 1); } accountsArray = ArrayLib.RemoveLast(accountsArray); MenuLib.PrintMessage("\nA conta foi deletada. Pressione ENTER para retornar ao menu de contas:"); Console.ReadKey(); return(accountsArray); } MenuLib.PrintMessage("\nOperação cancelada pelo usuário.\n\n" + "Pressione ENTER para retornar ao menu de contas:"); Console.ReadKey(); } else { MenuLib.PrintMessage("\nA operação não pôde ser concluída pois há saldo na conta.\n" + "Primeiramente deve ser feito o saque de todo o saldo da conta.\n\n" + "Pressione ENTER para retornar ao menu de contas:"); Console.ReadKey(); } } else { MenuLib.PrintMessage("A operação não pôde ser concluída pois a conta não pertence a este CPF.\n" + "Verifique o número da conta e do CPF digitados e tente novamente.\n\n" + "Pressione ENTER para retornar ao de contas:"); Console.ReadKey(); } } return(accountsArray); }
public void TestIsBST() { // Any tree created like this should be a BST int[] turnintotree = ArrayLib.CreateArray(10); BinaryTreeNode treeHead = new BinaryTreeNode(turnintotree); Assert.IsTrue(treeHead.IsBinarySearchTree()); // add another node to mess it up BinaryTreeNode tmp = treeHead; while (tmp.Right != null) { tmp = tmp.Right; } tmp.Right = new BinaryTreeNode(-42); Assert.IsFalse(treeHead.Balanced()); }
public void TestBalanced() { // Any tree created like this should be balanced int[] turnintotree = ArrayLib.CreateArray(10); BinaryTreeNode treeHead = new BinaryTreeNode(turnintotree); Assert.IsTrue(treeHead.Balanced()); // add another node to unbalance the tree BinaryTreeNode tmp = treeHead; while (tmp.Right != null) { tmp = tmp.Right; } tmp.Right = new BinaryTreeNode(42); Assert.IsFalse(treeHead.Balanced()); }
/// <summary> /// read and record the birth date of the position i client /// </summary> /// <param name="clientsArray"></param> /// <param name="clientIndex"></param> /// <param name="message"></param> private static string[,] ReadAndRecordBirthDate(string[,] clientsArray, int clientIndex, string message) { string birthDate = Verifications.ReadBirthDate(clientsArray, message); if (!Verifications.IsClientUnderage(birthDate)) { clientsArray[clientIndex, 2] = birthDate; MenuLib.PrintMessage("Cliente adicionado com sucesso!\n" + "Pressione qualquer tecla para retornar ao Menu."); Console.ReadKey(); return(clientsArray); } else { clientsArray = ArrayLib.RemoveLast(clientsArray); MenuLib.PrintMessage("O cliente não pôde ser cadastrado por ser menor de idade.\n" + "Operação cancelada. Digite qualquer tecla para retornar ao menu principal:"); Console.ReadKey(); return(clientsArray); } }
/// <summary> /// Reads account input, if found returns position on accountsArray, if not, keeps asking until /// valid input or 0 for exit. /// </summary> /// <param name="accountsArray"></param> /// <param name="message"></param> /// <returns></returns> public static int ReadAccount(decimal[,] accountsArray, string message) { while (true) { decimal target = MenuLib.ReaddecimalValue(message); int accountPosition = ArrayLib.Find_Ordinary(accountsArray, target, 1); if (accountPosition != -1) { return(accountPosition); } else { message = ("A conta digitada não foi encontrada.\n" + "Digite uma conta válida ou entre com o valor 0 para voltar ao menu principal:"); target = MenuLib.ReaddecimalValue(message); if (target == 0) { return(-1); } } } }
/// <summary> /// Displays a message than reads CPF input. /// If it is found in the clienrsArray, returns the position, /// if not, keeps asking for another valid input, unless user types "" to leave. /// </summary> /// <param name="clientsArray"></param> /// <param name="message"></param> /// <returns></returns> public static int ReadCPF(string[,] clientsArray, string message) { string target = MenuLib.ReadStringValue(message); while (true) { int i = ArrayLib.Find_Ordinary(clientsArray, target, 0); if (i != -1) { return(i); } else { target = MenuLib.ReadStringValue("O CPF digitado não foi encontrado.\n" + "Digite um CPF válido ou tecle ENTER para voltar ao menu principal:"); if (target == "") { return(-1); } } } }
static void Main(string[] args) { string[] startMenu = new string[] { "Clientes", "Contas", "Operações", "Sair" }; StringLib.PrintAddingSpaces("SISTEMA DO BANCO"); Console.WriteLine("\nEntre com o número da opção desejada:\n"); ArrayLib.PrintMenuStyle1(startMenu); string startMenuChoice = ArrayLib.GetChoiceMenuStyle1(startMenu, Console.ReadLine()); switch (startMenuChoice) { case "Clientes": string[]clientsMenu = new string[] {"Adicionar novo cliente","Remover um cliente","} break; case "Contas": break; case "Operações": break; case "Sair": break; default: break; } Console.ReadKey(); }