static pwdCheck[] Initialize_pwd_check_object_array(Random rand) { Console.WriteLine(ASTERISK + " Initializing Heterogeneous Collection of Objects " + ASTERISK); Console.WriteLine(); const int MAX_STATE_CHANGES = 10; pwdCheck[] initializer_array = new pwdCheck[TEST_OBJ_ARRAY_SIZE]; uint random_password_length; int random_valid_ascii_index; uint max_state_changes; for (uint i = 0; i < TEST_OBJ_ARRAY_SIZE; i++) { random_password_length = (uint)rand.Next(0, RANDOM_PASSWORD_LENGTH); random_valid_ascii_index = rand.Next(0, POSSIBLE_ASCII.Length); max_state_changes = (uint)rand.Next(0, MAX_STATE_CHANGES); if (i < TEST_OBJ_ARRAY_SIZE / 3) { initializer_array[i] = new pwdCheck(random_password_length, POSSIBLE_ASCII[random_valid_ascii_index]); Console.WriteLine("Object " + i + " is a pwdCheck object."); } else if ((TEST_OBJ_ARRAY_SIZE / 3) <= i && TEST_OBJ_ARRAY_SIZE - (TEST_OBJ_ARRAY_SIZE / 3) > i) { initializer_array[i] = new excessC(random_password_length, POSSIBLE_ASCII[random_valid_ascii_index]); Console.WriteLine("Object " + i + " is an excessC object."); } else { initializer_array[i] = new compundC(max_state_changes, random_password_length, POSSIBLE_ASCII[random_valid_ascii_index]); Console.WriteLine("Object " + i + " is a compundC object."); } Console.WriteLine("Object " + i + " took in a password of length: " + random_password_length); Console.WriteLine("After construction, object " + i + " has a password length requirement of: " + initializer_array[i].Minimum_Password_Length); Console.WriteLine("Object " + i + " has a forbidden character: " + POSSIBLE_ASCII[random_valid_ascii_index]); Console.WriteLine(); } return(initializer_array); }
static void Test_Both_ExcessC_States(Random rand, pwdCheck[] pwd_check_object_array) { Console.WriteLine(ASTERISK + " Specific test tailored to testing excessC's on and off functionality " + ASTERISK); Console.WriteLine(); uint random_password_length; int random_valid_ascii_index; char forbidden_char; string password; Console.WriteLine("First, we will test excessC functions in their off state and they will have the \n" + "same functionality as pwdCheck"); Console.WriteLine(); for (uint i = EXCESSC_TEST_OBJ; i < COMPUND_TEST_OBJ; i++) { random_password_length = (uint)rand.Next(0, RANDOM_PASSWORD_LENGTH); random_valid_ascii_index = rand.Next(0, POSSIBLE_ASCII.Length); password = ""; pwd_check_object_array[i] = new excessC(random_password_length, POSSIBLE_ASCII[random_valid_ascii_index]); forbidden_char = POSSIBLE_ASCII[random_valid_ascii_index]; for (uint j = 0; j < random_password_length; j++) { random_valid_ascii_index = rand.Next(0, POSSIBLE_ASCII.Length); password += POSSIBLE_ASCII[random_valid_ascii_index]; } if (i == EXCESSC_TEST_OBJ) { password = CUSTOM_EXCESSC_PWD; } Console.WriteLine("The random password generated for object " + i + " is: " + password); Console.WriteLine("The minimum length requirement for passwords in object " + i + " is: " + pwd_check_object_array[i].Minimum_Password_Length); if (pwd_check_object_array[i].Password_Check(password)) { Console.WriteLine("The entered password is acceptable"); } else { Console.WriteLine("The entered password does not meet the requirements"); } Console.WriteLine("The actual length of the password entered in object " + i + " is: " + pwd_check_object_array[i].Password_Length); Console.WriteLine("Object " + i + " has a forbidden character: " + forbidden_char); Console.WriteLine("Is the object on?: " + pwd_check_object_array[i].isActive); Console.WriteLine(); } Console.WriteLine("Second, we will test excessC functions in their on state which they are in by default"); Console.WriteLine(); Console.WriteLine("Entering passwords to force each excessC object to change state."); Console.WriteLine(); for (uint i = 0; i < MAX_PWD_LENGTH_REQUIRMENT; i++) { random_password_length = (uint)rand.Next(0, RANDOM_PASSWORD_LENGTH); password = ""; for (uint j = 0; j < random_password_length; j++) { random_valid_ascii_index = rand.Next(0, POSSIBLE_ASCII.Length); password += POSSIBLE_ASCII[random_valid_ascii_index]; } for (uint j = EXCESSC_TEST_OBJ; j < COMPUND_TEST_OBJ; j++) { if (i < pwd_check_object_array[j].Minimum_Password_Length + 1) { pwd_check_object_array[j].Password_Check(password); } } } for (uint i = EXCESSC_TEST_OBJ; i < COMPUND_TEST_OBJ; i++) { random_password_length = (uint)rand.Next(0, RANDOM_PASSWORD_LENGTH); password = ""; for (uint j = 0; j < random_password_length; j++) { random_valid_ascii_index = rand.Next(0, POSSIBLE_ASCII.Length); password += POSSIBLE_ASCII[random_valid_ascii_index]; } if (i == EXCESSC_TEST_OBJ) { password = CUSTOM_EXCESSC_PWD; } Console.WriteLine("The random password generated for object " + i + " is: " + password); Console.WriteLine("The minimum length requirement for passwords in object " + i + " is: " + pwd_check_object_array[i].Minimum_Password_Length); if (pwd_check_object_array[i].Password_Check(password)) { Console.WriteLine("The entered password is acceptable"); } else { Console.WriteLine("The entered password does not meet the requirements"); } Console.WriteLine("The actual length of the password entered in object " + i + " is: " + pwd_check_object_array[i].Password_Length); Console.WriteLine("Is the object on?: " + pwd_check_object_array[i].isActive); Console.WriteLine(); } Console.WriteLine("Press enter to continue..."); Console.ReadLine(); }