You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.1 KiB
112 lines
2.1 KiB
# class defs
|
|
class A_CLASS(object):
|
|
a_class_i:int = 0
|
|
def __init__(self:"A_CLASS", x:int):
|
|
self.x = x
|
|
|
|
def add(self:"A_CLASS", y:int) -> int:
|
|
y = y+self.x
|
|
return y
|
|
|
|
class B_CLASS(object):
|
|
b_class_i:int = 0
|
|
|
|
class C_CLASS(B_CLASS):
|
|
pass
|
|
|
|
# var defs
|
|
a_s:str = "a_s"
|
|
b_s:str = "b_s"
|
|
c_s:str = "c_s"
|
|
|
|
a_i:int = 0
|
|
b_i:int = 0
|
|
c_i:int = 0
|
|
|
|
a_b:bool = False
|
|
b_b:bool = False
|
|
c_b:bool = False
|
|
|
|
a_list:[int] = None
|
|
b_list:[int] = None
|
|
c_list:[int] = None
|
|
|
|
a_class:A_CLASS = None
|
|
b_class:B_CLASS = None
|
|
c_class:C_CLASS = None
|
|
|
|
|
|
# fun defs
|
|
def f_1() -> object:
|
|
def f_f_1() -> object:
|
|
global a_s # Fails if we change it to z, which doesnt exist in global scope
|
|
pass
|
|
pass
|
|
|
|
def f_2() -> object:
|
|
f_a_s:str = "s"
|
|
def f_f_2() -> object:
|
|
nonlocal f_a_s # Fails if we change this to a_s which is in global scope but not in upper scope
|
|
pass
|
|
pass
|
|
|
|
def f_3(x:int) -> str:
|
|
f_b_s:int = 3
|
|
return x*f_b_s
|
|
|
|
|
|
# Declarations
|
|
a_list = [1, 2, 3]
|
|
b_list = [0, 0, 0]
|
|
c_list = [-1, -2, -3]
|
|
|
|
a_class = A_CLASS(5)
|
|
b_class = B_CLASS()
|
|
c_class = C_CLASS()
|
|
|
|
|
|
# NEGATIVE TEST CASES - TYPES
|
|
c_i = True
|
|
|
|
c_i + [1] # Bad, addint list to an int
|
|
|
|
a_i = a_b = z = "Error" # Bad, z is not defined and a_b is boolean
|
|
|
|
a_s = a_s + 1 # Bad, adding integer to a string
|
|
|
|
c_s = a_s[a_s] # Bad, indexing with a string variable
|
|
|
|
b_class.b_class_i = 2 # Bad, object attribute is not assignable
|
|
|
|
f_1 = 5 # Bad, function is not assignable
|
|
|
|
f_2 = f_1 # Bad, function is not storable
|
|
|
|
a_i = b_class.b_class_i = z = 5 # Bad, b_class.b_class_i is not assignable and z is not declared
|
|
|
|
x_i = "ss" # Bad assignment
|
|
|
|
a_s = a_i + b_i # Bad, assigning integer to a variable with string type
|
|
|
|
a_s = a_i == b_i and True # Bad, assigning boolean to a variable with string type
|
|
|
|
a_list = a_list + a_s # Bad, adding string and list
|
|
|
|
a_s = a_list[a_s] # Bad, indexing with a string variable and assigning int to str
|
|
|
|
a_list[1] = "a" # Bad, assigning str to int
|
|
|
|
a_i = f_3(3) + 5 # Bad, f_3 has string return type but it actually returns an int
|
|
|
|
f_1()
|
|
|
|
f_2()
|
|
|
|
a_i = a_class.add(a_s) # Bad, passing string where method expects int
|
|
|
|
|
|
|
|
|
|
|
|
|