is Valid Phone Number(): ReturnsTrue if the provided phone number (represented as a string) is cor-rectly formatted, otherwiseFalse. To be considered correctly formatted, phone numbers must bewritten as###-###-####, where#is a digit between 0 and 9 .•validatePhoneBook(): A phone book is a list where each entry is a phone book record (represented asa dictionary; see below for more details). This function checks each phone book record in the phonebook for correctly formatted phone numbers.A phone book record is a dictionary which initially has two keys: the key"name"mapped to thecontact’s name (string) and the key"phone number"mapped to that contact’s phone number (alsoa string).validatePhoneBook()adds a new key"valid"to the record with the valueTrueif the phonenumber is formatted correctly, otherwiseFalse.   1. Write white-box and black-box tests for the function is ValidPhoneNumber(). You should do this with-out Python, either on paper, or in a simple document. Don’t worry about running your tests until youhave thought about which test cases you want. Make sure you haveat least3 black-box tests and 3white-box tests. More tests may be useful. 2.Implement a test driver using your test cases in a document name 9q2_testing.  3. Run your tests and copy/paste the console output to a document named a9q2_output.txt. Theconsole output you hand in should come from the program before you try to fix it! 4.try to deduce the problems with the isValidPhoneNumber() function from the output of your testing.Then fixx the error(s) in the function! 5. In the document a9q2_output.txt, describe the error(s) you found and how you fixed it (them). Youdo not need to write a lot; a sentence or two for each error is all we want. Write your explanation as if you are explaining the error to a colleague of yours who wrote the functions. 6. Repeat the above steps for the second functionvalidatePhoneBook(). The 9q2_testing is below.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

•is Valid Phone Number(): ReturnsTrue if the provided phone number (represented as a string) is cor-rectly formatted, otherwiseFalse. To be considered correctly formatted, phone numbers must bewritten as###-###-####, where#is a digit between 0 and 9

.•validatePhoneBook(): A phone book is a list where each entry is a phone book record (represented asa dictionary; see below for more details). This function checks each phone book record in the phonebook for correctly formatted phone numbers.A phone book record is a dictionary which initially has two keys: the key"name"mapped to thecontact’s name (string) and the key"phone number"mapped to that contact’s phone number (alsoa string).validatePhoneBook()adds a new key"valid"to the record with the valueTrueif the phonenumber is formatted correctly, otherwiseFalse.

 

1. Write white-box and black-box tests for the function is ValidPhoneNumber(). You should do this with-out Python, either on paper, or in a simple document. Don’t worry about running your tests until youhave thought about which test cases you want. Make sure you haveat least3 black-box tests and 3white-box tests. More tests may be useful.

2.Implement a test driver using your test cases in a document name 9q2_testing. 

3. Run your tests and copy/paste the console output to a document named a9q2_output.txt. Theconsole output you hand in should come from the program before you try to fix it!

4.try to deduce the problems with the isValidPhoneNumber() function from the output of your testing.Then fixx the error(s) in the function!

5. In the document a9q2_output.txt, describe the error(s) you found and how you fixed it (them). Youdo not need to write a lot; a sentence or two for each error is all we want. Write your explanation as if you are explaining the error to a colleague of yours who wrote the functions.

6. Repeat the above steps for the second functionvalidatePhoneBook().

The 9q2_testing is below.

def 1svalidPhoneNumber (number):
Verifies whether the provided phone number is correctly formatted - should be
formatted
as #-#-## where # can be any digit from 8-9.
:param number: phone number (stored as a string)
:return: True if the phone number string is correctly formatted, otherwise
False
# Check the length requirement
if len(number) - 1 != 12:
return False
# Check if the dashes are in the right spot
if number [3] !- '-' and number [7] !- '-':
return False
# Check if non - dash characters are digits in the set "0"
for i in [1,2,4,5, 6,7,8,9, 10]:
if number [1] not in ["o", "1", "2", "3", "4", "5", "6", "7", "8", "9"]:
return False
"9"
return True
def validatePhoneBook (phone_book):
Verifies whether every phone book record (dictionary) in a phone book (list)
has a correct ly
formatted phone number
Adds a new key "valid" to each phone book record with the value True if that
record's phone
number 15 correct ly formatted, otherwise False
:param phone_book: A list of phone book dictionary records, where each record
has the key "name"
mapped to a string and "phone number" mapped to a string
for record in phone_hook:
numher = record["phone number"]
if not isvalidPhoneNumber (number):
record["valid"] = True
else:
record["valid"] - False
# a sample phone book BEFORE validatePhoneBook() is called on it:
# [ { "name" : "Depar tment of Computer Science",
"phone number" : "306-966-4886" },
{ "name" : "Depar tment of History",
"phone number" : "306.966.8712" },
{ "name" : "Department of Psychology",
"phone number" : "(306) 966- 6657" }
%#3
%23
%23
%23
# 1
Transcribed Image Text:def 1svalidPhoneNumber (number): Verifies whether the provided phone number is correctly formatted - should be formatted as #-#-## where # can be any digit from 8-9. :param number: phone number (stored as a string) :return: True if the phone number string is correctly formatted, otherwise False # Check the length requirement if len(number) - 1 != 12: return False # Check if the dashes are in the right spot if number [3] !- '-' and number [7] !- '-': return False # Check if non - dash characters are digits in the set "0" for i in [1,2,4,5, 6,7,8,9, 10]: if number [1] not in ["o", "1", "2", "3", "4", "5", "6", "7", "8", "9"]: return False "9" return True def validatePhoneBook (phone_book): Verifies whether every phone book record (dictionary) in a phone book (list) has a correct ly formatted phone number Adds a new key "valid" to each phone book record with the value True if that record's phone number 15 correct ly formatted, otherwise False :param phone_book: A list of phone book dictionary records, where each record has the key "name" mapped to a string and "phone number" mapped to a string for record in phone_hook: numher = record["phone number"] if not isvalidPhoneNumber (number): record["valid"] = True else: record["valid"] - False # a sample phone book BEFORE validatePhoneBook() is called on it: # [ { "name" : "Depar tment of Computer Science", "phone number" : "306-966-4886" }, { "name" : "Depar tment of History", "phone number" : "306.966.8712" }, { "name" : "Department of Psychology", "phone number" : "(306) 966- 6657" } %#3 %23 %23 %23 # 1
# the same sample phone book AFTER validatePhoneBook () is called on it, assuming
all errors have been corrected:
# [ { "name" : "Department of Computer science",
"phone number" : "306-966-4886",
"valid" : True ),
{ "name" : "Department of History",
"phone number" : "306.966.8712",
"valid" : False },
{ "name" : "Depar tment of Psychology",
"phone number" : "(306) 966-6657",
"valid" : False }
23
23
#3
23
#3
%23
Transcribed Image Text:# the same sample phone book AFTER validatePhoneBook () is called on it, assuming all errors have been corrected: # [ { "name" : "Department of Computer science", "phone number" : "306-966-4886", "valid" : True ), { "name" : "Department of History", "phone number" : "306.966.8712", "valid" : False }, { "name" : "Depar tment of Psychology", "phone number" : "(306) 966-6657", "valid" : False } 23 23 #3 23 #3 %23
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT