forked from eth-sri/TFix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
39 lines (29 loc) · 959 Bytes
/
utils.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
from datetime import datetime
from typing import Dict, List
from data_reader import DataPoint
def boolean_string(s: str) -> bool:
if s not in {"False", "True"}:
raise ValueError("Not a valid boolean string")
return s == "True"
def get_current_time() -> str:
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
return current_time
def compute_dict_average(dict: Dict) -> float:
# empty dictionary, return 0
if not dict:
return 0
total = 0
N = 0
for key, value in dict.items():
total += value
N += 1
return total / N
def check_test_alignment(
test_inputs: Dict[str, str], test_info: Dict[str, List[DataPoint]]
) -> None:
for warning in test_inputs:
inputs = test_inputs[warning]
infos = test_info[warning]
for i, code in enumerate(inputs):
assert code == infos[i].GetT5Representation(True)[0], "something wrong! stop it!"