Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Name: Anastasia Belenkii
- Course: COMSC-110-1021
- 1. Objective: Extract email addresses from a file and output them to console
- 2. Requirements
- INPUT:
- iFile
- keepGoing
- enterKey
- oFile
- line
- PROCESSING:(list of the major parts of the objective [that will become the code blocks in a program])
- 1. introduction and directions
- 2. get input and output files from user, output filenames back to user and wait for confirmation before proceeding
- 3. open input file, search for valid email addresses, if not duplicate then output them and add to list
- OUTPUT:
- dFile
- prompt1
- prompt2
- label1
- iFile
- label2
- oFile
- prompt3
- anEmail
- emptymsg
- size of list email
- nonevalidmsg
- goodbyemsg
- DATA: (name of data item, definition, data type, valid values...)
- iFile-> name of input file [string] [any string]
- dFile->default filename for input or output [string] ["fileContainingEmails.txt", iFile, or "copyPasteMyEmails.txt"]
- oFile-> name of output file [string] [any string]
- enterKey-> whether the enter key was pressed at a prompt or not [true/false]
- keepGoing-> input to determine whether program was unpaused or not [string] [any string]
- line-> each line of the input file [string] [any string]
- i-> loop index for going over each character in line [whole number] [any whole number greater than 0]
- empty->whether the input FILE has '@'s or not [true/false]
- hasDot = false; //whether the substring(subset of string) has a dot or not [true/false]
- s->the index for going to the start of the substring [whole number] [any whole number that is at most 1 less than i]
- e->the index for going to the end of the substring [whole number] [any whole number that is at least 1 + i]
- anEmail->an email that has been detected [string] [any string composed of valid email characters, with a dot that at least one character between it and an @]
- dotPos->position of dot [whole number] [any whole number greater than 0]
- is->whether a given character is a valid email character
- email->list of emails [list of strings] [members must be valid emails, no duplicates]
- m->
- n->
- temp->
- prompt1: "Please enter the name of the input file. [Leave blank for '...']: "
- prompt2: "Please enter the name of the output file. [Leave blank for '...']: "
- prompt3: "Press ENTER to continue. Any other key (+ enter) quits."
- label1: "input filename:"
- label2: "output filename:"
- label3: "Number of emails:"
- emptymsg: "I'm sorry, your input file is empty"
- nonevalidmsg: "There are no valid email addresses in your input file."
- goodbyemsg: Thanks for using this program. Have a great day!
- SUBPROGRAMS:
- ***subprogram isValidEmailchar
- Objective: test a character and see if it's a valid email character
- DATA: [INPUT] c->character being checked [single character]
- [OUTPUT] result->whether c is valid or not [true/false]
- ***subprogram isDup
- Objective: check if an email is equal to any of the emails in the list
- DATA: [INPUT] subject->string being tested [string] [any string]
- [OUTPUT] result->whether subject is a duplicate or not [true/false]
- k->loop index [whole number] [any whole number > 0]
- ***subprogram lower
- Objective: take each character in a string and put lowercase version of it in 'out'
- DATA: [INPUT] given->the string to be made lowercase [string] [any string]
- [OUTPUT] out->the lowercase version of given [any string]
- h->loop index. Not using k because lower gets called from isDup. This way, value of k is preserved. [whole number] [any whole number > 0]
- 3. Instructions
- ***subprogram isValidEmailchar
- 1000 set result = false
- 1010 if c is between A-Z, a-z, 0-9, or is _, +, -, or ., set result = true
- 1020 return result to program that called
- 1030 return to program that called
- ***subprogram isDup
- 2000 set result = false
- 2010 set k = 0
- 2015 if k = size of 'email', skip to instruction 2060
- 2020 call subprogram lower on subject
- 2030 call subprogram lower on member of email at position k
- 2040 if 'out' from call to lower on subject == 'out' from call to lower on email_k, set result = true
- 2050 k = k + 1
- 2055 skip to instruction 2015
- 2060 return result to program that called
- 2070 return to program that called
- ***subprogram lower
- 3000 set out = given
- 3010 set h = 0
- 3015 if h = length of given, skip to instruction 3040
- 3020 character at position h in out = lowercase version of given_h
- 3030 h = h + 1
- 3035 skip to instruction 3015
- 3040 return out to program that called
- 3050 return to to program that called
- ***MAIN PROGRAM
- 10 output Introduction
- 20 output directions
- 30 dFile = "fileContainingEmails.txt"
- 40 enterKey = false
- 45 set empty = true
- 50 output prompt1, dFile
- 60 input iFile
- 70 if length of iFile = 0, then set enterKey = true
- 80 if enterKey = true, then iFile = dFile
- 90 if enterKey = true, skip to instruction 120
- 100 dFile = iFile
- 110 skip to instruction 130
- 120 dFile = "copyPasteMyEmails.txt"
- 130 output prompt2, dFile
- 140 input oFile
- 150 enterKey = false;
- 160 if length of oFile is 0, then enterKey = true
- 170 if enter key is true, then oFile = dFile
- 180 output label for the input file name, and iFile
- 190 output label for the output file name, and oFile
- 200 output prompt3
- 210 input keepGoing
- 220 if length of keepGoing > 0, skip to instruction 995
- 230 open iFile
- 240 if there are no problems with iFile, skip to instruction 270
- 250 send error message to OS
- 260 skip to instruction 999
- 270 if there are problems with iFile or iFile has ended, skip to instruction 570
- 280 set line = current line of iFile
- 290 if length of line = 0 skip to instruction 550
- 300 set i = 0
- 310 set empty = false
- 320 if i = length of line, skip to instruction 550
- 330 if character at position i in line not '@', skip to instruction 530
- 350 set s = (i - 1)
- 360 set e = (i + 1)
- 370 if s < 0 skip to instruction 410
- 375 call subprogram isValidEmailchar on character at position s in line
- 380 if result = false skip to instruction 410
- 390 set s = s - 1
- 400 skip to instruction 370
- 410 if e = the length of line, skip to instruction 470
- 412 call subprogram isValidEmailchar on character at position s in line
- 420 if result = false, skip to instruction 470
- 430 if character at position in line != '.' skip to instruction 460
- 440 set hasDot = true
- 450 dotPos = e
- 460 set e = e + 1
- 465 skip to instruction 410
- 470 set s = s + 1
- 475 if the following is FALSE, skip to instruction 510: (s < i) and (e > i) and (hasDot is true) and (dotPos > 1)
- 480 anEmail = the text between s and e
- 490 call isDup on anEmail
- 500 if result = true skip to instruction 530
- 510 output anEmail
- 520 add anEmail to list email
- 530 set i = i + 1
- 540 skip to instruction 320
- 550 move to next line
- 560 skip to instruction 270
- 570 if empty = false, skip to instruction 590
- 580 output emptymsg
- 590 if the size of list emails > 0, skip to instruction 620
- 600 output nonevalidmsg
- 610 skip to instruction 995
- 620 set m = 0
- 630 if m equals size of list email, skip to instruction 760
- 640 set n = m + 1
- 650 if n = size of list email, skip to instruction 740
- 660 call subprogram lower on email_m
- 670 call subprogram lower on email_n
- 680 if 'out' from lower on email_m <= 'out' from lower on email_n, skip to instruction 720
- 690 set temp = email_m
- 700 set email_m=email_n
- 710 set email_n = temp
- 720 set n = n + 1
- 730 skip to instruction 650
- 740 set m = m + 1
- 750 skip to instruction 630
- 760 open oFile
- 770 set i = 0
- 780 if i = size of list email, skip to instruction
- 790 output email_i
- ....(finish writing output loop basically)
- ... output label3 and size of list email
- 995 output goodbyemsg
- 999 END
- 4. Test Cases
- (THERE ARE MORE TEST CASES NOW... I THINK)
- *****Test Case#1: very simple, unproblematic usage
- *What is being tested: simple- one line has two '@', another line has one '@'
- *Input values if any:
- iFile = 'test.txt'
- CONTENTS:
- abc@123.com
- oFile = '\n'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'test.txt']:
- -input filename: test.txt
- -output filename: test.txt
- -Press ENTER to continue. Any other key (+ enter) quits.
- -abc@123.com
- -number of emails: 1
- -Thanks for using this program. Have a great day!
- *Test:
- 10 Introduction
- 20 directions
- 30 dFile = "fileContainingEmails.txt"
- 40 enterKey = false
- 45 empty = true
- 50 prompt1, dFile
- 60 iFile = test.txt
- 100 dFile = iFile
- 110 skip to instruction 130
- 130 prompt2, dFile
- 140 oFile = '\n'
- 150 enterKey = false;
- 160 enterKey = true
- 170 oFile = dFile
- 180 label1, iFile
- 190 label2, oFile
- 200 output a prompt to press ENTER key to continue
- 210 keepGoing = '\n'
- 270 if there are problems with iFile or iFile has ended, skip to instruction 995
- 280 line = abc@123.com
- 300 i = 0
- 310 empty = false
- 330 skip to instruction 510
- 510 i= 0 + 1 = 1
- 520 skip to instruction 320
- 330 skip to instruction 510
- 510 i = 1 + 1 = 2
- 520 skip to instruction 320
- 330 skip to instruction 510
- 510 i = 2 + 1 = 3
- 520 skip to instruction 320
- 340 hasAt = 0 + 1 = 1
- 350 s = 3 - 1 = 2
- 360 e = 3 + 1 = 4
- 375 call isDup on line_2 ('c')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 390 s = 2 - 1 = 1
- 400 skip to instruction 370
- 375 call isDup on line_1 ('b')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 390 s = 1 - 1 = 0
- 400 skip to instruction 370
- 375 call isDup on line_0 ('a')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 390 s = 0 - 1 = -1
- 400 skip to instruction 370
- 370 skip to instruction 410
- 412 call isValidEmailchar on line_4 ('1')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 430 skip to instruction 460
- 460 e = 4 + 1 = 5
- 465 skip to instruction 410
- 412 call isValidEmailchar on line_5 ('2')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 430 skip to instruction 460
- 460 e = 5 + 1 = 6
- 465 skip to instruction 410
- 412 call isValidEmailchar on line_6 ('3')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 430 skip to instruction 460
- 460 e = 6 + 1 = 7
- 465 skip to instruction 410
- 412 call isValidEmailchar on line_7 ('.')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 440 hasDot = true
- 450 dotPos = 7
- 460 e = 7 + 1 = 8
- 465 skip to instruction 410
- 412 call isValidEmailchar on line_8 ('c')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 430 skip to instruction 460
- 460 e = 8 + 1 = 9
- 465 skip to instruction 410
- 412 call isValidEmailchar on line_9 ('o')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 430 skip to instruction 460
- 460 e = 9 + 1 = 10
- 465 skip to instruction 410
- 412 call isValidEmailchar on line_10 ('m')
- 1000 result = false
- 1010 result = true
- 1020 return result to main program
- 430 skip to instruction 460
- 460 e = 10 + 1 = 11
- 465 skip to instruction 410
- 410 skip to instruction 470
- 470 s = -1 + 1 = 0
- 480 anEmail = text between 0 and 11- abc@123.com
- 490 call isDup on abc@123.com
- 2000 result = false
- 2010 k = 0
- 2015 skip to instruction 2060
- 2060 return false to main program
- 510 abc@123.com
- 520 email_0 = abc@123.com
- 530 i = 3 + 1 = 4
- 540 skip to instruction 320
- 330 skip to instruction 530
- 510 i = 4 + 1 = 5
- 520 skip to instruction 320
- 330 skip to instruction 530
- 510 i = 5 + 1 = 6
- 520 skip to instruction 320
- 330 skip to instruction 530
- 510 i = 6 + 1 = 7
- 520 skip to instruction 320
- 330 skip to instruction 530
- 510 i = 7 + 1 = 8
- 520 skip to instruction 320
- 330 skip to instruction 530
- 510 i = 8 + 1 = 9
- 520 skip to instruction 320
- 330 skip to instruction 530
- 510 i = 9 + 1 = 10
- 520 skip to instruction 320
- 330 skip to instruction 530
- 510 i = 10 + 1 = 11
- 320 skip to instruction 550
- 560 skip to instruction 270
- 270 skip to instruction 570
- 570 skip to instruction 590
- 590 skip to instruction 620
- 620 label3, 1
- 995 goodbyemsg
- 999 END
- *****Test Case#2: both defaults
- *What is being tested: user only enters ENTER key, no custom values (then quits program execution)
- *Input values if any:
- iFile = '\n'
- oFile = '\n'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'copyPasteMyEmails.txt']:
- -input filename: fileContainingEmails.txt
- -output filename: copyPasteMyEmails.txt
- -Press ENTER to continue. Any other key (+ enter) quits.
- -Thanks for using this program. Have a great day!
- *****Test Case#3: custom input filename
- *What is being tested: user wants different input file from default, and uses the same file for output
- *Input values if any:
- iFile = 'x.txt'
- CONTENTS:
- abc@123.com
- oFile = '\n'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'x.txt']:
- -input filename: x.txt
- -output filename: x.txt
- -Press ENTER to continue.
- -abc@123.com
- -number of emails: 1
- -Thanks for using this program. Have a great day!
- *****Test Case#4: custom output filename
- *What is being tested: user wants different output file from default, and uses the same file for output
- *Input values if any:
- iFile = '\n'
- CONTENTS [fileContainingEmails.txt] :
- abc@123.com
- oFile = 'y.txt'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'copyPasteMyEmails.txt']:
- -input filename: fileContainingEmails.txt
- -output filename: y.txt
- -Press ENTER to continue.
- -abc@123.com
- -number of emails: 1
- -Thanks for using this program. Have a great day!
- *****Test Case#5: both custom filenames
- *What is being tested: user wants different input AND out file from default
- *Input values if any:
- iFile = 'x.txt'
- CONTENTS:
- abc@123.com
- oFile = 'y.txt'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'x.txt']:
- -input filename: x.txt
- -output filename: y.txt
- -Press ENTER to continue.
- -abc@123.com
- -number of emails: 1
- -Thanks for using this program. Have a great day!
- *****Test Case#6: user wants to quit (change filenames)
- *What is being tested: user makes a mistake with output filename
- *Input values if any:
- iFile = 'test.txt'
- CONTENTS:
- @@
- \n
- @
- oFile = reddit.com
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'test.txt']:
- -input filename: test.txt
- -output filename: reddit.com
- -Press ENTER to continue. Any other key (+ enter) quits.
- -Thanks for using this program. Have a great day!
- *****Test Case#7: user makes filename mistake and doesn't fix it
- *What is being tested: user makes a mistake with input filename
- *Input values if any:
- iFile = reddit.com
- oFile = '\n'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'reddit.com']:
- -input filename: reddit.com
- -output filename: reddit.com
- -Press ENTER to continue. Any other key (+ enter) quits.
- -error message sent to OS
- -program failure
- *****Test Case#8: file contains no emails
- *What is being tested: input file just has non-email text
- *Input values if any:
- iFile = 'test1.txt'
- CONTENTS:
- at at
- \n
- at
- oFile = '\n'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'test1.txt']:
- -input filename: test1.txt
- -output filename: test1.txt
- -Press ENTER to continue. Any other key (+ enter) quits.
- -Your input file contains no emails.
- -Thanks for using this program. Have a great day!
- *****Test Case #9: file is empty
- *What is being tested: nothing in input file- no characters, only end of file marker (if applicable)
- *Input values if any:
- iFile = 'test2.txt'
- CONTENTS:
- oFile = '\n'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'test2.txt']:
- -input filename: test2.txt
- -output filename: test2.txt
- -Press ENTER to continue. Any other key (+ enter) quits.
- -I'm sorry, your input file is empty
- -Thanks for using this program. Have a great day!
- ******Test Case #10: input file has multiple duplicate emails
- *What is being tested: ability to distinguish exact duplicates
- *Input values if any:
- iFile = 'test3.txt'
- CONTENTS:
- abc@123.com
- abc@123.com
- oFile = '\n'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'test3.txt']:
- -input filename: test3.txt
- -output filename: test3.txt
- -Press ENTER to continue. Any other key (+ enter) quits.
- -abc@123.com
- -number of emails: 1
- -Thanks for using this program. Have a great day!
- ******Test Case #11: input file has the same email more than once, but cased differently
- *What is being tested: ability to distinguish cases
- *Input values if any:
- iFile = 'test4.txt'
- CONTENTS:
- abc@123.com
- ABC@123.com
- abc@123.com
- oFile = '\n'
- *Expected result:
- -Introduction
- -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
- -Please enter the name of the output file. [Leave blank for 'test4.txt']:
- -input filename: test4.txt
- -output filename: test4.txt
- -Press ENTER to continue. Any other key (+ enter) quits.
- -abc@123.com
- -number of emails: 1
- -Thanks for using this program. Have a great day!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement