-
Notifications
You must be signed in to change notification settings - Fork 5
/
check.py
69 lines (58 loc) · 2.17 KB
/
check.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2023 Ruize Tang <[email protected]>, Runze Wu
# <[email protected]>.
#
# This file is a part of Disalg-ICS-NJU/algocentric.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import sys
from collections import Counter
from get_input import get_input # pylint: disable=wrong-import-position # noqa
from critical_op import equal_op # pylint: disable=wrong-import-position, no-name-in-module # noqa
from frequent_element import frequent_element
def check(oracle, to_check) -> bool:
'''检查oracle和to_check是否完全一致.
Args:
oracle: 给定的正确结果
to_check: 待验证的输入
Returns:
oracle是否与to_check完全一致的检查结果
'''
return oracle == to_check
def frequent_element_check(array: list, k: int, to_check: list) -> bool:
'''检查to_check是否为正确的常见元素
Args:
array (list): 给定的输入list
k (int): 给定的正整数常数k
to_check (list): 待检查的常见元素序列
Returns:
to_check是否为正确的常见元素
'''
counter = Counter(array)
oracle = [elem for elem, freq in counter.items() if freq >=
len(array)//k+1]
return check(sorted(oracle), to_check)
if __name__ == '__main__':
testcase = get_input()
result = frequent_element(testcase[0], testcase[1])
if frequent_element_check(testcase[0], testcase[1], result):
print('PASS')
print('Critical op counts:', equal_op.get_op_count())
else:
print('FAIL')
print('Input :', testcase)
print('Result:', result)
sys.exit(1)