98
1 COMP61511 (Fall 2017) Software Engineering Concepts In Practice Week 2 Bijan Parsia & Christos Kotselidis < , @manchester.ac.uk> (bug reports welcome!) bijan.parsia christos.kotselidis

COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

1

COMP61511(Fall2017)SoftwareEngineeringConcepts

InPracticeWeek2

BijanParsia&ChristosKotselidis< , @manchester.ac.uk>

(bugreportswelcome!)bijan.parsia christos.kotselidis

Page 2: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.1

FizzBuzzInWayTooMuchDetail

Page 3: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.2

TheNaivestFizzbuzzAnyproposals?Let'sseethe !obvious

Page 4: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.3

ARationalFizzBuzzLet'sconsidera"standard"implementation

NotsillyNotgolfy

I.e.,asimplelooporientedimplementation

Page 5: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.4

DRY"Don'tRepeatYourself"

AfundamentalprincipleofSEItisagainst

CutandPastereuseNotInventedHeresyndrome

Isour DRY?currentversion

Page 6: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.5

ADryerVersionWerepeati % 3 == 0andi % 5 == 0Let's !abstractthatout

Page 7: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.6

EVENDRIER!!!Werepeatthe_ % _ == 0pattern!WesayprintalotWecan !fixit

Page 8: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.7

ParameterizationBasicsoftwareprinciple:Don'thardcodestuff!

Makeyourcodeparameterisable!Thecurrentversionhardcodesalot,e.g.,

Wehavetomodifythesourcecodeifwewanttochangethis!Whatelseishardcoded?Wecan !

FIZZ = 'Fizz'BUZZ = 'Buzz'

fixit

Page 9: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.8

StillHardCoding!ThekindoftestishardcodedWecanfix !that

Page 10: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.9

ThePathToHell......ispavedwithgoodintentions!Eachchoicewassomehowreasonable

WeappliedgoodSEprinciplesWemadechoicesthatareoftengood

ButweendedupinnonsenselandLocalsenseledtoglobalnonsense

Page 11: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.10

JudgementSoftwareengineerscan'tjustfollowrulesGoodsoftwareengineeringrequiresjudgementWhentoapplywhichrulesWhentobreakrules*HowtoapplyorbreakthemThereasonforeachrule

Andwhetheritmakessensenow

Page 12: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

2.11

AcknowledgementThislecturewasderivedfromtheexcellentblogpost

byTomDalling.FizzBuzzInTooMuch

Detail

TomusesRubyandgoesacoupleofstepsfurther.Wortharead!

Page 14: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

3.2

WhoOwnsYourCode?Youwrotesomecode!

Allweek!Bothsystemsandtests!

Akeyquestion:Whoownsthatcode?

Ordifferentbitsofit?Whatkindofownership?

Page 15: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

3.3

IntellectualProperty(IP)Intellectualproperty is anyarticulable, tangible productionofamindwhosephysical realisationsare restrictedby law (inproduction,distribution,etc.)

Wedon'tcontrolwhatotherpeoplethink!Wecancontrolwhattheydowithcertainthoughts.IntellectualPropertyrightsgivepowertocertainpeopletocontrolwhatotherpeopledo

Forexample,whethertheycandistributeabook,song,orprogram

Page 16: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

3.4

KindsOfIntellectualPropertyName Establishment Enforcement

Copyright Automatic,immediate CivilandCriminal

Patent Application;exposurebeforeapplicationdestroysit

Mostlycivil

Trademark Applicationandvigorousdefense MostlycivilTradeSecret

Automatic(bynottellingpeople)andNDAs Mostlycivil

Page 17: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

3.5

CopyrightCopyright isa licensablemonopolyoftangible expressionofan idea with respect to reproduction, derivation, display,distribution,andthelike.

ProtectstheexpressionnottheideaThoughthesebluratthelimit

Someplagiarismisacopyrightviolation;someisnotTypicallyautomaticallyassignedatcreationtime

No"notice"or"registration"neededThoughthesemighthelpwithlawsuits

Page 18: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

3.6

PatentsApatent isa licensablemonopolyof theuseorsaleofa"non-obvious"invention(ofaprocess,machine,design(sometimes),mechanism,procedure,etc.

ApatentisanincentivetodiscloseManypatentableinventionscouldbeexploited"secretly"Goalistoaddtoourcommonknowledge

PriorartdestroysapatentIncludingyourown

Defensivepatenting"common"Independentinventionnodefense

Page 19: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

3.7

TradeSecretAtradesecretisaninventionwhichisnotdisclosed

PersistsforeverUnlessleakedOrreinvented

TypicallyprotectedbysecrecyOrspecificcontracts

"Non-DisclosureAgreements"(NDAs)

Page 20: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

3.8

WhoOwnsYourCode?Copyrightstartswiththecreator

I.e.,you!Cheap!(Eventoregister)Unlessyoucreateitaswork-for-hire

OrotherwisetransferitPatentsbelongtothepatenter

Expensive(ish)tosecureTradesecretsbelongtotheinventor

Page 21: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

AreYouWorkingForHire?Not !quite

Page 22: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

3.9

3.10

WhatToKeepInMind(Now)SoftwareengineerstypicallyproduceIP

Evenifnotprotected,ouroutputis"intellectual"VariousformsofIPdriveproductvalueemployee/entrepreneurvalue

SoftwareengineerstypicallyuseIPAllsortsandinallwaysIPconsiderationsaconstraintonthedesignspace

Page 23: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.1

ComprehendingProductQualities

Page 24: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.2

Comprehension?Wecandistinguishtwoforms:

Know-thatYoubelieveatrueclaimaboutthesoftware...withappropriateevidence

Know-howYouhaveacompetancywithrespecttothesoftwareE.g.,youknow-howtorecompileitforadifferentplatform

TheyareinterrelatedBothrequiresignificanteffort!

Page 25: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.3

QualityLevelsWetalkedaboutdifferentkindsofquality

Butforeachkindtherecanbedegreesorlevelsthereof"Easy"example:Highvs.Lowperformance

MostqualitiesinprinciplearequantifiableMostthingsarequantifiableinsomesense

Butreasonablequantificationisn'talwayspossibleOrworthitBeingclearaboutyourvaguenessisessential!

Page 26: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.4

ClarityOurdiscussionwillbeadequate if ithasasmuchclearnessas the subject-matter admits of, for precision is not to besought for alike in all discussions, any more than in all theproducts of the crafts...for it is the mark of an educated[person]tolookforprecisionineachclassofthingsjustsofarasthenatureofthesubjectadmits...—Aristotle,NicomachaenEthics,Book1,3

Page 27: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.5

Clarity(2)We demand rigidly defined areas of doubt anduncertainty!—DouglasAdams,TheHitchhiker'sGuidetotheGalaxy

Page 28: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.6

DefectsAsQualityLacksA defect in a software system is a quality level (for somequality)thatisnotacceptable.

QualitylevelsneedtobeelicitedandnegotiatedAllpartiesmustagreeonwhattheyare,theiroperationaldefinitiontheirsignificance

Whatcountsasadefectisoftendeterminedlateinthegame!

Page 29: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.7

QuestionIfyourprogramcrashesthenit

1. definitelyhasabug.2. ishighlylikelytohaveabug.3. mayormaynothaveabug.

Page 30: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.8

QuestionIfyourprogramcrashes,andthecauseisinyourcode,thenit

1. definitelyhasabug.2. ishighlylikelytohaveabug.3. mayormaynothaveabug.

Page 31: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.9

BugOrFeature?( —scrollforthecartoonsaswellasthewisdom.)DoesQAhateyou?

Evenacrashingcodepathcanbeafeature!Contentionariseswhenthestakesarehigh

andsometimethestakescanseemhightosomepeople!defectrectificationcoststhesame

whetherthedefectisdetected......orafeatureisredefined

Defects(evenredefinedfeatures)aren'tpersonal

Page 33: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.10

4.11

ProblemDefinitionThe penalty for failing to define the problem is that you canwastealotoftimesolvingthewrongproblem.Thisisadouble-barreledpenaltybecauseyoualsodon'tsolvetherightproblem.—McConnell,3.3

Page 34: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.12

QualityAssuranceDefectAvoidanceorPrevention

"Prerequisite"workcanhelpRequirementnegotiationDesignTechchoice

MethodologyDefectDetection&Rectification

Ifadefectexists,FinditFixit

Page 35: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.13

ThePointsOfQuality1. Defectprevention

Designcare,codereviews,etc.2. Defectappraisal

Detection,triaging,etc.3. Internalrectification

Wefix/mitigatebeforeshipping4. Externalrectification

Wecopeaftershipping

Page 36: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.14

DefectDetectionTechniques

Page 38: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.16

ExperiencingSoftwareIt'sonetoknowthattherearebugsAllsoftwarehasbugs!

It'sanothertobeabletotriggerabugNotjustaspecificbug!Ifyouunderstandthesoftware

Youknowhowtobreakit.Similarly,formakingchanges

tweaks,extensions,adaptions,etc.Themorecommand,themoremodalitiesofmastery

Page 39: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.17

FormsOfKnowledge(Manifestations)Humaninterpretable

Comments,designdocs,userstories,javadocSourcecode

Both,awrittendescriptionanda"live"objectAlsothingslikedemocode,examples,testsuites,ec.

Diagrams"Mere"picturestosemi-formaltoformaldiagrams:ERdocs,UML,etc.

FormalspecificationsCompetencies

Icanmakeitcrash

Page 40: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

4.18

SourcesOfKnowledge(Modalities)Analyticalknowledge

DerivedfrominspectionandreasoningCanbeautomatedusingformalmethods

ExperimentalknowledgeDerivedfromtheconductofexperimentsTypicallytests

ExperientialknowledgeDerivedfrompersonalinteractionwiththesoftwareStrong"know-how"component

Page 42: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

5.2

RevisitingRainfallWe'regoingtolookatyourrainfallsbeforediscussingitindetail.

We'regoingtodoacodereview!

You'regoingtoworkin2-personteams!

Page 43: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

5.3

ThreeTasks1. Doacodereview!2. Writesometestsbasedonyourcodereview!3. Doanessayreview!

Tothelab!Materialintheusualplace.

Page 45: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.2

RainfailKeypoint:0outof47programspassedall13tests

1programpassed8tests2passed75passed60passed5or45passed33passed21passed115passed011"hadaproblemwithsubmission"4"Wecouldnotcompileyourcode."

Therainfallproblemisstillachallenge!

Page 46: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.3

Let'sTalkTestingYouhadlimitedtime

Sotestgenerationhadtobequick!Typicallyadhoc

Canwedobetter?Howtestableisrainfall.py?

Youwereresponsibleonlyforaverage_rainfall(input_list)Onlythisunit!Canignoreallelse!

Perfectfordoctest

Page 47: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.4

ProblemStatementDesign a program called rainfall that consumes a list ofnumbers representing daily rainfall amounts as entered by auser. The list may contain the number -999 indicating theend of thedataof interest.Produce theaverageof thenon-negativevalues in the listup to the first -999(if it showsup).Theremaybenegativenumbersotherthan-999inthelist.

Page 48: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.5

SetUpdef average_rainfall(input_list): """>>> average_rainfall(<<FIRST TEST INPUT>>) <<FIRST EXPECTED RESULT>> """ # Here is where your code should go return "Your computed average as a integer" #<-- change this!

$ python 1setup.py Your computed average as a integer

Page 49: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.6

FirstTestRun$ python -m doctest 1setup.py **********************************************************************File "/Users/bparsia/Documents/2018/Teaching/COMP61511/labs/lab1/followup/1setup.py", line 2, in 1setup.average_rainfallFailed example: average_rainfall(<<FIRST TEST INPUT>>)Exception raised: Traceback (most recent call last): File "//anaconda/lib/python3.5/doctest.py", line 1320, in __run compileflags, 1), test.globs) File "<doctest 1setup.average_rainfall[0]>", line 1 average_rainfall(<<FIRST TEST INPUT>>) ^ SyntaxError: invalid syntax**********************************************************************1 items had failures: 1 of 1 in 1setup.average_rainfall***Test Failed*** 1 failures.

Page 50: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.7

FirstTestWheredowegetourfirstrealtest?

Hint:Readthedocs:

Page 51: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.8

ConvertToAppropriateDoctestForasystemtest,we'dneedtousesubprocessetc.

Butwecanjusttestourunit!average_rainfall(input_list)Butittakesalistnotastringasinput!

'2 3 4 67 -999'==>[2, 3, 4, 67, -999]Wehadtomassagetheinputtogetourtest!

Page 52: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.9

TestedAverage_rainfallV2def average_rainfall(input_list): """>>> average_rainfall([2,3,4,67, -999]) 19.0 """ # Here is where your code should go return "Your computed average as a integer" #<-- change this!

$ python 1setup.py Your computed average as a integer

Page 53: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.10

SecondTestRun$ python -m doctest 2firstfull.py **********************************************************************File "/Users/bparsia/Documents/2018/Teaching/COMP61511/labs/lab1/followup/2firstfull.py", line 2, in 2firstfull.average_rainfallFailed example: average_rainfall([2,3,4,67, -999])Expected: 19.0Got: 'Your computed average as a integer'**********************************************************************1 items had failures: 1 of 1 in 2firstfull.average_rainfall***Test Failed*** 1 failures.

Page 54: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.11

Yay!Wehavearealandreasonabletest!

AndaclearformatforsubsequenttestsAndaninfrastructurethatmakesiteasytoruntests

WehaveabrokenimplementationAswitnessedbyatest!

WeCanFixIt!

Page 55: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.12

RosieSez

Page 56: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.13

FirstImplementationdef average_rainfall(input_list): """>>> average_rainfall([2,3,4,67, -999]) 19.0 """ # Here is where your code should go return sum(input_list)/len(input_list)

Willthisfailthistest?Isthereatestthatitwillpass?

Page 57: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.14

FirstImplementationWithTestdef average_rainfall(input_list): """>>> average_rainfall([2,3,4,67, -999]) 19.0 >>> average_rainfall([2,3,4,67]) 19.0 """ # Here is where your code should go return sum(input_list)/len(input_list)

Page 58: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.15

ThirdTestRun$ python -m doctest 4firstimpl2.py **********************************************************************File "/Users/bparsia/Documents/2018/Teaching/COMP61511/labs/lab1/followup/4firstimpl2.py", line 2, in 4firstimpl2.average_rainfallFailed example: average_rainfall([2,3,4,67, -999])Expected: 19.0Got: -184.6**********************************************************************1 items had failures: 1 of 2 in 4firstimpl2.average_rainfall***Test Failed*** 1 failures.

Page 59: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.16

SecondImplementationdef average_rainfall(input_list): """>>> average_rainfall([2,3,4,67, -999]) 19.0 >>> average_rainfall([2,3,4,67]) 19.0 """ # Here is where your code should go return sum(input_list[:-1])/len(input_list[:-1])

Fixesonetestbutnottheother!Testsworktogether

Page 60: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.17

ThirdImplementationdef average_rainfall(input_list): """>>> average_rainfall([2, 3, 4, 67, -999]) 19.0 >>> average_rainfall([2, 3, 4, 67]) 19.0 """ rainfall_sum = 0 count = 0 for i in input_list: if i == -999: break else: rainfall_sum += i count += 1 # Here is where your code should go return rainfall_sum/count

Page 61: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.18

FourthTestRun$ python -m doctest 5secondimpl.py **********************************************************************File "/Users/bparsia/Documents/2018/Teaching/COMP61511/labs/lab1/followup/5secondimpl.py", line 2, in 5secondimpl.average_rainfallFailed example: average_rainfall([2,3,4,67, -999])Expected: 19.0Got: 19.0**********************************************************************1 items had failures: 1 of 2 in 5secondimpl.average_rainfall***Test Failed*** 1 failures.

Whaaaaaaaaaaaaaaaaaat?!

Page 62: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.19

ABug!Therewasabuginourtests

Allalong!

vs.

Earliertestsfailedfortworeasons!

Onebugconcealedtheother!!!

def average_rainfall(input_list):""">>> average_rainfall([2, 3, 4, 67, -999])19.0

def average_rainfall(input_list):""" >>> average_rainfall([2, 3, 4, 67, -999])19.0

Page 63: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.20

Yay!$ python -m doctest 6secondimpl2.py $$ python -m doctest -v 6secondimpl2.py Trying: average_rainfall([2,3,4,67, -999])Expecting: 19.0okTrying: average_rainfall([2,3,4,67])Expecting: 19.0ok1 items had no tests: 6secondimpl21 items passed all tests: 2 tests in 6secondimpl2.average_rainfall2 tests in 2 items.2 passed and 0 failed.Test passed.

Page 64: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

6.21

NextTests?Thesetestsclearlyaren'tenoughWhatnext?

Lookforboundaryconditions([-999])Lookfor"oddequivalents"

Is[-999, 1]thesameas[-999]?Howabout[]and[-999]?Howabout[-999]and[-999, 0]

Lookfornormalcasesyouhaven'tcovered[-1 0 10]Foreachnewfeatureiteratetheearliermoves!

e.g.,is[-1 -2 -3 -999 1]thesameas[]?

Page 66: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

7.2

AClassificationOfTestsBasedona5W+Happroachby (archived)Who(Programmervs.customervs.managervs...)What(Correctnessvs.Performancevs.Useabilityvs...)When(Beforewritingcodeorafter)

Orevenbeforearchitecting!Where(Unitvs.Componentvs.Integrationvs.System)

Orlabvs.fieldWhy(Verificationvs.specificationvs.design)How(Manualvs.automated)

Ondemandvs.continuous

RaySinnema

Page 67: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

7.3

Who?Sinnema:Testsgiveconfidenceinthesystem

I.e.,theyareevidenceofaqualityWhoisgettingtheevidence?Users?Testsfocusonexternalqualities

CanIacceptthissoftware?Programmers?Testsfocusoninternalqualities

CanIcheckinthiscode?Managers?Both?

ArewereadytoreleaseButalso,whoiswritingthetest?

Abugreportisa(typicallypartial)testcase!

Page 68: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

7.4

What?WhichqualitiesamItryingtoshow?

Internalvs.externalFunctionalvs.non-functional?Mostdevelopertestingisfunctional(i.e.,correctness)

AndattheunitlevelDoesthisclassbehaveasdesigned

Page 69: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

7.5

When?Whenisthetestwritten?Beforethecodeiswritten?Afterthecodeiswritten?

PerhapsabetterdistinctionTestswrittenwithexistingcode/designinmindTestwrittenwithoutregardforexistingcode/designThisisrelatedtowhitevs.blackboxtesting

MaindifferenceiswhetheryourespecttheexistingAPI

Page 70: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

7.6

Where?Unit

Smallest"chunk"ofcoherentcodeMethod,routine,sometimesaclass

:"theexecutionofacompleteclass,routine,orsmallprogramthathasbeenwrittenbyasingleprogrammerorteamofprogrammers,whichistestedinisolationfromthemorecompletesystem"

Component(McConnellspecific,Ithink)"workofmultipleprogrammersorprogrammingteams"andinisolation

McConnell

Page 71: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

7.7

Where?(Ctnd)Integration

Testingtheinteractionoftwoormoreunits/componentsSystem

TestingthesystemasawholeInthelab

I.e.,inacontrolledsettingInthefield

I.e.,in"natural",uncontrolledsettings

Page 72: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

7.8

Where?(CtndEncore)Regression

AbitofafunnyoneBackwardlookingandchangeoriented

Ensureachangehasn'tbrokenanythingEsppreviousfixes.

Page 73: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

7.9

Why?Threebigreasons1. Verification(orvalidation)

Doesthesystempossessaqualitytoacertaindegree?2. Design

ImposeconstraintsonthedesignspaceBothstructureandfunction

3. ComprehensionHowdoesthesystemwork?

ReverseengineeringHowdoIworkwiththesystem?

Page 74: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

7.10

How?Manual

TypicallyinteractiveHumanintervationformorethaninitiation

ExpectationsflexibleAutomated

ThetestexecutesandevaluatesoninitiationAutomaticallyrun(i.e.,continuously)

Page 76: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.2

Bill Sempf@sempf

QA Engineer walks into a bar. Orders a beer. Orders 0 beers. Orders 999999999 beers. Orders a lizard. Orders -1 beers. Orders a sfdeljknesv.6:56 PM - Sep 23, 2014

21.1K 29.9K people are talking about this

Coverage

Esp.forfinegrainedtests,generalityisaproblemWewantasetofteststhat

determinessomepropertyatareasonablelevelofconfidence

Thistypicallyrequirescoverage

Page 77: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.3

CoverageAndRequirementsConsideracceptancetesting

ForatestsuitetosupportacceptanceItneedstoprovideinformationaboutallthecriticalrequirements

ConsidertestdrivendevelopmentWheretestsdrivedesignWhathappenswithoutrequirementscoverage?

Page 78: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.4

CodeCoverageAtestcase(orsuite)coversalineofcode

iftherunningofthetestexecutestheLOCCodecoverageisaminimalsortofcompleteness

SeeMcConnellon"basis"testingAimforminimaltestsuitewithfullcodecoverage

SeeTrickybittypicallyinvolvesbranches

Themorebranches,thehardertoachievecodecoverage

coverage.py

Page 79: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.5

InputCoverageInputspacesare(typically)toolargetocoverdirectly

SoweneedasamplePuresampleprobablyinadequate

SpacetoolargeanduninterestingWewantabiasedsample

E.g.,wherethebugsareHence,attentiontoboundarycases

E.g.,commoninputsThatis,what'slikelytobeseen

Page 80: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.6

Situation/ScenarioCoverageInputsaren'teverything

MachineconfigurationHistoryofuseInteractionpatterns

FieldtestinghelpsHencealphaplusnarrowandwidebetatesting

Systemtestsanswertothis!

Page 81: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.7

LimitsOf(Developer)TestingTestingalwayshaslimits

TestsarewrongTestsarebuggyTestsareincomplete

"Self"Testingsubjecttocognitivebiases:Weinterpretwrongly

:Weinfluenceotherstointerpretincorrectly

:Welookinthewrongplace

ConfirmationbiasObserver-expectancyeffect/Experimenterbias

Congruencebias

Page 82: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.8

DevelopingTestStrategiesHaveone!Howeverpreliminary

AdhoctestingrarelyworksoutwellReviewitregularly

YoumayneedadjustementsbasedonIndividualorteampsychologySituation

TheMcConnell (22.2)isagooddefaultbasicstrategy

Page 83: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.9

DeveloperTestStrategiesMcConnell:22.2RecommendedApproachtoDeveloperTesting

"Testforeachrelevantrequirementtomakesurethattherequirementshavebeenimplemented.""Testforeachrelevantdesignconcerntomakesurethatthedesignhasbeenimplemented...asearlyaspossible""Use"basistesting"...Ataminimum,youshouldtesteverylineofcode.""Useachecklistofthekindsoferrorsyou'vemadeontheprojecttodateorhavemadeonpreviousprojects."Designthetestcasesalongwiththeproduct.

Page 84: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.10

WhatAboutInputCoverageInWC?ByreverseengineeringwcweaimforanalternativepythonimplementationWithaclearspecaccordingtoCW1Howcanweachievefunctionalcorrectnessofminiwc?

Byachieving100%inputcoveragetosatisfythespecificationLet'sseesomeexamples...

Page 85: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.11

EmptyTextFile

Page 86: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.12

CommonCase:1Line

Page 87: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.13

CommonCase:2Lines

Page 88: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

8.14

VisualisingPotentialErrorsGuardagainstprograminput

Whatkindoffile?Differenttypes,wrongnames...Contentsoffile?

ProvideinputcoverageforeveryoutputdimensionNumberoflines(single,multiple)Numberofcharacters(commoncase,large,small)Numberofwords(howarewordscounted?)Numberofbytes(encoding?)

Page 90: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

9.2

CourseworkActivitiesReadingQ1

MostlyrelatedtoreadingMostly"Recall"...withsomeinterpretation

TheywillgohigherontheBloomtaxonomy!SE1

ReadingandanalysingCW1ReverseengineeredaspecificationReengineeredminiwcfromthespec

Programconstruction

Page 91: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

9.3

ANoteOnMarksUKmarksrunfrom0-100%

<=49=Failing(<40%seriousfailure)50-59=Pass60-69=Meritover70=DistinctionNOTETHEWIDEBANDATTHETOPANDBOTTOM

A65%isagoodmarkAn85%isexceedinglyrareOver70%isfairlyrare

Page 92: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

9.4

Q1Meanof3.57(71%)

Lastyear:3.71(74%)Wewilldosome"inexamconditions"Let'sdelve

Page 93: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

9.5

SimplifiedProblemThiswasasmallproblem

WithclearboundariesEvenhere:

WeendedupwithsupportprogramsAndcornerscut

Softwareengineeringis(complex)systemengineeringOnboththeproductandprojectsidesWeuseacomplexinfrastructure!

Page 94: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

9.6

ChallengesWhatwerethechallengesyouencountered?

Whatchallengeswereinherenttotheproblem?

Whatchallengeswereenvironmental?

Page 95: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

9.7

CW1MarksInBlackboard!Average:4/10(40%)Max:8>70%660%s1450%s5<49%26

Notunusualforfirstassignment!LearningcurveFinalcourseworkaveagetendstobe≈62%

Page 96: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

9.8

CW1FeedbackFeedbackisinBlackboardFeedbackisdetailedbutabstract

There seems to be a miniwc.py: 0.5/0.5 points. There seems to be a doctest_miniwc.py and test files: 0.5/0.5 points. Prohibited libraries have been used: 0/1 points. Formatting was correct: 1/1 points.The script passed 35.7% of miniwc simple tests: 2/5 points. The script passed 0.0% of miniwc binary tests: 0/1 points. The script passed 0.0% of miniwc unicode tests: 0/1 points. Penalties: none. Total marks: 4.0/10.0

Page 97: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

9.9

NextWe'regoingtodomorewc

Job1istofixyourminiwc.py(nowcalledwc.py)Fixyourtests!Addmoretests!

Unicode!Binary!Job2istoaddnewfunctionality

Flags!MultipleinputfilesJob3istoupdateyourtests

NotethatJob3isn't*temporallylast!Youwilldoacodereviewofminiwc.pyDiscussthefeedback!Thisistheonlytimeyoucantalkwithaclassmateaboutit!

Page 98: COMP61511 (Fall 2017) Software Engineering Concepts In ...syllabus.cs.manchester.ac.uk/pgt/2018/COMP61511/... · obvious" invention (of a process, machine, design (sometimes), mechanism,

9.10

OtherCourseworkSE2!

YouneedtoreadNoSilverBulletSE1!

TAsareavailabletodiscuss