Testing, Debugging, Exception Flashcards

1
Q

What can you do to achieve high quality programming?

A
  1. Testing
  2. Defensive Programming
  3. Eliminate sources of bugs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is defensive programming?

A
  • Write specifications for functions
  • Modularize programs
  • Check conditions on inputs/outputs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What can you do to test your programs?

A
  1. Compare in/outputs

i. e. it’s not working

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

What is debugging?

A

Study the events leading up to an error

  • -> Why is it not working?
  • -> How can I fix my peogram?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you create a good debugging experience?

A
  1. Break program into modules that can be tested and debugged individually
  2. Document constraints on modules
    - -> What do you expect the input to be
    - -> what do you expect the output to be?
  3. Document assumptions behind code design
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When are you ready to test?

A
  1. Code has to run!
    - > remove syntax errors
    - -> remove static semantic errors
  2. Have a set of expected results
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What testing classes do we know?

A
  1. Unit testing: Test each function separately
  2. Regression testing: Catch reintroduced errors that were previously fixed
  3. Integration testing: does the overall program work?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What testing approaches do we know?

A
  1. Intuition about natural boundaries
  2. Blackbox Testing
  3. Glassbox testing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is blackbox testing?

A
  • it is designed without looking at the code
  • should be done by someone else than the programmer to avoid implementer bias
  • can be reused if implementation changes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is glassbox testing?

A
  • use code directly to guide design of test cases
  • called path complete if every potential path through code is tested at least once

disadvantages:
- missing paths
- can go through loops randomly many times

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

Can a pass complete test miss a bug?

A

yes, test boundary cases

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

What are print statements good for?

A

To test hypothesis
use bisection method:
-> put print halfway in code

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

What are the steps in debugging?

A
  1. Study program code
  2. don’t ask whats wrong
  3. Ask how did I get an unexpected result
  4. Pick simple input to test with
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When do you get an index error?

A

I.e. trying to access beyond the limits of a list

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

When do you get an TypeError?

A
  1. trying to convert an inappropriate type i.e. int(test)

2. Mixing data types without appropriate coercion

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

When do you get a NameError?

A

When you reference a non-existent variable

17
Q

When do you get a syntax error?

A

python can’t parse the program –> forgetting to close parentheses, quotation etc.

18
Q

When do you get a value error?

A

the operand is okay but the value is illegal

19
Q

How do you handle exceptions?

A
Python can provide handlers for exceptions: 
try:
     body - what to do
except : 
     print("Bug in ...")
20
Q

What to do when you encounter an error?

A
  1. Fail silently (bad idea)
  2. return an error value
  3. stop execution - in python: raise an exception
21
Q

What is an assertion?

A
  1. means of defensive programming
  2. use an assert statement
    to raise an AssertionError
    exception if assumptions not met
  3. ensure than execution halts whenever expected conditions are met