-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add check to perm check challenge
- Loading branch information
1 parent
ccfcf34
commit cfa6dd7
Showing
2 changed files
with
21 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,4 @@ | ||
from typing import List | ||
|
||
|
||
class PermCheck: | ||
def solution(self, A: List) -> int: | ||
N = max(A) | ||
return ( | ||
1 if len(A) == len(set(A)) and sum(set(A)) - (N * (N + 1) // 2) == 0 else 0 | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
# sample = [4, 1, 3, 2] | ||
# sample = [4, 1, 3] | ||
sample = [1, 1] | ||
print(PermCheck().solution(sample)) | ||
async def solution(arr: list) -> int: | ||
"""Returns 1 if the array is a permutation and 0 if it is not.""" | ||
max_value = max(arr) | ||
return 1 if len(arr) == len(set(arr)) and sum(set(arr)) - (max_value * (max_value + 1) // 2) == 0 else 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
|
||
from lesson4.perm_check import solution | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data_input, expected", | ||
[ | ||
([4, 1, 3, 2], 1), | ||
([4, 1, 3], 0), | ||
([1, 1], 0), | ||
], | ||
) | ||
@pytest.mark.asyncio | ||
async def test_perm_check(data_input: list[int], expected: int): | ||
"""Should return 1 if the array is a permutation and 0 if it is not.""" | ||
assert await solution(data_input) == expected |