Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.82 KB | None | 0 0
  1. Name: Anastasia Belenkii
  2. Course: COMSC-110-1021
  3.  
  4. 1. Objective: Extract email addresses from a file and output them to console
  5.  
  6. 2. Requirements
  7. INPUT:
  8. iFile
  9. keepGoing
  10. enterKey
  11. oFile
  12. line
  13.  
  14. PROCESSING:(list of the major parts of the objective [that will become the code blocks in a program])
  15. 1. introduction and directions
  16. 2. get input and output files from user, output filenames back to user and wait for confirmation before proceeding
  17. 3. open input file, search for valid email addresses, if not duplicate then output them and add to list
  18.  
  19. OUTPUT:
  20. dFile
  21. prompt1
  22. prompt2
  23. label1
  24. iFile
  25. label2
  26. oFile
  27. prompt3
  28. anEmail
  29. emptymsg
  30. size of list email
  31. nonevalidmsg
  32. goodbyemsg
  33.  
  34. DATA: (name of data item, definition, data type, valid values...)
  35. iFile-> name of input file [string] [any string]
  36. dFile->default filename for input or output [string] ["fileContainingEmails.txt", iFile, or "copyPasteMyEmails.txt"]
  37. oFile-> name of output file [string] [any string]
  38. enterKey-> whether the enter key was pressed at a prompt or not [true/false]
  39. keepGoing-> input to determine whether program was unpaused or not [string] [any string]
  40. line-> each line of the input file [string] [any string]
  41. i-> loop index for going over each character in line [whole number] [any whole number greater than 0]
  42. empty->whether the input FILE has '@'s or not [true/false]
  43. hasDot = false; //whether the substring(subset of string) has a dot or not [true/false]
  44. s->the index for going to the start of the substring [whole number] [any whole number that is at most 1 less than i]
  45. e->the index for going to the end of the substring [whole number] [any whole number that is at least 1 + i]
  46. 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 @]
  47. dotPos->position of dot [whole number] [any whole number greater than 0]
  48. is->whether a given character is a valid email character
  49. email->list of emails [list of strings] [members must be valid emails, no duplicates]
  50. m->
  51. n->
  52. temp->
  53.  
  54. prompt1: "Please enter the name of the input file. [Leave blank for '...']: "
  55. prompt2: "Please enter the name of the output file. [Leave blank for '...']: "
  56. prompt3: "Press ENTER to continue. Any other key (+ enter) quits."
  57. label1: "input filename:"
  58. label2: "output filename:"
  59. label3: "Number of emails:"
  60. emptymsg: "I'm sorry, your input file is empty"
  61. nonevalidmsg: "There are no valid email addresses in your input file."
  62. goodbyemsg: Thanks for using this program. Have a great day!
  63.  
  64. SUBPROGRAMS:
  65.  
  66. ***subprogram isValidEmailchar
  67. Objective: test a character and see if it's a valid email character
  68. DATA: [INPUT] c->character being checked [single character]
  69. [OUTPUT] result->whether c is valid or not [true/false]
  70.  
  71. ***subprogram isDup
  72. Objective: check if an email is equal to any of the emails in the list
  73. DATA: [INPUT] subject->string being tested [string] [any string]
  74. [OUTPUT] result->whether subject is a duplicate or not [true/false]
  75. k->loop index [whole number] [any whole number > 0]
  76.  
  77. ***subprogram lower
  78. Objective: take each character in a string and put lowercase version of it in 'out'
  79. DATA: [INPUT] given->the string to be made lowercase [string] [any string]
  80. [OUTPUT] out->the lowercase version of given [any string]
  81. 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]
  82.  
  83.  
  84. 3. Instructions
  85.  
  86. ***subprogram isValidEmailchar
  87. 1000 set result = false
  88. 1010 if c is between A-Z, a-z, 0-9, or is _, +, -, or ., set result = true
  89. 1020 return result to program that called
  90. 1030 return to program that called
  91.  
  92.  
  93.  
  94. ***subprogram isDup
  95. 2000 set result = false
  96. 2010 set k = 0
  97. 2015 if k = size of 'email', skip to instruction 2060
  98. 2020 call subprogram lower on subject
  99. 2030 call subprogram lower on member of email at position k
  100. 2040 if 'out' from call to lower on subject == 'out' from call to lower on email_k, set result = true
  101. 2050 k = k + 1
  102. 2055 skip to instruction 2015
  103. 2060 return result to program that called
  104. 2070 return to program that called
  105.  
  106.  
  107. ***subprogram lower
  108. 3000 set out = given
  109. 3010 set h = 0
  110. 3015 if h = length of given, skip to instruction 3040
  111. 3020 character at position h in out = lowercase version of given_h
  112. 3030 h = h + 1
  113. 3035 skip to instruction 3015
  114. 3040 return out to program that called
  115. 3050 return to to program that called
  116.  
  117.  
  118. ***MAIN PROGRAM
  119. 10 output Introduction
  120. 20 output directions
  121. 30 dFile = "fileContainingEmails.txt"
  122. 40 enterKey = false
  123. 45 set empty = true
  124. 50 output prompt1, dFile
  125. 60 input iFile
  126. 70 if length of iFile = 0, then set enterKey = true
  127. 80 if enterKey = true, then iFile = dFile
  128. 90 if enterKey = true, skip to instruction 120
  129. 100 dFile = iFile
  130. 110 skip to instruction 130
  131. 120 dFile = "copyPasteMyEmails.txt"
  132. 130 output prompt2, dFile
  133. 140 input oFile
  134. 150 enterKey = false;
  135. 160 if length of oFile is 0, then enterKey = true
  136. 170 if enter key is true, then oFile = dFile
  137. 180 output label for the input file name, and iFile
  138. 190 output label for the output file name, and oFile
  139. 200 output prompt3
  140. 210 input keepGoing
  141. 220 if length of keepGoing > 0, skip to instruction 995
  142. 230 open iFile
  143. 240 if there are no problems with iFile, skip to instruction 270
  144. 250 send error message to OS
  145. 260 skip to instruction 999
  146. 270 if there are problems with iFile or iFile has ended, skip to instruction 570
  147. 280 set line = current line of iFile
  148. 290 if length of line = 0 skip to instruction 550
  149. 300 set i = 0
  150. 310 set empty = false
  151. 320 if i = length of line, skip to instruction 550
  152. 330 if character at position i in line not '@', skip to instruction 530
  153. 350 set s = (i - 1)
  154. 360 set e = (i + 1)
  155. 370 if s < 0 skip to instruction 410
  156. 375 call subprogram isValidEmailchar on character at position s in line
  157. 380 if result = false skip to instruction 410
  158. 390 set s = s - 1
  159. 400 skip to instruction 370
  160. 410 if e = the length of line, skip to instruction 470
  161. 412 call subprogram isValidEmailchar on character at position s in line
  162. 420 if result = false, skip to instruction 470
  163. 430 if character at position in line != '.' skip to instruction 460
  164. 440 set hasDot = true
  165. 450 dotPos = e
  166. 460 set e = e + 1
  167. 465 skip to instruction 410
  168. 470 set s = s + 1
  169. 475 if the following is FALSE, skip to instruction 510: (s < i) and (e > i) and (hasDot is true) and (dotPos > 1)
  170. 480 anEmail = the text between s and e
  171. 490 call isDup on anEmail
  172. 500 if result = true skip to instruction 530
  173. 510 output anEmail
  174. 520 add anEmail to list email
  175. 530 set i = i + 1
  176. 540 skip to instruction 320
  177. 550 move to next line
  178. 560 skip to instruction 270
  179. 570 if empty = false, skip to instruction 590
  180. 580 output emptymsg
  181. 590 if the size of list emails > 0, skip to instruction 620
  182. 600 output nonevalidmsg
  183. 610 skip to instruction 995
  184. 620 set m = 0
  185. 630 if m equals size of list email, skip to instruction 760
  186. 640 set n = m + 1
  187. 650 if n = size of list email, skip to instruction 740
  188. 660 call subprogram lower on email_m
  189. 670 call subprogram lower on email_n
  190. 680 if 'out' from lower on email_m <= 'out' from lower on email_n, skip to instruction 720
  191. 690 set temp = email_m
  192. 700 set email_m=email_n
  193. 710 set email_n = temp
  194. 720 set n = n + 1
  195. 730 skip to instruction 650
  196. 740 set m = m + 1
  197. 750 skip to instruction 630
  198. 760 open oFile
  199. 770 set i = 0
  200. 780 if i = size of list email, skip to instruction
  201. 790 output email_i
  202. ....(finish writing output loop basically)
  203. ... output label3 and size of list email
  204. 995 output goodbyemsg
  205. 999 END
  206.  
  207.  
  208. 4. Test Cases
  209.  
  210. (THERE ARE MORE TEST CASES NOW... I THINK)
  211. *****Test Case#1: very simple, unproblematic usage
  212.  
  213. *What is being tested: simple- one line has two '@', another line has one '@'
  214.  
  215. *Input values if any:
  216. iFile = 'test.txt'
  217. CONTENTS:
  218. abc@123.com
  219. oFile = '\n'
  220.  
  221. *Expected result:
  222. -Introduction
  223. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  224. -Please enter the name of the output file. [Leave blank for 'test.txt']:
  225. -input filename: test.txt
  226. -output filename: test.txt
  227. -Press ENTER to continue. Any other key (+ enter) quits.
  228. -abc@123.com
  229. -number of emails: 1
  230. -Thanks for using this program. Have a great day!
  231.  
  232. *Test:
  233. 10 Introduction
  234. 20 directions
  235. 30 dFile = "fileContainingEmails.txt"
  236. 40 enterKey = false
  237. 45 empty = true
  238. 50 prompt1, dFile
  239. 60 iFile = test.txt
  240. 100 dFile = iFile
  241. 110 skip to instruction 130
  242. 130 prompt2, dFile
  243. 140 oFile = '\n'
  244. 150 enterKey = false;
  245. 160 enterKey = true
  246. 170 oFile = dFile
  247. 180 label1, iFile
  248. 190 label2, oFile
  249. 200 output a prompt to press ENTER key to continue
  250. 210 keepGoing = '\n'
  251. 270 if there are problems with iFile or iFile has ended, skip to instruction 995
  252. 280 line = abc@123.com
  253. 300 i = 0
  254. 310 empty = false
  255. 330 skip to instruction 510
  256. 510 i= 0 + 1 = 1
  257. 520 skip to instruction 320
  258. 330 skip to instruction 510
  259. 510 i = 1 + 1 = 2
  260. 520 skip to instruction 320
  261. 330 skip to instruction 510
  262. 510 i = 2 + 1 = 3
  263. 520 skip to instruction 320
  264. 340 hasAt = 0 + 1 = 1
  265. 350 s = 3 - 1 = 2
  266. 360 e = 3 + 1 = 4
  267. 375 call isDup on line_2 ('c')
  268. 1000 result = false
  269. 1010 result = true
  270. 1020 return result to main program
  271. 390 s = 2 - 1 = 1
  272. 400 skip to instruction 370
  273. 375 call isDup on line_1 ('b')
  274. 1000 result = false
  275. 1010 result = true
  276. 1020 return result to main program
  277. 390 s = 1 - 1 = 0
  278. 400 skip to instruction 370
  279. 375 call isDup on line_0 ('a')
  280. 1000 result = false
  281. 1010 result = true
  282. 1020 return result to main program
  283. 390 s = 0 - 1 = -1
  284. 400 skip to instruction 370
  285. 370 skip to instruction 410
  286. 412 call isValidEmailchar on line_4 ('1')
  287. 1000 result = false
  288. 1010 result = true
  289. 1020 return result to main program
  290. 430 skip to instruction 460
  291. 460 e = 4 + 1 = 5
  292. 465 skip to instruction 410
  293. 412 call isValidEmailchar on line_5 ('2')
  294. 1000 result = false
  295. 1010 result = true
  296. 1020 return result to main program
  297. 430 skip to instruction 460
  298. 460 e = 5 + 1 = 6
  299. 465 skip to instruction 410
  300. 412 call isValidEmailchar on line_6 ('3')
  301. 1000 result = false
  302. 1010 result = true
  303. 1020 return result to main program
  304. 430 skip to instruction 460
  305. 460 e = 6 + 1 = 7
  306. 465 skip to instruction 410
  307. 412 call isValidEmailchar on line_7 ('.')
  308. 1000 result = false
  309. 1010 result = true
  310. 1020 return result to main program
  311. 440 hasDot = true
  312. 450 dotPos = 7
  313. 460 e = 7 + 1 = 8
  314. 465 skip to instruction 410
  315. 412 call isValidEmailchar on line_8 ('c')
  316. 1000 result = false
  317. 1010 result = true
  318. 1020 return result to main program
  319. 430 skip to instruction 460
  320. 460 e = 8 + 1 = 9
  321. 465 skip to instruction 410
  322. 412 call isValidEmailchar on line_9 ('o')
  323. 1000 result = false
  324. 1010 result = true
  325. 1020 return result to main program
  326. 430 skip to instruction 460
  327. 460 e = 9 + 1 = 10
  328. 465 skip to instruction 410
  329. 412 call isValidEmailchar on line_10 ('m')
  330. 1000 result = false
  331. 1010 result = true
  332. 1020 return result to main program
  333. 430 skip to instruction 460
  334. 460 e = 10 + 1 = 11
  335. 465 skip to instruction 410
  336. 410 skip to instruction 470
  337. 470 s = -1 + 1 = 0
  338. 480 anEmail = text between 0 and 11- abc@123.com
  339. 490 call isDup on abc@123.com
  340. 2000 result = false
  341. 2010 k = 0
  342. 2015 skip to instruction 2060
  343. 2060 return false to main program
  344. 510 abc@123.com
  345. 520 email_0 = abc@123.com
  346. 530 i = 3 + 1 = 4
  347. 540 skip to instruction 320
  348. 330 skip to instruction 530
  349. 510 i = 4 + 1 = 5
  350. 520 skip to instruction 320
  351. 330 skip to instruction 530
  352. 510 i = 5 + 1 = 6
  353. 520 skip to instruction 320
  354. 330 skip to instruction 530
  355. 510 i = 6 + 1 = 7
  356. 520 skip to instruction 320
  357. 330 skip to instruction 530
  358. 510 i = 7 + 1 = 8
  359. 520 skip to instruction 320
  360. 330 skip to instruction 530
  361. 510 i = 8 + 1 = 9
  362. 520 skip to instruction 320
  363. 330 skip to instruction 530
  364. 510 i = 9 + 1 = 10
  365. 520 skip to instruction 320
  366. 330 skip to instruction 530
  367. 510 i = 10 + 1 = 11
  368. 320 skip to instruction 550
  369. 560 skip to instruction 270
  370. 270 skip to instruction 570
  371. 570 skip to instruction 590
  372. 590 skip to instruction 620
  373. 620 label3, 1
  374. 995 goodbyemsg
  375. 999 END
  376.  
  377. *****Test Case#2: both defaults
  378.  
  379. *What is being tested: user only enters ENTER key, no custom values (then quits program execution)
  380.  
  381. *Input values if any:
  382. iFile = '\n'
  383. oFile = '\n'
  384.  
  385. *Expected result:
  386. -Introduction
  387. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  388. -Please enter the name of the output file. [Leave blank for 'copyPasteMyEmails.txt']:
  389. -input filename: fileContainingEmails.txt
  390. -output filename: copyPasteMyEmails.txt
  391. -Press ENTER to continue. Any other key (+ enter) quits.
  392. -Thanks for using this program. Have a great day!
  393.  
  394. *****Test Case#3: custom input filename
  395.  
  396. *What is being tested: user wants different input file from default, and uses the same file for output
  397.  
  398. *Input values if any:
  399. iFile = 'x.txt'
  400. CONTENTS:
  401. abc@123.com
  402. oFile = '\n'
  403.  
  404. *Expected result:
  405. -Introduction
  406. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  407. -Please enter the name of the output file. [Leave blank for 'x.txt']:
  408. -input filename: x.txt
  409. -output filename: x.txt
  410. -Press ENTER to continue.
  411. -abc@123.com
  412. -number of emails: 1
  413. -Thanks for using this program. Have a great day!
  414.  
  415. *****Test Case#4: custom output filename
  416.  
  417. *What is being tested: user wants different output file from default, and uses the same file for output
  418.  
  419. *Input values if any:
  420. iFile = '\n'
  421. CONTENTS [fileContainingEmails.txt] :
  422. abc@123.com
  423. oFile = 'y.txt'
  424.  
  425. *Expected result:
  426. -Introduction
  427. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  428. -Please enter the name of the output file. [Leave blank for 'copyPasteMyEmails.txt']:
  429. -input filename: fileContainingEmails.txt
  430. -output filename: y.txt
  431. -Press ENTER to continue.
  432. -abc@123.com
  433. -number of emails: 1
  434. -Thanks for using this program. Have a great day!
  435.  
  436. *****Test Case#5: both custom filenames
  437.  
  438. *What is being tested: user wants different input AND out file from default
  439.  
  440. *Input values if any:
  441. iFile = 'x.txt'
  442. CONTENTS:
  443. abc@123.com
  444. oFile = 'y.txt'
  445.  
  446. *Expected result:
  447. -Introduction
  448. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  449. -Please enter the name of the output file. [Leave blank for 'x.txt']:
  450. -input filename: x.txt
  451. -output filename: y.txt
  452. -Press ENTER to continue.
  453. -abc@123.com
  454. -number of emails: 1
  455. -Thanks for using this program. Have a great day!
  456.  
  457. *****Test Case#6: user wants to quit (change filenames)
  458.  
  459. *What is being tested: user makes a mistake with output filename
  460.  
  461. *Input values if any:
  462. iFile = 'test.txt'
  463. CONTENTS:
  464. @@
  465. \n
  466. @
  467. oFile = reddit.com
  468.  
  469. *Expected result:
  470. -Introduction
  471. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  472. -Please enter the name of the output file. [Leave blank for 'test.txt']:
  473. -input filename: test.txt
  474. -output filename: reddit.com
  475. -Press ENTER to continue. Any other key (+ enter) quits.
  476. -Thanks for using this program. Have a great day!
  477.  
  478. *****Test Case#7: user makes filename mistake and doesn't fix it
  479.  
  480. *What is being tested: user makes a mistake with input filename
  481.  
  482. *Input values if any:
  483. iFile = reddit.com
  484. oFile = '\n'
  485.  
  486. *Expected result:
  487. -Introduction
  488. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  489. -Please enter the name of the output file. [Leave blank for 'reddit.com']:
  490. -input filename: reddit.com
  491. -output filename: reddit.com
  492. -Press ENTER to continue. Any other key (+ enter) quits.
  493. -error message sent to OS
  494. -program failure
  495.  
  496. *****Test Case#8: file contains no emails
  497.  
  498. *What is being tested: input file just has non-email text
  499.  
  500. *Input values if any:
  501. iFile = 'test1.txt'
  502. CONTENTS:
  503. at at
  504. \n
  505. at
  506. oFile = '\n'
  507.  
  508. *Expected result:
  509. -Introduction
  510. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  511. -Please enter the name of the output file. [Leave blank for 'test1.txt']:
  512. -input filename: test1.txt
  513. -output filename: test1.txt
  514. -Press ENTER to continue. Any other key (+ enter) quits.
  515. -Your input file contains no emails.
  516. -Thanks for using this program. Have a great day!
  517.  
  518. *****Test Case #9: file is empty
  519.  
  520. *What is being tested: nothing in input file- no characters, only end of file marker (if applicable)
  521.  
  522. *Input values if any:
  523. iFile = 'test2.txt'
  524. CONTENTS:
  525.  
  526. oFile = '\n'
  527.  
  528. *Expected result:
  529. -Introduction
  530. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  531. -Please enter the name of the output file. [Leave blank for 'test2.txt']:
  532. -input filename: test2.txt
  533. -output filename: test2.txt
  534. -Press ENTER to continue. Any other key (+ enter) quits.
  535. -I'm sorry, your input file is empty
  536. -Thanks for using this program. Have a great day!
  537.  
  538. ******Test Case #10: input file has multiple duplicate emails
  539.  
  540. *What is being tested: ability to distinguish exact duplicates
  541.  
  542. *Input values if any:
  543. iFile = 'test3.txt'
  544. CONTENTS:
  545. abc@123.com
  546. abc@123.com
  547. oFile = '\n'
  548.  
  549. *Expected result:
  550. -Introduction
  551. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  552. -Please enter the name of the output file. [Leave blank for 'test3.txt']:
  553. -input filename: test3.txt
  554. -output filename: test3.txt
  555. -Press ENTER to continue. Any other key (+ enter) quits.
  556. -abc@123.com
  557. -number of emails: 1
  558. -Thanks for using this program. Have a great day!
  559.  
  560. ******Test Case #11: input file has the same email more than once, but cased differently
  561.  
  562. *What is being tested: ability to distinguish cases
  563.  
  564. *Input values if any:
  565. iFile = 'test4.txt'
  566. CONTENTS:
  567. abc@123.com
  568. ABC@123.com
  569. abc@123.com
  570. oFile = '\n'
  571.  
  572. *Expected result:
  573. -Introduction
  574. -Please enter the name of the input file. [Leave blank for 'fileContainingEmails.txt']:
  575. -Please enter the name of the output file. [Leave blank for 'test4.txt']:
  576. -input filename: test4.txt
  577. -output filename: test4.txt
  578. -Press ENTER to continue. Any other key (+ enter) quits.
  579. -abc@123.com
  580. -number of emails: 1
  581. -Thanks for using this program. Have a great day!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement