Sin descripción

Testing.html 69KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773
  1. <!DOCTYPE html><html><head><meta charset="utf-8"><style>body {
  2. width: 45em;
  3. border: 1px solid #ddd;
  4. outline: 1300px solid #fff;
  5. margin: 16px auto;
  6. }
  7. body .markdown-body
  8. {
  9. padding: 30px;
  10. }
  11. @font-face {
  12. font-family: octicons-anchor;
  13. src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAYcAA0AAAAACjQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABwAAAAca8vGTk9TLzIAAAFMAAAARAAAAFZG1VHVY21hcAAAAZAAAAA+AAABQgAP9AdjdnQgAAAB0AAAAAQAAAAEACICiGdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAADRAAABEKyikaNoZWFkAAACsAAAAC0AAAA2AtXoA2hoZWEAAALgAAAAHAAAACQHngNFaG10eAAAAvwAAAAQAAAAEAwAACJsb2NhAAADDAAAAAoAAAAKALIAVG1heHAAAAMYAAAAHwAAACABEAB2bmFtZQAAAzgAAALBAAAFu3I9x/Nwb3N0AAAF/AAAAB0AAAAvaoFvbwAAAAEAAAAAzBdyYwAAAADP2IQvAAAAAM/bz7t4nGNgZGFgnMDAysDB1Ml0hoGBoR9CM75mMGLkYGBgYmBlZsAKAtJcUxgcPsR8iGF2+O/AEMPsznAYKMwIkgMA5REMOXicY2BgYGaAYBkGRgYQsAHyGMF8FgYFIM0ChED+h5j//yEk/3KoSgZGNgYYk4GRCUgwMaACRoZhDwCs7QgGAAAAIgKIAAAAAf//AAJ4nHWMMQrCQBBF/0zWrCCIKUQsTDCL2EXMohYGSSmorScInsRGL2DOYJe0Ntp7BK+gJ1BxF1stZvjz/v8DRghQzEc4kIgKwiAppcA9LtzKLSkdNhKFY3HF4lK69ExKslx7Xa+vPRVS43G98vG1DnkDMIBUgFN0MDXflU8tbaZOUkXUH0+U27RoRpOIyCKjbMCVejwypzJJG4jIwb43rfl6wbwanocrJm9XFYfskuVC5K/TPyczNU7b84CXcbxks1Un6H6tLH9vf2LRnn8Ax7A5WQAAAHicY2BkYGAA4teL1+yI57f5ysDNwgAC529f0kOmWRiYVgEpDgYmEA8AUzEKsQAAAHicY2BkYGB2+O/AEMPCAAJAkpEBFbAAADgKAe0EAAAiAAAAAAQAAAAEAAAAAAAAKgAqACoAiAAAeJxjYGRgYGBhsGFgYgABEMkFhAwM/xn0QAIAD6YBhwB4nI1Ty07cMBS9QwKlQapQW3VXySvEqDCZGbGaHULiIQ1FKgjWMxknMfLEke2A+IJu+wntrt/QbVf9gG75jK577Lg8K1qQPCfnnnt8fX1NRC/pmjrk/zprC+8D7tBy9DHgBXoWfQ44Av8t4Bj4Z8CLtBL9CniJluPXASf0Lm4CXqFX8Q84dOLnMB17N4c7tBo1AS/Qi+hTwBH4rwHHwN8DXqQ30XXAS7QaLwSc0Gn8NuAVWou/gFmnjLrEaEh9GmDdDGgL3B4JsrRPDU2hTOiMSuJUIdKQQayiAth69r6akSSFqIJuA19TrzCIaY8sIoxyrNIrL//pw7A2iMygkX5vDj+G+kuoLdX4GlGK/8Lnlz6/h9MpmoO9rafrz7ILXEHHaAx95s9lsI7AHNMBWEZHULnfAXwG9/ZqdzLI08iuwRloXE8kfhXYAvE23+23DU3t626rbs8/8adv+9DWknsHp3E17oCf+Z48rvEQNZ78paYM38qfk3v/u3l3u3GXN2Dmvmvpf1Srwk3pB/VSsp512bA/GG5i2WJ7wu430yQ5K3nFGiOqgtmSB5pJVSizwaacmUZzZhXLlZTq8qGGFY2YcSkqbth6aW1tRmlaCFs2016m5qn36SbJrqosG4uMV4aP2PHBmB3tjtmgN2izkGQyLWprekbIntJFing32a5rKWCN/SdSoga45EJykyQ7asZvHQ8PTm6cslIpwyeyjbVltNikc2HTR7YKh9LBl9DADC0U/jLcBZDKrMhUBfQBvXRzLtFtjU9eNHKin0x5InTqb8lNpfKv1s1xHzTXRqgKzek/mb7nB8RZTCDhGEX3kK/8Q75AmUM/eLkfA+0Hi908Kx4eNsMgudg5GLdRD7a84npi+YxNr5i5KIbW5izXas7cHXIMAau1OueZhfj+cOcP3P8MNIWLyYOBuxL6DRylJ4cAAAB4nGNgYoAALjDJyIAOWMCiTIxMLDmZedkABtIBygAAAA==) format('woff');
  14. }
  15. .markdown-body {
  16. -ms-text-size-adjust: 100%;
  17. -webkit-text-size-adjust: 100%;
  18. color: #333;
  19. overflow: hidden;
  20. font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;
  21. font-size: 16px;
  22. line-height: 1.6;
  23. word-wrap: break-word;
  24. }
  25. .markdown-body a {
  26. background: transparent;
  27. }
  28. .markdown-body a:active,
  29. .markdown-body a:hover {
  30. outline: 0;
  31. }
  32. .markdown-body strong {
  33. font-weight: bold;
  34. }
  35. .markdown-body h1 {
  36. font-size: 2em;
  37. margin: 0.67em 0;
  38. }
  39. .markdown-body img {
  40. border: 0;
  41. }
  42. .markdown-body hr {
  43. -moz-box-sizing: content-box;
  44. box-sizing: content-box;
  45. height: 0;
  46. }
  47. .markdown-body pre {
  48. overflow: auto;
  49. }
  50. .markdown-body code,
  51. .markdown-body kbd,
  52. .markdown-body pre {
  53. font-family: monospace, monospace;
  54. font-size: 1em;
  55. }
  56. .markdown-body input {
  57. color: inherit;
  58. font: inherit;
  59. margin: 0;
  60. }
  61. .markdown-body html input[disabled] {
  62. cursor: default;
  63. }
  64. .markdown-body input {
  65. line-height: normal;
  66. }
  67. .markdown-body input[type="checkbox"] {
  68. -moz-box-sizing: border-box;
  69. box-sizing: border-box;
  70. padding: 0;
  71. }
  72. .markdown-body table {
  73. border-collapse: collapse;
  74. border-spacing: 0;
  75. }
  76. .markdown-body td,
  77. .markdown-body th {
  78. padding: 0;
  79. }
  80. .markdown-body * {
  81. -moz-box-sizing: border-box;
  82. box-sizing: border-box;
  83. }
  84. .markdown-body input {
  85. font: 13px/1.4 Helvetica, arial, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";
  86. }
  87. .markdown-body a {
  88. color: #4183c4;
  89. text-decoration: none;
  90. }
  91. .markdown-body a:hover,
  92. .markdown-body a:focus,
  93. .markdown-body a:active {
  94. text-decoration: underline;
  95. }
  96. .markdown-body hr {
  97. height: 0;
  98. margin: 15px 0;
  99. overflow: hidden;
  100. background: transparent;
  101. border: 0;
  102. border-bottom: 1px solid #ddd;
  103. }
  104. .markdown-body hr:before {
  105. display: table;
  106. content: "";
  107. }
  108. .markdown-body hr:after {
  109. display: table;
  110. clear: both;
  111. content: "";
  112. }
  113. .markdown-body h1,
  114. .markdown-body h2,
  115. .markdown-body h3,
  116. .markdown-body h4,
  117. .markdown-body h5,
  118. .markdown-body h6 {
  119. margin-top: 15px;
  120. margin-bottom: 15px;
  121. line-height: 1.1;
  122. }
  123. .markdown-body h1 {
  124. font-size: 30px;
  125. }
  126. .markdown-body h2 {
  127. font-size: 21px;
  128. }
  129. .markdown-body h3 {
  130. font-size: 16px;
  131. }
  132. .markdown-body h4 {
  133. font-size: 14px;
  134. }
  135. .markdown-body h5 {
  136. font-size: 12px;
  137. }
  138. .markdown-body h6 {
  139. font-size: 11px;
  140. }
  141. .markdown-body blockquote {
  142. margin: 0;
  143. }
  144. .markdown-body ul,
  145. .markdown-body ol {
  146. padding: 0;
  147. margin-top: 0;
  148. margin-bottom: 0;
  149. }
  150. .markdown-body ol ol,
  151. .markdown-body ul ol {
  152. list-style-type: lower-roman;
  153. }
  154. .markdown-body ul ul ol,
  155. .markdown-body ul ol ol,
  156. .markdown-body ol ul ol,
  157. .markdown-body ol ol ol {
  158. list-style-type: lower-alpha;
  159. }
  160. .markdown-body dd {
  161. margin-left: 0;
  162. }
  163. .markdown-body code {
  164. font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
  165. }
  166. .markdown-body pre {
  167. margin-top: 0;
  168. margin-bottom: 0;
  169. font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;
  170. }
  171. .markdown-body .octicon {
  172. font: normal normal 16px octicons-anchor;
  173. line-height: 1;
  174. display: inline-block;
  175. text-decoration: none;
  176. -webkit-font-smoothing: antialiased;
  177. -moz-osx-font-smoothing: grayscale;
  178. -webkit-user-select: none;
  179. -moz-user-select: none;
  180. -ms-user-select: none;
  181. user-select: none;
  182. }
  183. .markdown-body .octicon-link:before {
  184. content: '\f05c';
  185. }
  186. .markdown-body>*:first-child {
  187. margin-top: 0 !important;
  188. }
  189. .markdown-body>*:last-child {
  190. margin-bottom: 0 !important;
  191. }
  192. .markdown-body .anchor {
  193. position: absolute;
  194. top: 0;
  195. bottom: 0;
  196. left: 0;
  197. display: block;
  198. padding-right: 6px;
  199. padding-left: 30px;
  200. margin-left: -30px;
  201. }
  202. .markdown-body .anchor:focus {
  203. outline: none;
  204. }
  205. .markdown-body h1,
  206. .markdown-body h2,
  207. .markdown-body h3,
  208. .markdown-body h4,
  209. .markdown-body h5,
  210. .markdown-body h6 {
  211. position: relative;
  212. margin-top: 1em;
  213. margin-bottom: 16px;
  214. font-weight: bold;
  215. line-height: 1.4;
  216. }
  217. .markdown-body h1 .octicon-link,
  218. .markdown-body h2 .octicon-link,
  219. .markdown-body h3 .octicon-link,
  220. .markdown-body h4 .octicon-link,
  221. .markdown-body h5 .octicon-link,
  222. .markdown-body h6 .octicon-link {
  223. display: none;
  224. color: #000;
  225. vertical-align: middle;
  226. }
  227. .markdown-body h1:hover .anchor,
  228. .markdown-body h2:hover .anchor,
  229. .markdown-body h3:hover .anchor,
  230. .markdown-body h4:hover .anchor,
  231. .markdown-body h5:hover .anchor,
  232. .markdown-body h6:hover .anchor {
  233. padding-left: 8px;
  234. margin-left: -30px;
  235. line-height: 1;
  236. text-decoration: none;
  237. }
  238. .markdown-body h1:hover .anchor .octicon-link,
  239. .markdown-body h2:hover .anchor .octicon-link,
  240. .markdown-body h3:hover .anchor .octicon-link,
  241. .markdown-body h4:hover .anchor .octicon-link,
  242. .markdown-body h5:hover .anchor .octicon-link,
  243. .markdown-body h6:hover .anchor .octicon-link {
  244. display: inline-block;
  245. }
  246. .markdown-body h1 {
  247. padding-bottom: 0.3em;
  248. font-size: 2.25em;
  249. line-height: 1.2;
  250. border-bottom: 1px solid #eee;
  251. }
  252. .markdown-body h2 {
  253. padding-bottom: 0.3em;
  254. font-size: 1.75em;
  255. line-height: 1.225;
  256. border-bottom: 1px solid #eee;
  257. }
  258. .markdown-body h3 {
  259. font-size: 1.5em;
  260. line-height: 1.43;
  261. }
  262. .markdown-body h4 {
  263. font-size: 1.25em;
  264. }
  265. .markdown-body h5 {
  266. font-size: 1em;
  267. }
  268. .markdown-body h6 {
  269. font-size: 1em;
  270. color: #777;
  271. }
  272. .markdown-body p,
  273. .markdown-body blockquote,
  274. .markdown-body ul,
  275. .markdown-body ol,
  276. .markdown-body dl,
  277. .markdown-body table,
  278. .markdown-body pre {
  279. margin-top: 0;
  280. margin-bottom: 16px;
  281. }
  282. .markdown-body hr {
  283. height: 4px;
  284. padding: 0;
  285. margin: 16px 0;
  286. background-color: #e7e7e7;
  287. border: 0 none;
  288. }
  289. .markdown-body ul,
  290. .markdown-body ol {
  291. padding-left: 2em;
  292. }
  293. .markdown-body ul ul,
  294. .markdown-body ul ol,
  295. .markdown-body ol ol,
  296. .markdown-body ol ul {
  297. margin-top: 0;
  298. margin-bottom: 0;
  299. }
  300. .markdown-body li>p {
  301. margin-top: 16px;
  302. }
  303. .markdown-body dl {
  304. padding: 0;
  305. }
  306. .markdown-body dl dt {
  307. padding: 0;
  308. margin-top: 16px;
  309. font-size: 1em;
  310. font-style: italic;
  311. font-weight: bold;
  312. }
  313. .markdown-body dl dd {
  314. padding: 0 16px;
  315. margin-bottom: 16px;
  316. }
  317. .markdown-body blockquote {
  318. padding: 0 15px;
  319. color: #777;
  320. border-left: 4px solid #ddd;
  321. }
  322. .markdown-body blockquote>:first-child {
  323. margin-top: 0;
  324. }
  325. .markdown-body blockquote>:last-child {
  326. margin-bottom: 0;
  327. }
  328. .markdown-body table {
  329. display: block;
  330. width: 100%;
  331. overflow: auto;
  332. word-break: normal;
  333. word-break: keep-all;
  334. }
  335. .markdown-body table th {
  336. font-weight: bold;
  337. }
  338. .markdown-body table th,
  339. .markdown-body table td {
  340. padding: 6px 13px;
  341. border: 1px solid #ddd;
  342. }
  343. .markdown-body table tr {
  344. background-color: #fff;
  345. border-top: 1px solid #ccc;
  346. }
  347. .markdown-body table tr:nth-child(2n) {
  348. background-color: #f8f8f8;
  349. }
  350. .markdown-body img {
  351. max-width: 100%;
  352. -moz-box-sizing: border-box;
  353. box-sizing: border-box;
  354. }
  355. .markdown-body code {
  356. padding: 0;
  357. padding-top: 0.2em;
  358. padding-bottom: 0.2em;
  359. margin: 0;
  360. font-size: 85%;
  361. background-color: rgba(0,0,0,0.04);
  362. border-radius: 3px;
  363. }
  364. .markdown-body code:before,
  365. .markdown-body code:after {
  366. letter-spacing: -0.2em;
  367. content: "\00a0";
  368. }
  369. .markdown-body pre>code {
  370. padding: 0;
  371. margin: 0;
  372. font-size: 100%;
  373. word-break: normal;
  374. white-space: pre;
  375. background: transparent;
  376. border: 0;
  377. }
  378. .markdown-body .highlight {
  379. margin-bottom: 16px;
  380. }
  381. .markdown-body .highlight pre,
  382. .markdown-body pre {
  383. padding: 16px;
  384. overflow: auto;
  385. font-size: 85%;
  386. line-height: 1.45;
  387. background-color: #f7f7f7;
  388. border-radius: 3px;
  389. }
  390. .markdown-body .highlight pre {
  391. margin-bottom: 0;
  392. word-break: normal;
  393. }
  394. .markdown-body pre {
  395. word-wrap: normal;
  396. }
  397. .markdown-body pre code {
  398. display: inline;
  399. max-width: initial;
  400. padding: 0;
  401. margin: 0;
  402. overflow: initial;
  403. line-height: inherit;
  404. word-wrap: normal;
  405. background-color: transparent;
  406. border: 0;
  407. }
  408. .markdown-body pre code:before,
  409. .markdown-body pre code:after {
  410. content: normal;
  411. }
  412. .markdown-body .highlight {
  413. background: #fff;
  414. }
  415. .markdown-body .highlight .h {
  416. color: #333;
  417. font-style: normal;
  418. font-weight: normal;
  419. }
  420. .markdown-body .highlight .mf,
  421. .markdown-body .highlight .mh,
  422. .markdown-body .highlight .mi,
  423. .markdown-body .highlight .mo,
  424. .markdown-body .highlight .il,
  425. .markdown-body .highlight .m {
  426. color: #945277;
  427. }
  428. .markdown-body .highlight .s,
  429. .markdown-body .highlight .sb,
  430. .markdown-body .highlight .sc,
  431. .markdown-body .highlight .sd,
  432. .markdown-body .highlight .s2,
  433. .markdown-body .highlight .se,
  434. .markdown-body .highlight .sh,
  435. .markdown-body .highlight .si,
  436. .markdown-body .highlight .sx,
  437. .markdown-body .highlight .s1 {
  438. color: #df5000;
  439. }
  440. .markdown-body .highlight .kc,
  441. .markdown-body .highlight .kd,
  442. .markdown-body .highlight .kn,
  443. .markdown-body .highlight .kp,
  444. .markdown-body .highlight .kr,
  445. .markdown-body .highlight .kt,
  446. .markdown-body .highlight .k,
  447. .markdown-body .highlight .o {
  448. font-weight: bold;
  449. }
  450. .markdown-body .highlight .kt {
  451. color: #458;
  452. }
  453. .markdown-body .highlight .c,
  454. .markdown-body .highlight .cm,
  455. .markdown-body .highlight .c1 {
  456. color: #998;
  457. font-style: italic;
  458. }
  459. .markdown-body .highlight .cp,
  460. .markdown-body .highlight .cs,
  461. .markdown-body .highlight .cp .h {
  462. color: #999;
  463. font-weight: bold;
  464. }
  465. .markdown-body .highlight .cs {
  466. font-style: italic;
  467. }
  468. .markdown-body .highlight .n {
  469. color: #333;
  470. }
  471. .markdown-body .highlight .na,
  472. .markdown-body .highlight .nv,
  473. .markdown-body .highlight .vc,
  474. .markdown-body .highlight .vg,
  475. .markdown-body .highlight .vi {
  476. color: #008080;
  477. }
  478. .markdown-body .highlight .nb {
  479. color: #0086B3;
  480. }
  481. .markdown-body .highlight .nc {
  482. color: #458;
  483. font-weight: bold;
  484. }
  485. .markdown-body .highlight .no {
  486. color: #094e99;
  487. }
  488. .markdown-body .highlight .ni {
  489. color: #800080;
  490. }
  491. .markdown-body .highlight .ne {
  492. color: #990000;
  493. font-weight: bold;
  494. }
  495. .markdown-body .highlight .nf {
  496. color: #945277;
  497. font-weight: bold;
  498. }
  499. .markdown-body .highlight .nn {
  500. color: #555;
  501. }
  502. .markdown-body .highlight .nt {
  503. color: #000080;
  504. }
  505. .markdown-body .highlight .err {
  506. color: #a61717;
  507. background-color: #e3d2d2;
  508. }
  509. .markdown-body .highlight .gd {
  510. color: #000;
  511. background-color: #fdd;
  512. }
  513. .markdown-body .highlight .gd .x {
  514. color: #000;
  515. background-color: #faa;
  516. }
  517. .markdown-body .highlight .ge {
  518. font-style: italic;
  519. }
  520. .markdown-body .highlight .gr {
  521. color: #aa0000;
  522. }
  523. .markdown-body .highlight .gh {
  524. color: #999;
  525. }
  526. .markdown-body .highlight .gi {
  527. color: #000;
  528. background-color: #dfd;
  529. }
  530. .markdown-body .highlight .gi .x {
  531. color: #000;
  532. background-color: #afa;
  533. }
  534. .markdown-body .highlight .go {
  535. color: #888;
  536. }
  537. .markdown-body .highlight .gp {
  538. color: #555;
  539. }
  540. .markdown-body .highlight .gs {
  541. font-weight: bold;
  542. }
  543. .markdown-body .highlight .gu {
  544. color: #800080;
  545. font-weight: bold;
  546. }
  547. .markdown-body .highlight .gt {
  548. color: #aa0000;
  549. }
  550. .markdown-body .highlight .ow {
  551. font-weight: bold;
  552. }
  553. .markdown-body .highlight .w {
  554. color: #bbb;
  555. }
  556. .markdown-body .highlight .sr {
  557. color: #017936;
  558. }
  559. .markdown-body .highlight .ss {
  560. color: #8b467f;
  561. }
  562. .markdown-body .highlight .bp {
  563. color: #999;
  564. }
  565. .markdown-body .highlight .gc {
  566. color: #999;
  567. background-color: #EAF2F5;
  568. }
  569. .markdown-body kbd {
  570. background-color: #e7e7e7;
  571. background-image: -webkit-linear-gradient(#fefefe, #e7e7e7);
  572. background-image: linear-gradient(#fefefe, #e7e7e7);
  573. background-repeat: repeat-x;
  574. display: inline-block;
  575. padding: 3px 5px;
  576. font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;
  577. line-height: 10px;
  578. color: #000;
  579. border: 1px solid #cfcfcf;
  580. border-radius: 2px;
  581. }
  582. .markdown-body .highlight .pl-coc,
  583. .markdown-body .highlight .pl-entm,
  584. .markdown-body .highlight .pl-eoa,
  585. .markdown-body .highlight .pl-mai .pl-sf,
  586. .markdown-body .highlight .pl-pdv,
  587. .markdown-body .highlight .pl-sc,
  588. .markdown-body .highlight .pl-sr,
  589. .markdown-body .highlight .pl-v,
  590. .markdown-body .highlight .pl-vpf {
  591. color: #0086b3;
  592. }
  593. .markdown-body .highlight .pl-eoac,
  594. .markdown-body .highlight .pl-mdht,
  595. .markdown-body .highlight .pl-mi1,
  596. .markdown-body .highlight .pl-mri,
  597. .markdown-body .highlight .pl-va,
  598. .markdown-body .highlight .pl-vpu {
  599. color: #008080;
  600. }
  601. .markdown-body .highlight .pl-c,
  602. .markdown-body .highlight .pl-pdc {
  603. color: #b4b7b4;
  604. font-style: italic;
  605. }
  606. .markdown-body .highlight .pl-k,
  607. .markdown-body .highlight .pl-ko,
  608. .markdown-body .highlight .pl-kolp,
  609. .markdown-body .highlight .pl-mc,
  610. .markdown-body .highlight .pl-mr,
  611. .markdown-body .highlight .pl-ms,
  612. .markdown-body .highlight .pl-s,
  613. .markdown-body .highlight .pl-sok,
  614. .markdown-body .highlight .pl-st {
  615. color: #6e5494;
  616. }
  617. .markdown-body .highlight .pl-ef,
  618. .markdown-body .highlight .pl-enf,
  619. .markdown-body .highlight .pl-enm,
  620. .markdown-body .highlight .pl-entc,
  621. .markdown-body .highlight .pl-eoi,
  622. .markdown-body .highlight .pl-sf,
  623. .markdown-body .highlight .pl-smc {
  624. color: #d12089;
  625. }
  626. .markdown-body .highlight .pl-ens,
  627. .markdown-body .highlight .pl-eoai,
  628. .markdown-body .highlight .pl-kos,
  629. .markdown-body .highlight .pl-mh .pl-pdh,
  630. .markdown-body .highlight .pl-mp,
  631. .markdown-body .highlight .pl-pde,
  632. .markdown-body .highlight .pl-stp {
  633. color: #458;
  634. }
  635. .markdown-body .highlight .pl-enti {
  636. color: #d12089;
  637. font-weight: bold;
  638. }
  639. .markdown-body .highlight .pl-cce,
  640. .markdown-body .highlight .pl-enc,
  641. .markdown-body .highlight .pl-kou,
  642. .markdown-body .highlight .pl-mq {
  643. color: #f93;
  644. }
  645. .markdown-body .highlight .pl-mp1 .pl-sf {
  646. color: #458;
  647. font-weight: bold;
  648. }
  649. .markdown-body .highlight .pl-cos,
  650. .markdown-body .highlight .pl-ent,
  651. .markdown-body .highlight .pl-md,
  652. .markdown-body .highlight .pl-mdhf,
  653. .markdown-body .highlight .pl-ml,
  654. .markdown-body .highlight .pl-pdc1,
  655. .markdown-body .highlight .pl-pds,
  656. .markdown-body .highlight .pl-s1,
  657. .markdown-body .highlight .pl-scp,
  658. .markdown-body .highlight .pl-sol {
  659. color: #df5000;
  660. }
  661. .markdown-body .highlight .pl-c1,
  662. .markdown-body .highlight .pl-cn,
  663. .markdown-body .highlight .pl-pse,
  664. .markdown-body .highlight .pl-pse .pl-s2,
  665. .markdown-body .highlight .pl-vi {
  666. color: #a31515;
  667. }
  668. .markdown-body .highlight .pl-mb,
  669. .markdown-body .highlight .pl-pdb {
  670. color: #df5000;
  671. font-weight: bold;
  672. }
  673. .markdown-body .highlight .pl-mi,
  674. .markdown-body .highlight .pl-pdi {
  675. color: #6e5494;
  676. font-style: italic;
  677. }
  678. .markdown-body .highlight .pl-ms1 {
  679. background-color: #f5f5f5;
  680. }
  681. .markdown-body .highlight .pl-mdh,
  682. .markdown-body .highlight .pl-mdi {
  683. font-weight: bold;
  684. }
  685. .markdown-body .highlight .pl-mdr {
  686. color: #0086b3;
  687. font-weight: bold;
  688. }
  689. .markdown-body .highlight .pl-s2 {
  690. color: #333;
  691. }
  692. .markdown-body .highlight .pl-ii {
  693. background-color: #df5000;
  694. color: #fff;
  695. }
  696. .markdown-body .highlight .pl-ib {
  697. background-color: #f93;
  698. }
  699. .markdown-body .highlight .pl-id {
  700. background-color: #a31515;
  701. color: #fff;
  702. }
  703. .markdown-body .highlight .pl-iu {
  704. background-color: #b4b7b4;
  705. }
  706. .markdown-body .highlight .pl-mo {
  707. color: #969896;
  708. }
  709. .markdown-body .task-list-item {
  710. list-style-type: none;
  711. }
  712. .markdown-body .task-list-item+.task-list-item {
  713. margin-top: 3px;
  714. }
  715. .markdown-body .task-list-item input {
  716. float: left;
  717. margin: 0.3em 0 0.25em -1.6em;
  718. vertical-align: middle;
  719. }</style><script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  720. <script>
  721. MathJax.Hub.Config({
  722. config: ["MMLorHTML.js"],
  723. extensions: ["tex2jax.js"],
  724. jax: ["input/TeX"],
  725. tex2jax: {
  726. inlineMath: [ ['$','$'], ["\\(","\\)"] ],
  727. displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
  728. processEscapes: false
  729. },
  730. TeX: {
  731. extensions: ["AMSmath.js", "AMSsymbols.js"],
  732. TagSide: "right",
  733. TagIndent: ".8em",
  734. MultLineWidth: "85%",
  735. equationNumbers: {
  736. autoNumber: "AMS",
  737. },
  738. unicode: {
  739. fonts: "STIXGeneral,'Arial Unicode MS'"
  740. }
  741. },
  742. showProcessingMessages: false
  743. });
  744. </script>
  745. <title>Testing</title></head><body><article class="markdown-body"><p><a href="#markdown-header-testing-and-unit-testing">English</a> | <a href="#markdown-header-pruebas-y-pruebas-unitarias">Español</a></p>
  746. <h1>
  747. <a id="user-content-pruebas-y-pruebas-unitarias" class="anchor" href="#pruebas-y-pruebas-unitarias" aria-hidden="true"><span class="octicon octicon-link"></span></a>Pruebas y pruebas unitarias</h1>
  748. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/main1.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/main1.png" alt="main1.png" style="max-width:100%;"></a>
  749. <a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/main2.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/main2.png" alt="main2.png" style="max-width:100%;"></a>
  750. <a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/main3.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/main3.png" alt="main3.png" style="max-width:100%;"></a></p>
  751. <p>Como habrás aprendido en experiencias de laboratorio anteriores, lograr que un programa compile es solo una pequeña parte de programar. El compilador se encargará de decirte si hubo errores de sintaxis, pero no podrá detectar errores en la lógica del programa. Es muy importante el probar las funciones del programa para validar que producen los resultados correctos y esperados.</p>
  752. <p>Una manera de hacer estas pruebas es “a mano”, esto es, corriendo el programa múltiples veces, ingresando valores representativos (por medio del teclado) y visualmente verificando que el programa devuelve los valores esperados. Una forma más conveniente es implementar funciones dentro del programa cuyo propósito es verificar que otras funciones produzcan resultados correctos. En esta experiencia de laboratorio practicarás ambos métodos de verificación.</p>
  753. <h2>
  754. <a id="user-content-objetivos" class="anchor" href="#objetivos" aria-hidden="true"><span class="octicon octicon-link"></span></a>Objetivos:</h2>
  755. <ol>
  756. <li>Validar el funcionamiento de varias funciones haciendo pruebas "a mano".</li>
  757. <li>Crear pruebas unitarias para validar funciones, utilizando la función <code>assert</code> </li>
  758. </ol>
  759. <h2>
  760. <a id="user-content-pre-lab" class="anchor" href="#pre-lab" aria-hidden="true"><span class="octicon octicon-link"></span></a>Pre-Lab:</h2>
  761. <p>Antes de llegar al laboratorio debes:</p>
  762. <ol>
  763. <li><p>Haber repasado los conceptos básicos relacionados a pruebas y pruebas unitarias.</p></li>
  764. <li><p>Haber repasado el uso de la función <code>assert</code> para hacer pruebas.</p></li>
  765. <li><p>Haber estudiado los conceptos e instrucciones para la sesión de laboratorio.</p></li>
  766. <li><p>Haber tomado el quiz Pre-Lab que se encuentra en Moodle.</p></li>
  767. </ol>
  768. <hr>
  769. <hr>
  770. <h2>
  771. <a id="user-content-haciendo-pruebas-a-una-función" class="anchor" href="#haciendo-pruebas-a-una-funci%C3%B3n" aria-hidden="true"><span class="octicon octicon-link"></span></a>Haciendo pruebas a una función.</h2>
  772. <p>Cuando probamos la validez de una función debemos probar casos que activen los diversos resultados de la función. </p>
  773. <hr>
  774. <p><strong>Ejemplo 1:</strong> si fueras a validar una función <code>esPar(unsigned int n)</code> que determina si un entero positivo <em>n</em> es par, deberías hacer pruebas a la función tanto con números pares como números impares. Un conjunto adecuado de pruebas para dicha función podría ser:</p>
  775. <table>
  776. <thead>
  777. <tr>
  778. <th>Prueba</th>
  779. <th>Resultado esperado</th>
  780. </tr>
  781. </thead>
  782. <tbody>
  783. <tr>
  784. <td><code>esPar(8)</code></td>
  785. <td>true</td>
  786. </tr>
  787. <tr>
  788. <td><code>esPar(7)</code></td>
  789. <td>false</td>
  790. </tr>
  791. </tbody>
  792. </table>
  793. <hr>
  794. <p><strong>Ejemplo 2:</strong> Digamos que un amigo ha creado una función <code>unsigned int rangoEdad(unsigned int edad)</code> que se supone que devuelva 0 si la edad está entre 0 y 5 (inclusive), 1 si la edad está entre 6 y 18 inclusive, y 2 si la edad es mayor de 18. Una fuente común de errores en funciones como esta son los valores próximos a los límites de cada rango, por ejemplo, el número 5 se presta para error si el programador no usó una comparación correcta. Un conjunto adecuado de pruebas para la función <code>rangoEdad</code> sería:</p>
  795. <table>
  796. <thead>
  797. <tr>
  798. <th>Prueba</th>
  799. <th>Resultado esperado</th>
  800. </tr>
  801. </thead>
  802. <tbody>
  803. <tr>
  804. <td><code>rangoEdad(5)</code></td>
  805. <td>0</td>
  806. </tr>
  807. <tr>
  808. <td><code>rangoEdad(2)</code></td>
  809. <td>0</td>
  810. </tr>
  811. <tr>
  812. <td><code>rangoEdad(6)</code></td>
  813. <td>1</td>
  814. </tr>
  815. <tr>
  816. <td><code>rangoEdad(18)</code></td>
  817. <td>1</td>
  818. </tr>
  819. <tr>
  820. <td><code>rangoEdad(17)</code></td>
  821. <td>1</td>
  822. </tr>
  823. <tr>
  824. <td><code>rangoEdad(19)</code></td>
  825. <td>2</td>
  826. </tr>
  827. <tr>
  828. <td><code>rangoEdad(25)</code></td>
  829. <td>2</td>
  830. </tr>
  831. </tbody>
  832. </table>
  833. <hr>
  834. <h3>
  835. <a id="user-content-la-función-assert" class="anchor" href="#la-funci%C3%B3n-assert" aria-hidden="true"><span class="octicon octicon-link"></span></a>La función <code>assert</code>
  836. </h3>
  837. <p>La función <code>assert(bool expression)</code> se puede utilizar como herramienta rudimentaria para validar de funciones. <code>assert</code> tiene un funcionamiento muy sencillo y poderoso. Si la expresión que colocamos entre los paréntesis de <code>assert</code> es <em>cierta</em> la función permite que el programa continúe con la próxima instrucción. De lo contrario, si la expresión que colocamos entre los paréntesis es <em>falsa</em>, la función <code>assert</code> hace que el programa termine e imprime un mensaje al terminal que informa al usuario sobre la instrucción de <code>assert</code> que falló. </p>
  838. <p>Por ejemplo, el siguiente programa correrá de principio a fin sin problemas pues todos las expresiones incluidas en los paréntesis de los asserts evalúan a <em>true</em>.</p>
  839. <hr>
  840. <div class="highlight highlight-cpp"><pre>#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>iostream<span class="pl-pds">&gt;</span></span>
  841. #<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>cassert<span class="pl-pds">&gt;</span></span>
  842. <span class="pl-k">using</span> <span class="pl-k">namespace</span> <span class="pl-en">std</span><span class="pl-k">;</span>
  843. <span class="pl-k">int</span> <span class="pl-en">main</span>() {
  844. <span class="pl-k">int</span> i = <span class="pl-c1">10</span>, j = <span class="pl-c1">15</span>;
  845. <span class="pl-c1">assert</span>(i == <span class="pl-c1">10</span>);
  846. <span class="pl-c1">assert</span>(j == i + <span class="pl-c1">5</span>);
  847. <span class="pl-c1">assert</span>(j != i);
  848. <span class="pl-c1">assert</span>( (j &lt; i) == <span class="pl-c1">false</span>);
  849. cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Eso es todo, amigos!<span class="pl-pds">"</span></span> &lt;&lt; endl;
  850. <span class="pl-k">return</span> <span class="pl-c1">0</span>;
  851. }
  852. </pre></div>
  853. <p><strong>Figura 1.</strong> Ejemplo de programa que pasa todas las pruebas de <code>assert</code>.</p>
  854. <hr>
  855. <p>El siguiente programa no correrá hasta el final pues el segundo <code>assert</code> (<code>assert(j == i);</code>) contiene una expresión (<code>j==i</code>) que evalúa a <em>false</em>.</p>
  856. <hr>
  857. <div class="highlight highlight-cpp"><pre>
  858. #<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>iostream<span class="pl-pds">&gt;</span></span>
  859. #<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>cassert<span class="pl-pds">&gt;</span></span>
  860. <span class="pl-k">using</span> <span class="pl-k">namespace</span> <span class="pl-en">std</span><span class="pl-k">;</span>
  861. <span class="pl-k">int</span> <span class="pl-en">main</span>() {
  862. <span class="pl-k">int</span> i = <span class="pl-c1">10</span>, j = <span class="pl-c1">15</span>;
  863. <span class="pl-c1">assert</span>(i == <span class="pl-c1">10</span>);
  864. <span class="pl-c1">assert</span>(j == i);
  865. <span class="pl-c1">assert</span>(j != i);
  866. <span class="pl-c1">assert</span>( (j &lt; i) == <span class="pl-c1">false</span>);
  867. cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>Eso es todo, amigos!<span class="pl-pds">"</span></span> &lt;&lt; endl;
  868. <span class="pl-k">return</span> <span class="pl-c1">0</span>;
  869. }
  870. </pre></div>
  871. <p><strong>Figura 2.</strong> Ejemplo de programa que no "pasa" una prueba de <code>assert</code>.</p>
  872. <hr>
  873. <p>Al correr el pasado programa, en lugar de obtener la frase <code>”Eso es todo amigos!”</code> en el terminal, obtendremos un mensaje como el siguiente:</p>
  874. <p><code>Assertion failed: (j == i), function main, file ../programa01/main.cpp, line 8.</code></p>
  875. <p>El programa no ejecuta más instrucciones después de la línea 8.</p>
  876. <h4>
  877. <a id="user-content-cómo-usar-assert-para-validar-funciones" class="anchor" href="#c%C3%B3mo-usar-assert-para-validar-funciones" aria-hidden="true"><span class="octicon octicon-link"></span></a>¿Cómo usar assert para validar funciones?</h4>
  878. <p>Digamos que deseas automatizar la validación de la función <code>rangoEdad</code>. Un forma de hacerlo es crear una función que llame a la función <code>rangoEdad</code> con diversos argumentos y verifique que lo devuelto concuerde con el resultado esperado. Si incluimos cada comparación entre lo devuelto por <code>rangoEdad</code> y el resultado esperado dentro de un <code>assert</code>, obtenemos una función que se ejecuta de principio a fin solo si todas las invocaciones devolvieron el resultado esperado.</p>
  879. <hr>
  880. <div class="highlight highlight-cpp"><pre><span class="pl-k">void</span> <span class="pl-en">test_rangoEdad</span>() {
  881. <span class="pl-c1">assert</span>(<span class="pl-c1">rangoEdad</span>(<span class="pl-c1">5</span>) == <span class="pl-c1">0</span>);
  882. <span class="pl-c1">assert</span>(<span class="pl-c1">rangoEdad</span>(<span class="pl-c1">2</span>) == <span class="pl-c1">0</span>);
  883. <span class="pl-c1">assert</span>(<span class="pl-c1">rangoEdad</span>(<span class="pl-c1">6</span>) == <span class="pl-c1">1</span>);
  884. <span class="pl-c1">assert</span>(<span class="pl-c1">rangoEdad</span>(<span class="pl-c1">18</span>) == <span class="pl-c1">1</span>);
  885. <span class="pl-c1">assert</span>(<span class="pl-c1">rangoEdad</span>(<span class="pl-c1">17</span>) == <span class="pl-c1">1</span>);
  886. <span class="pl-c1">assert</span>(<span class="pl-c1">rangoEdad</span>(<span class="pl-c1">19</span>) == <span class="pl-c1">2</span>);
  887. <span class="pl-c1">assert</span>(<span class="pl-c1">rangoEdad</span>(<span class="pl-c1">25</span>) == <span class="pl-c1">2</span>);
  888. cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>rangoEdad passed all tests!!!<span class="pl-pds">"</span></span> &lt;&lt; endl;
  889. }</pre></div>
  890. <p><strong>Figura 3.</strong> Ejemplo de una función para pruebas usando <code>assert</code>.</p>
  891. <hr>
  892. <hr>
  893. <h2>
  894. <a id="user-content-sesión-de-laboratorio" class="anchor" href="#sesi%C3%B3n-de-laboratorio" aria-hidden="true"><span class="octicon octicon-link"></span></a>Sesión de laboratorio:</h2>
  895. <h3>
  896. <a id="user-content-ejercicio-1-diseñar-pruebas-a-mano" class="anchor" href="#ejercicio-1-dise%C3%B1ar-pruebas-a-mano" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ejercicio 1: Diseñar pruebas "a mano"</h3>
  897. <p>En este ejercicio practicarás cómo diseñar pruebas para validar funciones, utilizando solamente la descripción de la función y la interfaz que se usa para interactuar con la función. </p>
  898. <p>El ejercicio <strong>NO requiere programación</strong>, solo requiere que entiendas la descripción de la función, y tu habilidad para diseñar pruebas. Este ejercicio y el Ejercicio 2 son una adaptación del ejercicio en [1].</p>
  899. <p><strong>Ejemplo 3.</strong> Supón que una amiga te provee un programa. Ella asegura que el programa resuelve el siguiente problema: </p>
  900. <p><code>"dados tres enteros, despliega el valor máximo".</code> </p>
  901. <p>Supón que el programa tienen una interfaz como la siguiente:</p>
  902. <hr>
  903. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure4.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure4.png" alt="figure4.png" style="max-width:100%;"></a></p>
  904. <p><strong>Figura 4</strong> - Interfaz de un programa para hallar el valor máximo entre tres enteros.</p>
  905. <hr>
  906. <p>Podrías determinar si el programa provee resultados válidos <strong>sin analizar el código fuente</strong>. Por ejemplo, podrías intentar los siguientes casos:</p>
  907. <ul>
  908. <li>a = 4, b = 2, c = 1; resultado esperado: 4</li>
  909. <li>a = 3, b = 6, c = 2; resultado esperado: 6</li>
  910. <li>a = 1, b = 10, c = 100; resultado esperado: 100</li>
  911. </ul>
  912. <p>Si alguno de estos tres casos no da el resultado esperado, el programa de tu amiga no funciona. Por otro lado, si los tres casos funcionan, entonces el programa tiene una probabilidad alta de estar correcto.</p>
  913. <h4>
  914. <a id="user-content-funciones-para-validar" class="anchor" href="#funciones-para-validar" aria-hidden="true"><span class="octicon octicon-link"></span></a>Funciones para validar</h4>
  915. <p>En este ejercicio estarás diseñando pruebas que validen varias versiones de las funciones que se describen abajo. Cada una de las funciones tiene cuatro versiones, "Alpha", "Beta", "Gamma" y "Delta".</p>
  916. <ul>
  917. <li>
  918. <p><strong>3 Sorts:</strong> una función que recibe tres "strings" y los ordena en orden lexicográfico (alfabético). Por ejemplo, dados <code>jirafa</code>, <code>zorra</code>, y <code>coqui</code>, los ordena como: <code>coqui</code>, <code>jirafa</code>, y <code>zorra</code>. Para simplificar el ejercicio, solo usaremos "strings" con letras minúsculas. La Figura 5 muestra la interfaz de esta función. Nota que hay un menú para seleccionar la versión implementada.</p>
  919. <hr>
  920. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure5.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure5.png" alt="figure5.png" style="max-width:100%;"></a></p>
  921. <p><strong>Figura 5</strong> - Interfaz de la función <code>3 Sorts</code>.</p>
  922. <hr>
  923. </li>
  924. <li>
  925. <p><strong>Dice:</strong> cuando el usuario marca el botón <code>Roll them!</code>, el programa genera dos números aleatorios entre 1 y 6. El programa informa la suma de los números aleatorios. </p>
  926. <hr>
  927. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure6.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure6.png" alt="figure6.png" style="max-width:100%;"></a></p>
  928. <p><strong>Figura 6</strong> - Interfaz de la función <code>Dice</code>.</p>
  929. <hr>
  930. </li>
  931. <li>
  932. <p><strong>Rock, Paper, Scissors:</strong> cada uno de los jugadores entra su jugada y el programa informa quién ganó. La Figura 7 muestra las opciones en las que un objeto le gana a otro. La interfaz del juego se muestra en la Figura 8.</p>
  933. <hr>
  934. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure7.jpg" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure7.jpg" alt="figure7.jpg" style="max-width:100%;"></a></p>
  935. <p><strong>Figura 7</strong> - Formas de ganar en el juego "Piedra, papel y tijera".</p>
  936. <hr>
  937. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure8.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure8.png" alt="figure8.png" style="max-width:100%;"></a></p>
  938. <p><strong>Figura 8</strong> - Interfaz de la función <code>Rock, Paper, Scissors</code>.</p>
  939. <hr>
  940. </li>
  941. <li>
  942. <p><strong>Zulu time:</strong> Dada una hora en tiempo Zulu (Hora en el Meridiano de Greenwich) y la zona militar en la que el usuario desea saber la hora, el programa muestra la hora en esa zona. El formato para el dato de entrada es en formato de 23 horas <code>####</code>, por ejemplo <code>2212</code> sería las 10:12 pm. La lista de zonas militares válidas la puedes encontrar en <a href="http://en.wikipedia.org/wiki/List_of_military_time_zones">http://en.wikipedia.org/wiki/List_of_military_time_zones</a>. Lo que sigue son ejemplos de cómo deben ser los resultados del programa:</p>
  943. <ul>
  944. <li>Dada hora Zulu 1230 y zona A (UTC+1), el resultado debe ser 1330.</li>
  945. <li>Dada hora Zulu 1230 y zona N (UTC-1), el resultado debe ser 1130.</li>
  946. <li>Puerto Rico está en la zona militar Q (UTC-4), por lo tanto, cuando es 1800 en hora Zulu, son las 1400 en Puerto Rico.</li>
  947. </ul>
  948. <hr>
  949. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure9.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure9.png" alt="figure9.png" style="max-width:100%;"></a></p>
  950. <p><strong>Figura 9</strong> - Interfaz de la función <code>Zulu time</code>.</p>
  951. <hr>
  952. </li>
  953. </ul>
  954. <h4>
  955. <a id="user-content-instrucciones" class="anchor" href="#instrucciones" aria-hidden="true"><span class="octicon octicon-link"></span></a>Instrucciones</h4>
  956. <ol>
  957. <li>
  958. <p>Para cada una de las funciones descritas arriba, escribe en tu libreta las pruebas que harás para determinar la validez de cada implementación (Alpha, Beta, Gamma y Delta). Para cada función, piensa en los errores lógicos que el programador pudo haber cometido y escribe pruebas que determinen si se cometió ese error. Para cada prueba, escribe los valores que utilizarás y el resultado que esperas obtener.</p>
  959. <p>Por ejemplo, puedes organizar tus respuestas en una tabla como la que sigue:</p>
  960. <hr>
  961. <table>
  962. <thead>
  963. <tr>
  964. <th>3 Sorts</th>
  965. <th></th>
  966. <th></th>
  967. <th></th>
  968. <th></th>
  969. <th></th>
  970. </tr>
  971. </thead>
  972. <tbody>
  973. <tr>
  974. <td>Num</td>
  975. <td>Prueba</td>
  976. <td>Result Alpha</td>
  977. <td>Res. Beta</td>
  978. <td>Res. Gamma</td>
  979. <td>Res. Delta</td>
  980. </tr>
  981. <tr>
  982. <td>1</td>
  983. <td>"alce", "coyote", "zorro"</td>
  984. <td>"alce", "coyote", "zorro"</td>
  985. <td>....</td>
  986. <td>....</td>
  987. <td></td>
  988. </tr>
  989. <tr>
  990. <td>2</td>
  991. <td>"alce", "zorro", "coyote"</td>
  992. <td>"zorro", "alce", "coyote"</td>
  993. <td>....</td>
  994. <td>....</td>
  995. <td></td>
  996. </tr>
  997. <tr>
  998. <td>....</td>
  999. <td>....</td>
  1000. <td>....</td>
  1001. <td>....</td>
  1002. <td>....</td>
  1003. <td>....</td>
  1004. </tr>
  1005. </tbody>
  1006. </table>
  1007. <p><strong>Figura 10</strong> - Tabla para organizar los resultados de las pruebas.</p>
  1008. <hr>
  1009. <p>Puedes ver ejemplos de cómo organizar tus resultados <a href="http://i.imgur.com/ggDZ3TQ.png">aquí</a> y <a href="http://i.imgur.com/rpApVqm.png">aquí</a>. </p>
  1010. </li>
  1011. </ol>
  1012. <h3>
  1013. <a id="user-content-ejercicio-2-hacer-pruebas-a-mano" class="anchor" href="#ejercicio-2-hacer-pruebas-a-mano" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ejercicio 2: Hacer pruebas "a mano"</h3>
  1014. <p>El proyecto <code>testing</code> implementa varias versiones de cada una de las cuatro funciones simples que se decribieron en el Ejercicio 1. Algunas o todas las implementaciones pueden estar incorrectas. Tu tarea es, usando las pruebas que diseñaste en el Ejercicio 1, probar las versiones de cada función para determinar cuáles de ellas, si alguna, están implementadas correctamente.</p>
  1015. <p>Este ejercicio <strong>NO requiere programación</strong>, debes hacer las pruebas <strong>sin mirar el código.</strong></p>
  1016. <h4>
  1017. <a id="user-content-instrucciones-1" class="anchor" href="#instrucciones-1" aria-hidden="true"><span class="octicon octicon-link"></span></a>Instrucciones</h4>
  1018. <ol>
  1019. <li><p>Carga a Qt el proyecto <code>Testing</code> haciendo doble "click" en el archivo <code>Testing.pro</code> en el directorio <code>Documents/eip/Testing</code> de tu computadora. También puedes ir a <code>http://bitbucket.org/eip-uprrp/testing</code> para descargar la carpeta <code>Testing</code> a tu computadora.</p></li>
  1020. <li>
  1021. <p>Configura el proyecto y corre el programa. Verás una pantalla similar a la siguiente:</p>
  1022. <hr>
  1023. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure11.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure11.png" alt="figure11.png" style="max-width:100%;"></a></p>
  1024. <p><strong>Figura 11</strong> - Ventana para seleccionar la función que se va a probar.</p>
  1025. <hr>
  1026. </li>
  1027. <li><p>Selecciona el botón de <code>3 Sorts</code> y obtendrás la interfaz de la Figura 5.</p></li>
  1028. <li><p>La "Version Alpha" en la caja indica que estás corriendo la primera versión del algoritmo <code>3 Sorts</code>. Usa las pruebas que escribiste en el Ejercicio 1 para validar la "Version Alpha". Luego, haz lo mismo para las versiones Beta, Gamma y Delta. Escribe cuáles son las versiones correctas (si alguna) de la función y porqué. Recuerda que, para cada función, algunas o todas las implementaciones pueden estar incorrectas. Además, especifica cuáles pruebas te permitieron determinar las versiones que son incorrectas.</p></li>
  1029. </ol>
  1030. <h3>
  1031. <a id="user-content-ejercicio-3-usar-assert-para-realizar-pruebas-unitarias" class="anchor" href="#ejercicio-3-usar-assert-para-realizar-pruebas-unitarias" aria-hidden="true"><span class="octicon octicon-link"></span></a>Ejercicio 3: Usar <code>assert</code> para realizar pruebas unitarias</h3>
  1032. <p>Hacer pruebas "a mano" cada vez que corres un programa es una tarea que resulta "cansona" bien rápido. En los ejercicios anteriores lo hiciste para unas pocas funciones simples. !Imagínate hacer lo mismo para un programa complejo completo como un buscador o un procesador de palabras!</p>
  1033. <p>Las <em>pruebas unitarias</em> ayudan a los programadores a validar códigos y simplificar el proceso de depuración ("debugging") a la vez que evitan la tarea tediosa de hacer pruebas a mano en cada ejecución.</p>
  1034. <h4>
  1035. <a id="user-content-instrucciones-2" class="anchor" href="#instrucciones-2" aria-hidden="true"><span class="octicon octicon-link"></span></a>Instrucciones:</h4>
  1036. <ol>
  1037. <li><p>En el menú de QT, ve a <code>Build</code> y selecciona <code>Clean Project "Testing"</code>.</p></li>
  1038. <li><p>Carga a Qt el proyecto <code>UnitTests</code> haciendo doble "click" en el archivo <code>UnitTests.pro</code> en el directorio <code>Documents/eip/Testing</code> de tu computadora. También puedes ir a <code>http://bitbucket.org/eip-uprrp/testing</code> para descargar la carpeta <code>Testing</code> a tu computadora.</p></li>
  1039. <li>
  1040. <p>El proyecto solo contiene el archivo de código fuente <code>main.cpp</code>. Este archivo contiene cuatro funciones: <code>fact</code>, <code>isALetter</code>, <code>isValidTime</code>, y <code>gcd</code>, cuyos resultados son solo parcialmente correctos. </p>
  1041. <p>Estudia la descripción de cada una de las funciones que aparece como comentarios antes el código de la función para saber la tarea que se espera haga la función.</p>
  1042. <p>Tu tarea es escribir pruebas unitarias para cada una de las funciones para identificar los resultados erróneos. ** No necesitas reescribir las funciones para corregirlas. **</p>
  1043. <p>Para la función <code>fact</code> se provee la función <code>test_fact()</code> como función de prueba unitaria. Si invocas esta función desde <code>main</code>, compilas y corres el programa debes obtener un mensaje como el siguiente:</p>
  1044. <p><code>Assertion failed: (fact(2) == 2), function test_fact, file ../UnitTests/ main.cpp, line 69.</code></p>
  1045. <p>Esto es suficiente para saber que la función <code>fact</code> NO está correctamente implementada. </p>
  1046. </li>
  1047. <li><p>Nota que, al fallar la prueba anterior, el programa no continuó su ejecución. Para poder probar el código que escribirás, comenta la invocación de <code>test_fact()</code> en <code>main</code>.</p></li>
  1048. <li><p>Escribe una prueba unitaria llamada <code>test_isALetter</code> para la función <code>isALetter</code>. En la prueba unitaria escribe varias afirmaciones ("asserts") para probar algunos datos de entrada y sus valores esperados (mira la función <code>test_fact</code> para que te inspires). Invoca <code>test_isALetter</code> desde <code>main</code> y ejecuta tu programa. Si la función <code>isALetter</code> pasa las pruebas que escribiste, continúa escribiendo "asserts" y ejecutando tu programa hasta que alguno de los <code>asserts</code> falle. </p></li>
  1049. <li><p>Comenta la invocación de <code>test_isALetter</code> en <code>main</code> para que puedas continuar con las otras funciones.</p></li>
  1050. <li><p>Repite los pasos 5 y 6 paras las otras dos funciones, <code>isValidTime</code> y <code>gcd</code>. Recuerda que debes llamar a cada una de las funciones de prueba unitaria desde <code>main</code> para que corran. </p></li>
  1051. </ol>
  1052. <hr>
  1053. <hr>
  1054. <h2>
  1055. <a id="user-content-entregas" class="anchor" href="#entregas" aria-hidden="true"><span class="octicon octicon-link"></span></a>Entregas</h2>
  1056. <ol>
  1057. <li><p>Utiliza "Entrega 1" en Moodle para entregar la tabla con las pruebas que diseñaste en el Ejercicio 1 y que completaste en el Ejercicio 2 con los resultados de las pruebas de las funciones.</p></li>
  1058. <li><p>Utiliza "Entrega 2" en Moodle para entregar el archivo <code>main.cpp</code> que contiene las funciones <code>test_isALetter</code>, <code>test_isValidTime</code>, <code>test_gcd</code> y sus invocaciones. Recuerda utilizar buenas prácticas de programación, incluir el nombre de los programadores y documentar tu programa.</p></li>
  1059. </ol>
  1060. <hr>
  1061. <hr>
  1062. <h2>
  1063. <a id="user-content-referencias" class="anchor" href="#referencias" aria-hidden="true"><span class="octicon octicon-link"></span></a>Referencias</h2>
  1064. <p>[1] <a href="http://nifty.stanford.edu/2005/TestMe/">http://nifty.stanford.edu/2005/TestMe/</a></p>
  1065. <hr>
  1066. <hr>
  1067. <hr>
  1068. <p><a href="#markdown-header-testing-and-unit-testing">English</a> | <a href="#markdown-header-pruebas-y-pruebas-unitarias">Español</a></p>
  1069. <h1>
  1070. <a id="user-content-testing-and-unit-testing" class="anchor" href="#testing-and-unit-testing" aria-hidden="true"><span class="octicon octicon-link"></span></a>Testing and Unit Testing</h1>
  1071. <p><a href="https://camo.githubusercontent.com/0130842aaebc4a0ecc5cb368730342cb64f26f62/687474703a2f2f64656d6f30352e636c6f7564696d6167652e696f2f732f726573697a652f3231352f692e696d6775722e636f6d2f44306c614935722e706e67" target="_blank"><img src="https://camo.githubusercontent.com/0130842aaebc4a0ecc5cb368730342cb64f26f62/687474703a2f2f64656d6f30352e636c6f7564696d6167652e696f2f732f726573697a652f3231352f692e696d6775722e636f6d2f44306c614935722e706e67" alt="" data-canonical-src="http://demo05.cloudimage.io/s/resize/215/i.imgur.com/D0laI5r.png" style="max-width:100%;"></a>
  1072. <a href="https://camo.githubusercontent.com/df63e580b9f4f8f36e211d7d73119da4b9b9b6a5/687474703a2f2f64656d6f30352e636c6f7564696d6167652e696f2f732f726573697a652f3231352f692e696d6775722e636f6d2f6767445a3354512e706e67" target="_blank"><img src="https://camo.githubusercontent.com/df63e580b9f4f8f36e211d7d73119da4b9b9b6a5/687474703a2f2f64656d6f30352e636c6f7564696d6167652e696f2f732f726573697a652f3231352f692e696d6775722e636f6d2f6767445a3354512e706e67" alt="" data-canonical-src="http://demo05.cloudimage.io/s/resize/215/i.imgur.com/ggDZ3TQ.png" style="max-width:100%;"></a>
  1073. <a href="https://camo.githubusercontent.com/b7887ab1723cd1330bddd867446d02940a4b83ce/687474703a2f2f64656d6f30352e636c6f7564696d6167652e696f2f732f726573697a652f3231352f692e696d6775722e636f6d2f563678466f30302e706e67" target="_blank"><img src="https://camo.githubusercontent.com/b7887ab1723cd1330bddd867446d02940a4b83ce/687474703a2f2f64656d6f30352e636c6f7564696d6167652e696f2f732f726573697a652f3231352f692e696d6775722e636f6d2f563678466f30302e706e67" alt="" data-canonical-src="http://demo05.cloudimage.io/s/resize/215/i.imgur.com/V6xFo00.png" style="max-width:100%;"></a></p>
  1074. <p>As you have learned in previous labs, getting a program to compile is only a minor part of programming. The compiler will tell you if there are syntactical errors, but it isn't capable of detecting logical problems in your program. It's very important to test the program's functions to validate that they produce correct results.</p>
  1075. <p>These tests can be performed by hand, this is, running the program multiple times, providing representative inputs and visually checking that the program outputs correct results. A more convenient way is to implement functions in the program whose sole purpose is to validate that other functions are working correctly. In this lab you will be practicing both testing methods.</p>
  1076. <h2>
  1077. <a id="user-content-objectives" class="anchor" href="#objectives" aria-hidden="true"><span class="octicon octicon-link"></span></a>Objectives:</h2>
  1078. <ol>
  1079. <li>Design tests to validate several programs “by-hand”, then use these tests to determine if the program works as expected. </li>
  1080. <li>Create unit tests to validate functions, using the <code>assert</code> function.</li>
  1081. </ol>
  1082. <h2>
  1083. <a id="user-content-pre-lab-1" class="anchor" href="#pre-lab-1" aria-hidden="true"><span class="octicon octicon-link"></span></a>Pre-Lab:</h2>
  1084. <p>Before you get to the laboratory you should have:</p>
  1085. <ol>
  1086. <li><p>Reviewed the basic concepts related to testing and unit tests.</p></li>
  1087. <li><p>Reviewed how to use the <code>assert</code> function to validate another function.</p></li>
  1088. <li><p>Studied the concepts and instructions for this laboratory session.</p></li>
  1089. <li><p>Taken the Pre-Lab quiz available in Moodle.</p></li>
  1090. </ol>
  1091. <hr>
  1092. <hr>
  1093. <h2>
  1094. <a id="user-content-testing-a-function" class="anchor" href="#testing-a-function" aria-hidden="true"><span class="octicon octicon-link"></span></a>Testing a function</h2>
  1095. <p>When we test a function's validity we should test cases that activate the various results the function could return.</p>
  1096. <hr>
  1097. <p><strong>Example 1:</strong> if you were to validate the function <code>isEven(unsigned int n)</code> that determines if a positive integer <em>n</em> is even, you should test the function using even and odd numbers. A set of tests for that function could be:</p>
  1098. <table>
  1099. <thead>
  1100. <tr>
  1101. <th>Test</th>
  1102. <th>Expected Result</th>
  1103. </tr>
  1104. </thead>
  1105. <tbody>
  1106. <tr>
  1107. <td><code>isEven(8)</code></td>
  1108. <td>true</td>
  1109. </tr>
  1110. <tr>
  1111. <td><code>isEven(7)</code></td>
  1112. <td>false</td>
  1113. </tr>
  1114. </tbody>
  1115. </table>
  1116. <hr>
  1117. <p><strong>Example 2:</strong> Suppose that a friend has created a function <code>unsigned int ageRange(unsigned int age)</code> that is supposed to return 0 if the age is between 0 and 5 (inclusive), 1 if the age is between 6 and 18 inclusive, and 2 if the age is above 18. A common source of errors in functions like this one are the values near to the limits of each range, for example, the number 5 can cause errors if the programmer did not use a correct comparison. One good set of tests for the <code>ageRange</code> function would be:</p>
  1118. <table>
  1119. <thead>
  1120. <tr>
  1121. <th>Test</th>
  1122. <th>Expected Result</th>
  1123. </tr>
  1124. </thead>
  1125. <tbody>
  1126. <tr>
  1127. <td><code>ageRange(5)</code></td>
  1128. <td>0</td>
  1129. </tr>
  1130. <tr>
  1131. <td><code>ageRange(2)</code></td>
  1132. <td>0</td>
  1133. </tr>
  1134. <tr>
  1135. <td><code>ageRange(6)</code></td>
  1136. <td>1</td>
  1137. </tr>
  1138. <tr>
  1139. <td><code>ageRange(18)</code></td>
  1140. <td>1</td>
  1141. </tr>
  1142. <tr>
  1143. <td><code>ageRange(17)</code></td>
  1144. <td>1</td>
  1145. </tr>
  1146. <tr>
  1147. <td><code>ageRange(19)</code></td>
  1148. <td>2</td>
  1149. </tr>
  1150. <tr>
  1151. <td><code>ageRange(25)</code></td>
  1152. <td>2</td>
  1153. </tr>
  1154. </tbody>
  1155. </table>
  1156. <hr>
  1157. <h3>
  1158. <a id="user-content-assert-function" class="anchor" href="#assert-function" aria-hidden="true"><span class="octicon octicon-link"></span></a><code>Assert</code> Function:</h3>
  1159. <p>The <code>assert(bool expression)</code> function can be used as a rudimentary tool to validate functions. <code>assert</code> has a very powerful yet simple functionality. If the expression that we place between the <code>assert</code> parenthesis is <em>true</em>, the function allows the program to continue onto the next instruction. Otherwise, if the expression we place between the parenthesis is <em>false</em>, the <code>assert</code> function causes the program to terminate and prints an error message on the terminal that informs the user about the <code>assert</code> instruction that failed.</p>
  1160. <p>For example, the following program will run from start to finish without problems since every expression included in the assert's parentheses evaluates to <em>true</em>.</p>
  1161. <hr>
  1162. <div class="highlight highlight-cpp"><pre>#<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>iostream<span class="pl-pds">&gt;</span></span>
  1163. #<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>cassert<span class="pl-pds">&gt;</span></span>
  1164. <span class="pl-k">using</span> <span class="pl-k">namespace</span> <span class="pl-en">std</span><span class="pl-k">;</span>
  1165. <span class="pl-k">int</span> <span class="pl-en">main</span>() {
  1166. <span class="pl-k">int</span> i = <span class="pl-c1">10</span>, j = <span class="pl-c1">15</span>;
  1167. <span class="pl-c1">assert</span>(i == <span class="pl-c1">10</span>);
  1168. <span class="pl-c1">assert</span>(j == i + <span class="pl-c1">5</span>);
  1169. <span class="pl-c1">assert</span>(j != i);
  1170. <span class="pl-c1">assert</span>( (j &lt; i) == <span class="pl-c1">false</span>);
  1171. cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>That's all, folks!<span class="pl-pds">"</span></span> &lt;&lt; endl;
  1172. <span class="pl-k">return</span> <span class="pl-c1">0</span>;
  1173. }
  1174. </pre></div>
  1175. <p><strong>Figure 1.</strong> Example of a program that passes all of the <code>assert</code> tests.</p>
  1176. <hr>
  1177. <p>The following program will not run to completion because the second <code>assert</code> (<code>assert(j == i);</code>) contains an expression (<code>j==i</code>) that evaluates to <em>false</em>.</p>
  1178. <hr>
  1179. <div class="highlight highlight-cpp"><pre>
  1180. #<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>iostream<span class="pl-pds">&gt;</span></span>
  1181. #<span class="pl-k">include</span> <span class="pl-s"><span class="pl-pds">&lt;</span>cassert<span class="pl-pds">&gt;</span></span>
  1182. <span class="pl-k">using</span> <span class="pl-k">namespace</span> <span class="pl-en">std</span><span class="pl-k">;</span>
  1183. <span class="pl-k">int</span> <span class="pl-en">main</span>() {
  1184. <span class="pl-k">int</span> i = <span class="pl-c1">10</span>, j = <span class="pl-c1">15</span>;
  1185. <span class="pl-c1">assert</span>(i == <span class="pl-c1">10</span>);
  1186. <span class="pl-c1">assert</span>(j == i);
  1187. <span class="pl-c1">assert</span>(j != i);
  1188. <span class="pl-c1">assert</span>( (j &lt; i) == <span class="pl-c1">false</span>);
  1189. cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>That's all, folks!<span class="pl-pds">"</span></span> &lt;&lt; endl;
  1190. <span class="pl-k">return</span> <span class="pl-c1">0</span>;
  1191. }
  1192. </pre></div>
  1193. <p><strong>Figure 2.</strong> Example of a program that does not pass an <code>assert</code> test.</p>
  1194. <hr>
  1195. <p>When the program is run, instead of getting the phrase <code>”That's all, folks!”</code> in the terminal, we will obtain something like:</p>
  1196. <p><code>Assertion failed: (j == i), function main, file ../program01/main.cpp, line 8.</code></p>
  1197. <p>The program will not execute the remaining instructions after line 8.</p>
  1198. <h4>
  1199. <a id="user-content-how-to-use-assert-to-validate-functions" class="anchor" href="#how-to-use-assert-to-validate-functions" aria-hidden="true"><span class="octicon octicon-link"></span></a>How to use assert to validate functions?</h4>
  1200. <p>Suppose that you want to automate the validation of the <code>ageRange</code>. One way to do it is by implementing and calling a function that calls the <code>ageRange</code> function with different arguments and verifies that each returned value is equal to the expected result. If the <code>ageRange</code> function returns a value that is not expected, the testing function aborts the program and reports the test that failed. The following illustrates a function to test the <code>ageRange</code> function. Observe that it consists of one assert per each of the tests we had listed earlier. </p>
  1201. <hr>
  1202. <div class="highlight highlight-cpp"><pre><span class="pl-k">void</span> <span class="pl-en">test_ageRange</span>() {
  1203. <span class="pl-c1">assert</span>(<span class="pl-c1">ageRange</span>(<span class="pl-c1">5</span>) == <span class="pl-c1">0</span>);
  1204. <span class="pl-c1">assert</span>(<span class="pl-c1">ageRange</span>(<span class="pl-c1">2</span>) == <span class="pl-c1">0</span>);
  1205. <span class="pl-c1">assert</span>(<span class="pl-c1">ageRange</span>(<span class="pl-c1">6</span>) == <span class="pl-c1">1</span>);
  1206. <span class="pl-c1">assert</span>(<span class="pl-c1">ageRange</span>(<span class="pl-c1">18</span>) == <span class="pl-c1">1</span>);
  1207. <span class="pl-c1">assert</span>(<span class="pl-c1">ageRange</span>(<span class="pl-c1">17</span>) == <span class="pl-c1">1</span>);
  1208. <span class="pl-c1">assert</span>(<span class="pl-c1">ageRange</span>(<span class="pl-c1">19</span>) == <span class="pl-c1">2</span>);
  1209. <span class="pl-c1">assert</span>(<span class="pl-c1">ageRange</span>(<span class="pl-c1">25</span>) == <span class="pl-c1">2</span>);
  1210. cout &lt;&lt; <span class="pl-s"><span class="pl-pds">"</span>ageRange passed all tests!!!<span class="pl-pds">"</span></span> &lt;&lt; endl;
  1211. }</pre></div>
  1212. <p><strong>Figure 3.</strong> Example of a test function using <code>assert</code>.</p>
  1213. <hr>
  1214. <hr>
  1215. <h2>
  1216. <a id="user-content-laboratory-session" class="anchor" href="#laboratory-session" aria-hidden="true"><span class="octicon octicon-link"></span></a>Laboratory Session:</h2>
  1217. <h3>
  1218. <a id="user-content-exercise-1-designing-tests-by-hand" class="anchor" href="#exercise-1-designing-tests-by-hand" aria-hidden="true"><span class="octicon octicon-link"></span></a>Exercise 1: Designing tests by hand</h3>
  1219. <p>In this exercise you will practice how to design tests to validate functions, using only the function's description and the graphical user interface that is used interact with the function.</p>
  1220. <p>The exercise <strong>DOES NOT require programming</strong>, it only requires that you understand the function’s description, and your ability to design tests. This exercise and Exercise 2 are an adaptation of the exercise in [1].</p>
  1221. <p><strong>Example 3</strong> Suppose that a friend provides you with a program. She makes sure the program solves the following problem:</p>
  1222. <p><code>"given three integers, it displays the max value".</code></p>
  1223. <p>Suppose that the program has an interface like the following:</p>
  1224. <hr>
  1225. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure4.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure4.png" alt="figure4.png" style="max-width:100%;"></a></p>
  1226. <p><strong>Figure 4</strong> - Interface for a program that finds the max value out of three integers.</p>
  1227. <hr>
  1228. <p>You could determine if the program provides valid results <strong>without analyzing the source code</strong>. For example, you could try the following cases:</p>
  1229. <ul>
  1230. <li>a = 4, b = 2, c = 1; expected result: 4</li>
  1231. <li>a = 3, b = 6, c = 2; expected result: 6</li>
  1232. <li>a = 1, b = 10, c = 100; expected result: 100</li>
  1233. </ul>
  1234. <p>If one of these three cases does not have the expected result, your friend's program does not work. On the other hand, if the three cases work, then the program has a high probability of being correct.</p>
  1235. <h4>
  1236. <a id="user-content-functions-to-validate" class="anchor" href="#functions-to-validate" aria-hidden="true"><span class="octicon octicon-link"></span></a>Functions to validate</h4>
  1237. <p>In this exercise you will be designing tests to validate various versions of the functions that are described below. Each one of the functions has four versions, "Alpha", "Beta", "Gamma" and "Delta".</p>
  1238. <ul>
  1239. <li>
  1240. <p><strong>3 Sorts:</strong> a function that receives three strings and orders them in lexicographic (alphabetical) order. For example, given <code>giraffe</code>, <code>fox</code>, and <code>coqui</code>, it would order them as: <code>coqui</code>, <code>fox</code>, and <code>giraffe</code>. To simplify the exercise, we will be using strings with lowercase <strong>letters</strong>. Figure 5 shows the function's interface. Notice there is a menu to select the implemented version.</p>
  1241. <hr>
  1242. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure5.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure5.png" alt="figure5.png" style="max-width:100%;"></a></p>
  1243. <p><strong>Figure 5</strong> - Interface for the <code>3 Sorts</code> function.</p>
  1244. <hr>
  1245. </li>
  1246. <li>
  1247. <p><strong>Dice:</strong> when the user presses the <code>Roll them!</code> button, the program generates two random integers between 1 and 6. The program informs the sum of the two random numbers.</p>
  1248. <hr>
  1249. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure6.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure6.png" alt="figure6.png" style="max-width:100%;"></a></p>
  1250. <p><strong>Figure 6</strong> - Interface for the <code>Dice</code> function.</p>
  1251. <hr>
  1252. </li>
  1253. <li>
  1254. <p><strong>Rock, Paper, Scissors:</strong> each one of the players enters their play and the program informs who the winner is. Figure 7 shows the options where one object beats the other. The game's interface is shown in Figure 8.</p>
  1255. <hr>
  1256. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure7.jpg" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure7.jpg" alt="figure7.jpg" style="max-width:100%;"></a></p>
  1257. <p><strong>Figure 7</strong> - Ways to win in "Rock, paper, scissors".</p>
  1258. <hr>
  1259. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure8.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure8.png" alt="figure8.png" style="max-width:100%;"></a></p>
  1260. <p><strong>Figure 8</strong> - Interface for the <code>Rock, Paper, Scissors</code> function.</p>
  1261. <hr>
  1262. </li>
  1263. <li>
  1264. <p><strong>Zulu time:</strong> Given a time in Zulu format (time at the Greenwich Meridian) and the military zone in which the user wants to know the time, the program shows the time in that zone. The format for the entry data is in the 24 hour format <code>####</code>, for example <code>2212</code> would be 10:12pm. The list of valid military zones can be found in <a href="http://en.wikipedia.org/wiki/List_of_military_time_zones">http://en.wikipedia.org/wiki/List_of_military_time_zones</a>. The following are examples of some valid results:</p>
  1265. <ul>
  1266. <li>Given Zulu time 1230 and zone A (UTC+1), the result should be 1330.</li>
  1267. <li>Given Zulu time 1230 and zone N (UTC-1), the result should be 1130.</li>
  1268. <li>Puerto Rico is in military zone Q (UTC-4), therefore, when its 1800 in Zulu time, it's 1400 in Puerto Rico.</li>
  1269. </ul>
  1270. <hr>
  1271. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure9.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure9.png" alt="figure9.png" style="max-width:100%;"></a></p>
  1272. <p><strong>Figure 9</strong> - Interface for the <code>Zulu time</code> function.</p>
  1273. <hr>
  1274. </li>
  1275. </ul>
  1276. <h4>
  1277. <a id="user-content-instructions" class="anchor" href="#instructions" aria-hidden="true"><span class="octicon octicon-link"></span></a>Instructions</h4>
  1278. <ol>
  1279. <li>
  1280. <p>For each of the functions described above, write in your notebook the tests that you will do to determine the validity of each implementation (Alpha, Beta, Gamma and Delta). For each function, think of the logical errors that the programmer could have made and write tests that determine if these errors were made. For each test, write the values that you will use and the expected result.</p>
  1281. <p>For example, you could organize your answers in a table like the following:</p>
  1282. <hr>
  1283. <table>
  1284. <thead>
  1285. <tr>
  1286. <th>3 Sorts</th>
  1287. <th></th>
  1288. <th></th>
  1289. <th></th>
  1290. <th></th>
  1291. <th></th>
  1292. </tr>
  1293. </thead>
  1294. <tbody>
  1295. <tr>
  1296. <td>Num</td>
  1297. <td>Test</td>
  1298. <td>Alpha Result</td>
  1299. <td>Beta Result</td>
  1300. <td>Gamma Result</td>
  1301. <td>Delta Result</td>
  1302. </tr>
  1303. <tr>
  1304. <td>1</td>
  1305. <td>"deer", "coyote", "fox"</td>
  1306. <td>"coyote", "deer", "fox"</td>
  1307. <td>....</td>
  1308. <td>....</td>
  1309. <td></td>
  1310. </tr>
  1311. <tr>
  1312. <td>2</td>
  1313. <td>"deer", "fox", "coyote"</td>
  1314. <td>"fox", "deer", "coyote"</td>
  1315. <td>....</td>
  1316. <td>....</td>
  1317. <td></td>
  1318. </tr>
  1319. <tr>
  1320. <td>....</td>
  1321. <td>....</td>
  1322. <td>....</td>
  1323. <td>....</td>
  1324. <td>....</td>
  1325. <td>....</td>
  1326. </tr>
  1327. </tbody>
  1328. </table>
  1329. <p><strong>Figure 10</strong> - Table to organize the test results.</p>
  1330. <hr>
  1331. </li>
  1332. </ol>
  1333. <p>You can see examples of how to organize your results <a href="http://i.imgur.com/ggDZ3TQ.png">here</a> and <a href="http://i.imgur.com/rpApVqm.png">here</a>.</p>
  1334. <h3>
  1335. <a id="user-content-exercise-2-doing-tests-by-hand" class="anchor" href="#exercise-2-doing-tests-by-hand" aria-hidden="true"><span class="octicon octicon-link"></span></a>Exercise 2: Doing tests “by hand”</h3>
  1336. <p>The <code>testing</code> project implements several versions of each of the four functions that were described in Exercise 1. Some or all of the implementations could be incorrect. Your task is, using the tests you designed in Exercise 1, to test the versions for each function to determine which of them, if any, are implemented correctly.</p>
  1337. <p>This exercise <strong>DOES NOT require programming</strong>, you should make the tests <strong>without looking at the code.</strong></p>
  1338. <h4>
  1339. <a id="user-content-instructions-1" class="anchor" href="#instructions-1" aria-hidden="true"><span class="octicon octicon-link"></span></a>Instructions</h4>
  1340. <ol>
  1341. <li><p>Load the <code>Testing</code> project onto Qt by double clicking the <code>Testing.pro</code> file in the <code>Documents/eip/Testing</code> directory on your computer. You can also go to <code>http://bitbucket.org/eip-uprrp/testing</code> to downloaded the <code>Testing</code> folder on your computer.</p></li>
  1342. <li>
  1343. <p>Configure the project and run the program. You will see a window similar to the following:</p>
  1344. <hr>
  1345. <p><a href="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure11.png" target="_blank"><img src="/Users/Ivelisse/Dropbox/eip/EIP-REVISION-VERANO/Testing/Testing-Edited-WithSolutions-July2015/images/figure11.png" alt="figure11.png" style="max-width:100%;"></a></p>
  1346. <p><strong>Figure 11</strong> - Window to select the function that will be tested.</p>
  1347. <hr>
  1348. </li>
  1349. <li><p>Select the button for <code>3 Sorts</code> and you will obtain the interface in Figure 5.</p></li>
  1350. <li><p>The "Alpha Version" in the box indicates that you're running the first version of the <code>3 Sorts</code> algorithm. Use the tests that you wrote in Exercise 1 to validate the "Alpha Version". Afterwards, do the same with the Beta, Gamma and Delta versions. Write down which are the correct versions of the function (if any), and why. Remember that, for each function, some or all of the implementations could be incorrect. Additionally, specify which tests allowed you to determine the incorrect versions.</p></li>
  1351. </ol>
  1352. <h3>
  1353. <a id="user-content-exercise-3-using-assert-to-make-unit-tests" class="anchor" href="#exercise-3-using-assert-to-make-unit-tests" aria-hidden="true"><span class="octicon octicon-link"></span></a>Exercise 3: Using <code>assert</code> to make unit tests</h3>
  1354. <p>Doing tests by hand each time you run a program is a tiresome task. In the previous exercises you did it for a few simple functions. Imagine doing the same for a complex program like a search engine or a word processor.</p>
  1355. <p><em>Unit tests</em> help programmers validate code and simplify the process of debugging while avoiding having to do these tests by hand in each execution.</p>
  1356. <h4>
  1357. <a id="user-content-instructions-2" class="anchor" href="#instructions-2" aria-hidden="true"><span class="octicon octicon-link"></span></a>Instructions:</h4>
  1358. <ol>
  1359. <li><p>In the Qt menu, go to <code>Build</code> and select <code>Clean Project "Testing"</code>.</p></li>
  1360. <li><p>Load the <code>UnitTests</code> project onto Qt by double clicking the <code>UnitTests.pro</code> file in the <code>Documents/eip/Testing</code> directory on your computer. You can also go to <code>http://bitbucket.org/eip-uprrp/testing</code> to download the <code>Testing</code> folder on your computer.</p></li>
  1361. <li>
  1362. <p>The project only contains the source code file <code>main.cpp</code>. This file contains four functions: <code>fact</code>, <code>isALetter</code>, <code>isValidTime</code>, and <code>gcd</code>, whose results are only partially correct.</p>
  1363. <p>Study the description of each function that appears as a comment before the function's code to understand the task that the function is supposed to carry out.</p>
  1364. <p>Your task is to write unit tests for each of the functions to identify the erroneous results. <strong>You do not need to rewrite the functions to correct them.</strong></p>
  1365. <p>For the <code>fact</code> function, a <code>test_fact()</code> is provided as a unit test function. If you invoke the function from <code>main</code>, compile and run the program you should obtain a message like the following:</p>
  1366. <p><code>Assertion failed: (fact(2) == 2), function test_fact, file ../UnitTests/ main.cpp, line 69.</code></p>
  1367. <p>This is evidence enough to establish that the <code>fact</code> function is NOT correctly implemented.</p>
  1368. </li>
  1369. <li><p>Notice that, by failing the previous test, the program did not continue its execution. To test the code you will write, comment the <code>test_fact()</code> call in <code>main</code>.</p></li>
  1370. <li><p>Write a unit test called <code>test_isALetter</code> for the <code>isALetter</code> function. Write various asserts in the unit test to try some data and its expected values (use the <code>test_fact</code> function for inspiration). Invoke <code>test_isALetter</code> from <code>main</code> and execute your program. If the <code>isALetter</code> function passes the test you wrote, continue writing asserts and executing the program until one of them fails.</p></li>
  1371. <li><p>Comment the <code>test_isALetter</code> call in <code>main</code> so you can continue with the other functions.</p></li>
  1372. <li><p>Repeat the steps in 5 and 6 for the other two functions, <code>isValidTime</code> and <code>gcd</code>. Remember that you should call each of the unit test functions from <code>main</code> for them to run. </p></li>
  1373. </ol>
  1374. <hr>
  1375. <hr>
  1376. <h2>
  1377. <a id="user-content-deliverables" class="anchor" href="#deliverables" aria-hidden="true"><span class="octicon octicon-link"></span></a>Deliverables</h2>
  1378. <ol>
  1379. <li><p>Use "Deliverables 1" in Moodle to hand in the table with the tests you designed in Exercise 1 and that you completed in Exercise 2 with the results from the function tests.</p></li>
  1380. <li><p>Use "Deliverables 2" in Moodle to hand in the <code>main.cpp</code> file that contains the <code>test_isALetter</code>, <code>test_isValidTime</code>, <code>test_gcd</code> functions and their calls. Remember to use good programming techniques, include the name of the programmers involved and document your program.</p></li>
  1381. </ol>
  1382. <hr>
  1383. <hr>
  1384. <h2>
  1385. <a id="user-content-references" class="anchor" href="#references" aria-hidden="true"><span class="octicon octicon-link"></span></a>References</h2>
  1386. <p>[1] <a href="http://nifty.stanford.edu/2005/TestMe/">http://nifty.stanford.edu/2005/TestMe/</a></p>
  1387. <hr>
  1388. <hr>
  1389. <hr>
  1390. </article></body></html>