Design by Contract Flashcards
What is design by contract
defining interface specifications for software modules (e.g. functions). It specifies what the module expects and what it promises to deliver, what it maintains
What are the elements of design by contract?
- Pre-condition: What you assume to be true before running the module
- Post-conidition: What you assume to be true after running the module
- Some well-defined properties that should always be true about the stat of our program
What are assertions?
A software bug arises often because your assumptions are wrong. So it is useful to enforce your assumptions as executable code. That way, as soon as they get violated, you immediately know.
Meant for developers (not user friendly)
How do you compile without assertions
clang -Wall -DNDEBUG
How do you assert a large block of code?
Turn it into a function:
Defensive Programming:
How do you check an error return?
What cases should you test?
- typical cases
- edge cases
- special cases
What is the difference between black and white box testing
Black - you do not see the code
White - you do see the code
What is scaffolding?
Making our test into code, hard code the test data and the expected results and run it through your code.
What are the general guidelines of testing?
- Hard code test cases, results are verified automatically, not visually
- keep test code simple
- test paths and posibilities
- a failed test is good (means you found and will fix a problem
What is TDD
Test driven development
- write one simple test (that fails)
- write just enough code to pass that test
- add more test and repeat