"use strict";(self.webpackChunkfi=self.webpackChunkfi||[]).push([[3095],{3905:(e,t,n)=>{n.d(t,{Zo:()=>u,kt:()=>k});var a=n(7294);function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var s=a.createContext({}),p=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},u=function(e){var t=p(e.components);return a.createElement(s.Provider,{value:t},e.children)},m="mdxType",c={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},d=a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,i=e.originalType,s=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),m=p(n),d=r,k=m["".concat(s,".").concat(d)]||m[d]||c[d]||i;return n?a.createElement(k,o(o({ref:t},u),{},{components:n})):a.createElement(k,o({ref:t},u))}));function k(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=n.length,o=new Array(i);o[0]=d;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l[m]="string"==typeof e?e:r,o[1]=l;for(var p=2;p{n.r(t),n.d(t,{assets:()=>s,contentTitle:()=>o,default:()=>c,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var a=n(7462),r=(n(7294),n(3905));const i={id:"seminar-10",title:"10th seminar",description:"Finding bugs in a hangman.\n"},o=void 0,l={unversionedId:"bonuses/seminar-10",id:"bonuses/seminar-10",title:"10th seminar",description:"Finding bugs in a hangman.\n",source:"@site/pb071/bonuses/10.md",sourceDirName:"bonuses",slug:"/bonuses/seminar-10",permalink:"/pb071/bonuses/seminar-10",draft:!1,editUrl:"https://github.com/mfocko/blog/tree/main/pb071/bonuses/10.md",tags:[],version:"current",lastUpdatedAt:1694959505,formattedLastUpdatedAt:"Sep 17, 2023",frontMatter:{id:"seminar-10",title:"10th seminar",description:"Finding bugs in a hangman.\n"},sidebar:"autogeneratedBar",previous:{title:"8th seminar",permalink:"/pb071/bonuses/seminar-08"},next:{title:"Practice Exams",permalink:"/pb071/category/practice-exams"}},s={},p=[{value:"Introduction",id:"introduction",level:2},{value:"Project",id:"project",level:2},{value:"Summary of the gameplay",id:"summary-of-the-gameplay",level:3},{value:"Suggested workflow",id:"suggested-workflow",level:2},{value:"Tasks",id:"tasks",level:2},{value:"Dictionary",id:"dictionary",level:2},{value:"Submitting",id:"submitting",level:2}],u={toc:p},m="wrapper";function c(e){let{components:t,...i}=e;return(0,r.kt)(m,(0,a.Z)({},u,i,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("p",null,(0,r.kt)("a",{parentName:"p",href:"pathname:///files/pb071/bonuses/10.tar.gz"},"Source")),(0,r.kt)("h2",{id:"introduction"},"Introduction"),(0,r.kt)("p",null,"For this bonus you are given almost finished project - The Hangman Game. Your\ntask is to try the game, in case you find any bugs point them out and cover as\nmuch of the game as possible with tests."),(0,r.kt)("p",null,"For this bonus you can get at maximum 2 K\u20a1."),(0,r.kt)("table",null,(0,r.kt)("thead",{parentName:"table"},(0,r.kt)("tr",{parentName:"thead"},(0,r.kt)("th",{parentName:"tr",align:null},"Item"),(0,r.kt)("th",{parentName:"tr",align:null},"Bonus"))),(0,r.kt)("tbody",{parentName:"table"},(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Fixing bugs from failing tests"),(0,r.kt)("td",{parentName:"tr",align:null},"0.25")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},(0,r.kt)("inlineCode",{parentName:"td"},"word_guessed")),(0,r.kt)("td",{parentName:"tr",align:null},"0.50")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Hidden bug"),(0,r.kt)("td",{parentName:"tr",align:null},"0.50")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Extending tests, undetectable bugs or evil bug"),(0,r.kt)("td",{parentName:"tr",align:null},"0.37")),(0,r.kt)("tr",{parentName:"tbody"},(0,r.kt)("td",{parentName:"tr",align:null},"Refactor"),(0,r.kt)("td",{parentName:"tr",align:null},"0.38")))),(0,r.kt)("h2",{id:"project"},"Project"),(0,r.kt)("p",null,"Project consists of 2 source files - ",(0,r.kt)("inlineCode",{parentName:"p"},"hangman.c")," and ",(0,r.kt)("inlineCode",{parentName:"p"},"main.c"),"."),(0,r.kt)("p",null,(0,r.kt)("inlineCode",{parentName:"p"},"main.c")," is quite short and concise, there is nothing for you to do."),(0,r.kt)("p",null,(0,r.kt)("inlineCode",{parentName:"p"},"hangman.c")," contains implementation of the game. In case you feel lost, consult\nthe documentation in ",(0,r.kt)("inlineCode",{parentName:"p"},"hangman.h")," that represents an interface that can be used\nfor implementing the game."),(0,r.kt)("p",null,"Apart from those sources this project is a bit more complicated. ",(0,r.kt)("em",{parentName:"p"},"Game loop")," is\nrealised via single encapsulated function that complicates the testing. Because\nof that, there are 2 kinds of tests:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("em",{parentName:"p"},"Unit tests")," - that are present in ",(0,r.kt)("inlineCode",{parentName:"p"},"test_hangman.c")," and can be run via:"),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre"},"$ make check-unit\n")),(0,r.kt)("p",{parentName:"li"},"They cover majorly functions that can be tested easily via testing framework.")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("p",{parentName:"li"},(0,r.kt)("em",{parentName:"p"},"Functional tests")," - same as in ",(0,r.kt)("inlineCode",{parentName:"p"},"seminar-08")," and are focused on testing the\nprogram as whole. Basic smoke test is already included in ",(0,r.kt)("inlineCode",{parentName:"p"},"usage")," test case."),(0,r.kt)("p",{parentName:"li"},"They can be run via:"),(0,r.kt)("pre",{parentName:"li"},(0,r.kt)("code",{parentName:"pre"},"$ make check-functional\n")),(0,r.kt)("p",{parentName:"li"},"When testing ",(0,r.kt)("inlineCode",{parentName:"p"},"hangman")," function (the game loop), it is suggested to create\nfunctional tests."),(0,r.kt)("p",{parentName:"li"},"When submitting the files for review, please leave out functional tests that\nwere given as a part of the assignment, so that it is easier to navigate, I\nwill drag the common files myself. :)"))),(0,r.kt)("blockquote",null,(0,r.kt)("p",{parentName:"blockquote"},"Whole test suite can be run via:"),(0,r.kt)("pre",{parentName:"blockquote"},(0,r.kt)("code",{parentName:"pre"},"$ make check\n"))),(0,r.kt)("h3",{id:"summary-of-the-gameplay"},"Summary of the gameplay"),(0,r.kt)("ol",null,(0,r.kt)("li",{parentName:"ol"},"Secret word gets chosen from the file that's path is given as an argument."),(0,r.kt)("li",{parentName:"ol"},"You get 8 guesses."),(0,r.kt)("li",{parentName:"ol"},"Invalid characters don't count."),(0,r.kt)("li",{parentName:"ol"},"Already guessed characters don't count, even if not included in the secret."),(0,r.kt)("li",{parentName:"ol"},"You can guess the whole word at once",(0,r.kt)("ul",{parentName:"li"},(0,r.kt)("li",{parentName:"ul"},"If you get it right, you won, game ends."),(0,r.kt)("li",{parentName:"ul"},"If you don't get it right, you get to see the secret, game ends."))),(0,r.kt)("li",{parentName:"ol"},"In case of end of input, game finishes via force."),(0,r.kt)("li",{parentName:"ol"},"In case of invalid input, no guesses are subtracted, game carries on."),(0,r.kt)("li",{parentName:"ol"},"Letters and words are not case sensitive.")),(0,r.kt)("h2",{id:"suggested-workflow"},"Suggested workflow"),(0,r.kt)("p",null,"As we have talked about on the seminar, I suggest you to follow\n",(0,r.kt)("em",{parentName:"p"},"Test-Driven Development"),"\nin this case."),(0,r.kt)("p",null,(0,r.kt)("img",{alt:"TDD workflow",src:n(1530).Z,width:"2814",height:"1652"})),(0,r.kt)("p",null,"In our current scenario we are already in the stage of refactoring and fixing the\nbugs. Therefore try to follow this succession of steps:"),(0,r.kt)("ol",null,(0,r.kt)("li",{parentName:"ol"},"Try to reproduce the bug."),(0,r.kt)("li",{parentName:"ol"},"Create a test that proves the presence of the bug."),(0,r.kt)("li",{parentName:"ol"},"Fix the bug.")),(0,r.kt)("p",null,"In case you are submitting the bonus via GitLab, it is helpful to commit tests\nbefore commiting the fixes, so that it is apparent that the bug is manifested.\nExample of ",(0,r.kt)("inlineCode",{parentName:"p"},"git log")," (notice that the first line represents latest commit):"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre"},"feat: Implement fizz_buzzer\ntest: Add tests for fizz_buzzer\nfix: Fix NULL-check in print_name\ntest: Add test for NULL in print_name\n")),(0,r.kt)("h2",{id:"tasks"},"Tasks"),(0,r.kt)("p",null,"As to your tasks, there are multiple things wrong in this project."),(0,r.kt)("ol",null,(0,r.kt)("li",{parentName:"ol"},(0,r.kt)("p",{parentName:"li"},'There are 2 "bugs" that cannot be detected via tests, i.e. they are not bugs\nthat affect functionality of the game.')),(0,r.kt)("li",{parentName:"ol"},(0,r.kt)("p",{parentName:"li"},"There is one evil bug in ",(0,r.kt)("inlineCode",{parentName:"p"},"get_word"),". It is not required to be fixed ;) Assign\nit the lowest priority.")),(0,r.kt)("li",{parentName:"ol"},(0,r.kt)("p",{parentName:"li"},"There are some tests failing. Please try to figure it out, so you have green\ntests for the rest :)")),(0,r.kt)("li",{parentName:"ol"},(0,r.kt)("p",{parentName:"li"},"We have gotten a bug report for ",(0,r.kt)("inlineCode",{parentName:"p"},"word_guessed"),", all we got is"),(0,r.kt)("blockquote",{parentName:"li"},(0,r.kt)("p",{parentName:"blockquote"},"doesn't work when there are too many ",(0,r.kt)("inlineCode",{parentName:"p"},"a"),"s")),(0,r.kt)("p",{parentName:"li"},"Please try to replicate the bug and create a tests, so we don't get any\nregression later on.")),(0,r.kt)("li",{parentName:"ol"},(0,r.kt)("p",{parentName:"li"},"One hidden bug :) Closely non-specified, we cannot reproduce it and we were\ndrunk while playing the game, so we don't remember a thing. :/")),(0,r.kt)("li",{parentName:"ol"},(0,r.kt)("p",{parentName:"li"},"Try to cover as much code via the tests as possible. We are not going to look\nat the metrics, but DRY is violated a lot, so as a last task try to remove as\nmuch of the duplicit code as possible."),(0,r.kt)("p",{parentName:"li"},"Tests should help you a lot in case there are some regressions."))),(0,r.kt)("hr",null),(0,r.kt)("p",null,"In case you wonder why there are always 3 same words in the file with words, it\nis because of the ",(0,r.kt)("inlineCode",{parentName:"p"},"get_word")," bug. It is not a bug that can be easily fixed, so\nit is a not requirement at all and you can still get all points for the bonus ;)"),(0,r.kt)("h2",{id:"dictionary"},"Dictionary"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://en.wikipedia.org/wiki/Functional_testing"},"Functional tests")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://en.wikipedia.org/wiki/Smoke_testing_%28software%29"},"Smoke test")),(0,r.kt)("li",{parentName:"ul"},(0,r.kt)("a",{parentName:"li",href:"https://en.wikipedia.org/wiki/Don%27t_repeat_yourself"},"DRY"))),(0,r.kt)("h2",{id:"submitting"},"Submitting"),(0,r.kt)("p",null,"In case you have any questions, feel free to reach out to me."),(0,r.kt)("hr",null))}c.isMDXComponent=!0},1530:(e,t,n)=>{n.d(t,{Z:()=>a});const a=n.p+"assets/images/tdd_lifecycle-327ad9ee0ed8318ed11e19a28e02b2cc.png"}}]);