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 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 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.
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 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...
This is C. Please write it C. 1) Prompt the user to enter a string of...
This is C. Please write it C. 1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be...
WITH JAVA Follow the instructions in the attached to complete Task#2 and submit work along with...
WITH JAVA Follow the instructions in the attached to complete Task#2 and submit work along with screenshots of your output. I have attached the class code for Task#1 that you can use while completing Task#2. Task#1 CODE /** SocSecException exception class */ public class SocSecException extends Exception { public SocSecException(String error) { super("Invalid the social security number, " + error); } } Task #2 Writing Code to Handle an Exception 1. In the main method: a. The main method should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT