1/28
week
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is an error?
when your program doesn’t work as intended
Compile-time errors
errors that happens when you try to write your code this can be syntax error
Runtime errors
occurs when a program is running
you could be dividing by zero or index error
Logical errors:
mistakes in your code or algorithm and your code runs but it doesn’t work as intended
What is a bug?
flaws in a program
originated in 1940 when a bug(mont) was found in a computer
Debugging
art of removing bugs in a program
is a processing of finding isolating and removing errors in a code
the first bug
found in 1947
real bug found by Grace Hopper and her team at harvard
“Compile”-time Error
found by python interpreter
syntax error
the program doesn’t follow the programming language
IndentationError
NameError (misspelling key words)
runtime error
the program structure is correct but is doesnt work as intended
ZeroDivisionError
TypeError
NameError (variable thats not defined )
FileNotFoundError:
KeyError
indexError
syntax error
happens when the code is not following the rules
Program does not pass checking/compiling stage
Logic Error
Program passes checking/compiling and runs but produces incorrect results or no results - because of a flaw in the algorithm or implementation of algorithm.
test
uncovering errors
Debug
finding the cause of the error
Exhaustive testing, also known as brute-force testing
a testing strategy where every possible input in its domain is use to test the program
Characteristics of Exhaustive Testing:
Test Coverage: ensure to test every possible input to make sure every scenario is covered
Expected Outputs: for every input the expected output must be predetermined so it can be compared with the actual values
Full Validation: it provides the high level of confidence since each case was tested
Pros of Exhaustive Testing:
validation
no assumption
Cons of Exhaustive Testing:
scalability
resource intensive
example for Exhaustive testing
Exhaustive testing
But how do we test for all values of integers?
def Threshold(val):
if val>10000:
val=10000
return val
This simple program asks the user for one integer – how many possible inputs in Python?
answers
Boundary values: 1001 1000 999
Edge cases: very large number 1 000 000 000, a negative number -100 and zero
Random Testing
randomly select subset of possible input in the domain
Sampling random integers from a wide range (positive, negative, very large, very small).
Test Coverage: generate random numbers
Equivalence Class
divides the input data into classes and these classes represent a set of inputs that will behave the same
example :valid age is between 18 and 65
therefore your equivalence classes are going to be
[18; 20; 44; 65]
[values under 18]
[values greater than 65]
Boundary Value
focuses on testing boundaries between equivalance classes
it assumes that errors are likely to appear on these values
example
input and accepts valid ages between 18 and 65
boundary values
just below 18 : 17
at min valid age: 18
at max valid age 65
above 65: 66
19 is not a boundary value since if falls under the valid age
path testing
creates case test that cover each possible path
Statement Coverage
line coverage
makes sure every line in a code is executed at least once during testing
black box testing
Exhaustive Testing
▪ Random Testing
▪ Equivalence classes
boundary values
glass box testing
Path Coverage,
Statement Coverage
tracing
you insert temporary statement in your code to track and output values during the execution
Debugging
the process of finding errors/bugs in a code
binary numbers
computer represents them using the presence or the absence of voltage
binary is a base two system number and it only uses two numbers 0 and 1
1101-base2 is a binary number
binary code
def convert_to_binary(decimal):
result_string = ""
while decimal > 0:
remainder = decimal % 2
decimal = decimal // 2
result_string = str(remainder) + result_string # Add remainder to the front of the result string
return result_string