{"base":{"id":"cs10-21","subject":"Programming","title":"Validation, verification and test data","scene":"mix","steps":[{"use":"cs10t3","mode":"validate","eyebrow":"Validation","title":"Is the data sensible?","body":"Validation is an automatic check that data is reasonable before a program uses it. Try each kind of check.","actions":[{"id":"presence","label":"Presence"},{"id":"range","label":"Range"},{"id":"length","label":"Length"},{"id":"type","label":"Type"},{"id":"format","label":"Format"}]},{"use":"cs10t3","mode":"verify","eyebrow":"Verification","title":"Was it copied correctly?","body":"Verification checks that data has been entered exactly as in the original. Try double entry and a visual check.","actions":[{"id":"double","label":"Double entry"},{"id":"visual","label":"Visual check"}]},{"use":"py9","mode":"testkinds","eyebrow":"Kinds of test data","title":"Normal, boundary, extreme, abnormal","body":"Good testing uses several kinds of data: normal values, values at the edges (boundary/extreme), and values that should be rejected (abnormal)."},{"use":"py9","mode":"testplan","eyebrow":"A test plan","title":"Expected vs actual","body":"A test plan lists each test, the data, the expected result and the actual result. Run one test, then all of them.","actions":[{"id":"one","label":"Run one test"},{"id":"all","label":"Run all tests"},{"id":"reset","label":"Reset"}]},{"use":"cs10t3","mode":"quiz","look":"validate","eyebrow":"Check yourself","title":"Which check?","body":"A form asks for a month number. It should reject 0 and 13.","question":"Which validation check is most suitable?","options":["A presence check","A range check","A length check"],"answer":1,"right":"Correct. A range check accepts 1 to 12 only.","wrong":"Not quite. Think about upper and lower limits."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","items":[{"tag":"Range","title":"Pseudocode","body":"REPEAT\n  INPUT mark\n  IF mark < 0 OR mark > 100 THEN\n    OUTPUT \"Mark must be 0 to 100\"\n  ENDIF\nUNTIL mark >= 0 AND mark <= 100","code":true},{"tag":"Python","title":"Length check","body":"pw = input(\"Password: \")\nwhile len(pw) < 8 or len(pw) > 20:\n    pw = input(\"8 to 20 characters: \")","code":true},{"tag":"Test data","title":"Age accepted from 11 to 18","body":"normal:     14, 16\nboundary:   11, 18 (accept), 10, 19 (reject)\nabnormal:   \"twelve\", -5","code":true},{"tag":"Presence","title":"Python","body":"name = input(\"Name: \").strip()\nwhile name == \"\":\n    name = input(\"Please enter a name: \")","code":true}]},{"type":"cards","id":"detail","eyebrow":"The ideas in detail","title":"Validation checks","items":[{"tag":"Presence","title":"Something entered","body":"Rejects empty fields. Example: a username must not be blank."},{"tag":"Range","title":"Between limits","body":"Rejects values outside lower and upper limits. Example: 1 ≤ month ≤ 12."},{"tag":"Length","title":"Number of characters","body":"Example: a password of 8 to 20 characters; a phone number of exactly 11 digits."},{"tag":"Type","title":"Right kind of data","body":"Example: a quantity must be an integer, not text or a decimal."},{"tag":"Format","title":"Matches a pattern","body":"Example: a date like DD/MM/YYYY, or a product code of two letters then four digits."},{"tag":"Check digit","title":"Extra digit from a calculation","body":"The last digit of a barcode or ISBN is calculated from the others. Scanners recalculate it to catch typing errors."}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"Thinking validation makes data correct","body":"Validation only checks data is reasonable. \"Smith\" can be valid but still the wrong name."},{"tag":"Mistake","title":"Testing only normal data","body":"Most bugs hide at the boundaries. Always test both sides of each limit."},{"tag":"Mistake","title":"Mixing up validation and verification","body":"Validation: is it sensible? Verification: does it match the original?"},{"tag":"Mistake","title":"Forgetting to re-ask","body":"After rejecting data, the program should ask again, usually inside a loop."}]},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"Real world","title":"ISBN check digits","body":"For a 13-digit ISBN, multiply digits alternately by 1 and 3, add them, and choose the last digit to make the total a multiple of 10. It catches every single-digit typing error."},{"tag":"Security","title":"Validation stops attacks","body":"Websites that don't validate input can be attacked by typing code into a form (for example SQL injection). Validating and cleaning input is a basic security rule."},{"tag":"History","title":"The Mars Climate Orbiter","body":"In 1999 a NASA probe was lost because one team used pound-force seconds and another used newton seconds. A units check between systems would have caught it."}]},{"type":"cards","id":"challenge","eyebrow":"Challenge yourself","title":"Stretch your brain","intro":"Try each one on paper before opening the card.","items":[{"tag":"Challenge","title":"Design","body":"List the validation checks for a UK-style postcode field.\n\nAnswer: presence, length (6–8 including space), format (letters and digits in the right pattern)."},{"tag":"Challenge","title":"Test data","body":"Give boundary test data for a quantity between 1 and 99 inclusive.\n\nAnswer: 1 and 99 accepted; 0 and 100 rejected."},{"tag":"Challenge","title":"Code","body":"Write Python that keeps asking for a whole number from 1 to 5.\n\nAnswer:\nwhile True:\n    s = input(\"1-5: \")\n    if s.isdigit() and 1 <= int(s) <= 5:\n        break","code":true}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Try it yourself","items":[{"title":"Break a form (safely)","time":"15 minutes","need":["A sign-up form you made yourself, or a paper sketch of one"],"steps":["List every field on the form.","For each field, write one normal, one boundary and one abnormal value.","Predict which should be accepted or rejected."],"why":"Thinking like a tester finds the checks a program is missing.","safety":"Only test forms you built yourself. Never try to break real websites."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"A presence check makes sure…","options":["the value is in range","the data matches a pattern","the field is not empty"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Which data is a boundary test for 1–10?","options":["10","5","\"ten\""],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"Double entry is a form of…","options":["validation","verification","encryption"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"\"abc\" in an age field is…","options":["normal data","boundary data","abnormal data"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"A check digit is used in…","options":["barcodes","passwords only","pie charts"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"A date written DD/MM/YYYY is checked by a…","options":["range check","format check","presence check"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"Validation can prove data is…","options":["always correct","encrypted","reasonable, not necessarily correct"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"A test plan includes…","options":["expected and actual results","only the code","the user's password"],"answer":0,"right":"Correct.","wrong":"Not quite."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["describe presence, range, length, type, format and check-digit validation","write validation loops in pseudocode and Python","explain double entry and visual checks","tell validation and verification apart","choose normal, boundary, extreme and abnormal test data","write a test plan"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"Validation","meaning":"An automatic check that data is sensible."},{"word":"Verification","meaning":"A check that data matches the original."},{"word":"Boundary data","meaning":"Values at the edge of the accepted range."},{"word":"Abnormal data","meaning":"Data that should be rejected."},{"word":"Check digit","meaning":"An extra digit calculated from the others to catch errors."},{"word":"Test plan","meaning":"A table of tests with expected and actual results."}]},{"type":"sources","id":"sources","title":"Sources","items":["Raspberry Pi Foundation, Isaac Computer Science: validation and verification","OWASP: Input Validation Cheat Sheet","NASA: Mars Climate Orbiter mishap report (1999)","BBC Bitesize, GCSE Computer Science: testing"]}]},"overlay":null}