-
Notifications
You must be signed in to change notification settings - Fork 0
/
burchard.py
83 lines (75 loc) · 2.89 KB
/
burchard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import math
LICENSE_MESSAGE="""
#############################################################
# #
# This program is relased in the GNU GPL v3.0 license #
# you can modify/use this program as you wish. Please #
# link the original distribution of this software. If #
# you plan to redistribute your modified/copied copy #
# you need to relased the in GNU GPL v3.0 licence too #
# according to the overmentioned licence. #
# #
# "PROUDLY" MADE BY chkrr00k (i'm not THAT proud tbh) #
# #
#############################################################
# #
# #
# YEE #
# #
# #
#############################################################
"""
def Urmpo(n, z):
if z < 1 - 1/n:
return (n - 1) * (2 ** (z / (n - 1)) - 1) + 2 ** (1 - z) - 1
else:
return n * (2 ** (1 / n) - 1)
def burchard(t, c):
x = [math.log2(t[i]) - math.floor(math.log2(t[i])) for i in range(len(t))]
for i in range(len(x)):
print("X{} := {:.4f}".format(i, x[i]))
z = max(x) - min(x)
print("\nZ := {:.4f}".format(z))
U = sum(c[i]/t[i] for i in range(len(t)))
Ur = Urmpo(len(t), z)
print("Urmpo(N={}, Z={:.4f}) := {:.4f}".format(len(t), z, Ur))
print("\nU := {:.4f} {} Urmpo:= {:.4f}".format(U, "<=" if U<=Ur else ">", Ur))
return U <= Ur
import getopt
import sys
import json
HELP_MESSAGE = """Help:
Creates the burchard test table
-h, --help Displays this help
-c "<array>" The Ci column
-t "<array>" The Ti column
-l Shows the license
Columns must be rappresented in array form. E.g. "[1,2,3,4]"
"""
try:
opts, args = getopt.getopt(sys.argv[1:], "hlc:t:", ["help"])
except getopt.GetoptError:
print("Error in arguments\n")
print(HELP_MESSAGE)
sys.exit(1)
settings = {
"c" : [],
"t": []
}
for opt, arg in opts:
if opt in ("-h", "--help"):
print(HELP_MESSAGE)
sys.exit(0)
elif opt in ("-l"):
print(LICENSE_MESSAGE)
sys.exit(0)
elif opt in ("-c"):
settings["c"] = json.loads(arg)
elif opt in ("-t"):
settings["t"] = json.loads(arg)
if len(settings["c"]) != len(settings["t"]):
raise ValueError("All array must be equal length")
if burchard(settings["t"], settings["c"]):
print("Test passed")
else:
print("Test NOT passed")