Question

C# Please Write Unit tests for a boolean method validateStudentID() that accepts a string. It validates...

C# Please

Write Unit tests for a boolean method validateStudentID() that accepts a string. It validates a DMACC 900 number. Then write the code to make the tests pass.

Test 1. A valid 900 as input (method returns true)

Test 2. An invalid 900 number -- does not start with 9  (method returns false)

Test 3. An invalid 900 number -- second character is not zero (method returns false)

Test 4. An invalid 900 number -- contains digits  (method returns false)

Write your method so all tests will pass. You should not need to change your Unit Tests unless you made an error in them. Likely, the change will be adding logic to your method.

Homework Answers

Answer #1

Question : -

Solution :-

public bool validateStudentID(string DMACC)
{
int number;
int.TryParse(DMACC, out number); //convert string to int
int[] nums = new int[900]; //array to store digits of number .

int i = 0; // initialization of i variable which is used for iteration.
// while loop to fill array and get reverse digit.
while (number != 0)
{
nums[i] = number % 10;
number = number / 10;
i++;

}
// to place digit in proper place
Array.Reverse(nums);

//Test 2. An invalid 900 number -- does not start with 9 (method returns false)
if (nums[0] == 9)
{
  
return false;
}

// Test 3.An invalid 900 number-- second character is not zero (method returns false)
if (nums[1] == 0)
{
  
return false;
}

// Test 4.An invalid 900 number-- contains digits(method returns false)
if (isNumber(DMACC))
{

return false;
}
return true; //otherwise .. A valid 900 as input (method returns true)
}
//method to check String contain any digit / number or not and this method is used to solve Test 4
public static bool isNumber(string str)
{
bool status = str.Where(y => Char.IsDigit(y)).Any();
return status;
}

Snapshots: -

code:-

output : -

there is specific output on console because of I'm not using that method .but it clearly indicate that code doesn't contain any error. i.e. 0 error ,0 warnings.

thank you ..?!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a method called countChar which accepts a string parameter and a character parameter and returns...
Write a method called countChar which accepts a string parameter and a character parameter and returns an integer, that is: int countChar (String s, char c) This method should count the number of occurrences of the character c within the string s, and return the count to the caller. Also write a main method that tests countChar. All of the print statements and user interaction belong in the main method, not in countChar.
C++ only: Please implement a function that accepts a string parameter as well as two character...
C++ only: Please implement a function that accepts a string parameter as well as two character arguments and a boolean parameter. Your function should return the number of times it finds the character arguments inside the string parameter. When both of the passed character arguments are found in the string parameter, set the boolean argument to true. Otherwise, set that boolean argument to false. Return -1 if the string argument is the empty string. The declaration for this function will...
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as...
Write a recursive method repeatNTimes(String s, int n) that accepts a String and an integer as two parameters and returns a string that is concatenated together n times. (For example, repeatNTimes ("hello", 3) returns "hellohellohello") Write a driver program that calls this method from the Main program. Program should ask for input and be stored in the string and should return n amount of times.
Write code in C++, using the correct headers not the catchall std/bitsc: Write a recursive, bool-valued...
Write code in C++, using the correct headers not the catchall std/bitsc: Write a recursive, bool-valued function, containsVowel, that accepts a string and returns true if the string contains a vowel. A string contains a vowel if: The first character of the string is a vowel, or The rest of the string (beyond the first character) contains a vowel it should be making use of true/false as it is a boolean, substr(), find, and !=.
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
Please code in Java Write a recursive method that takes a string and return a string...
Please code in Java Write a recursive method that takes a string and return a string where every character appears twice. For example, if the string is “HELLO”, it will return “HHEELLOO”. Write a program to test it.
Write a PHP script that tests whether an e-mail address is input correctly. Verify that the...
Write a PHP script that tests whether an e-mail address is input correctly. Verify that the input begins with series of characters, followed by the @ character, another series of characters, a perod (.) and a final series of characters. Test your program, using both valid and invalid e-mail address. Please make sure it outputs valid or invalid address
Write a Java method that takes a String as Input and replaces the first two occurrencesof...
Write a Java method that takes a String as Input and replaces the first two occurrencesof a given character to another provided character.   For example, if the input String is “Java is Great” and asked to replace the letter a with x then the output would be: “Jxvx is Great” The method takes a String and two characters and returns the modified String. Please make your own assumptions if needed, you do not need to write the main.
Write a method public static boolean isPalindrome(String input) that uses one or more stacks to determine...
Write a method public static boolean isPalindrome(String input) that uses one or more stacks to determine if a given string is a palindrome. [A palindrome is a string that reads the same forwards and backwards, for example ‘racecar’, ‘civic’]. Make sure that your method works correctly for special cases, if any. (b) What is the big-O complexity of your method in terms of the list size n.
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT