Design by Contract Flashcards

1
Q

What is design by contract

A

defining interface specifications for software modules (e.g. functions). It specifies what the module expects and what it promises to deliver, what it maintains

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the elements of design by contract?

A
  1. Pre-condition: What you assume to be true before running the module
  2. Post-conidition: What you assume to be true after running the module
  3. Some well-defined properties that should always be true about the stat of our program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are assertions?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you compile without assertions

A

clang -Wall -DNDEBUG

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you assert a large block of code?

A

Turn it into a function:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Defensive Programming:

How do you check an error return?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What cases should you test?

A
  • typical cases
  • edge cases
  • special cases
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between black and white box testing

A

Black - you do not see the code

White - you do see the code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is scaffolding?

A

Making our test into code, hard code the test data and the expected results and run it through your code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the general guidelines of testing?

A
  1. Hard code test cases, results are verified automatically, not visually
  2. keep test code simple
  3. test paths and posibilities
  4. a failed test is good (means you found and will fix a problem
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is TDD

A

Test driven development

  • write one simple test (that fails)
  • write just enough code to pass that test
  • add more test and repeat
How well did you know this?
1
Not at all
2
3
4
5
Perfectly