Added test file for Graded Assignment 1
This commit is contained in:
parent
85f6fe46dc
commit
414b0304be
1 changed files with 29 additions and 0 deletions
29
ga1_last.py
Normal file
29
ga1_last.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import random
|
||||
|
||||
def calc(A):
|
||||
n = len(A)
|
||||
res = 0
|
||||
for i in range(0,n):
|
||||
for j in range(i+1, n):
|
||||
res += A[j] - A[i]
|
||||
return res
|
||||
|
||||
def calc2(A):
|
||||
n = len(A)
|
||||
res = 0
|
||||
for i in range(0,n):
|
||||
res += (2*(i+1)-n-1)*A[i]
|
||||
return res
|
||||
|
||||
def main():
|
||||
for i in range(0,100):
|
||||
A = []
|
||||
for j in range(0,i):
|
||||
A.append(random.randint(0,1000000))
|
||||
if not calc(A) == calc2(A):
|
||||
print("wrong!")
|
||||
return
|
||||
print("ok!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in a new issue