Skip to content

Commit 8921b56

Browse files
Adding tests to monotonic_array.py (#12073)
* Contributes to #9943 by adding tests to monotonic_array.py Addeded doctest in the if __name__. Checks for negaitves and an array of same integers * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7e55fb6 commit 8921b56

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

data_structures/arrays/monotonic_array.py

+14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ def is_monotonic(nums: list[int]) -> bool:
99
True
1010
>>> is_monotonic([1, 3, 2])
1111
False
12+
>>> is_monotonic([1,2,3,4,5,6,5])
13+
False
14+
>>> is_monotonic([-3,-2,-1])
15+
True
16+
>>> is_monotonic([-5,-6,-7])
17+
True
18+
>>> is_monotonic([0,0,0])
19+
True
20+
>>> is_monotonic([-100,0,100])
21+
True
1222
"""
1323
return all(nums[i] <= nums[i + 1] for i in range(len(nums) - 1)) or all(
1424
nums[i] >= nums[i + 1] for i in range(len(nums) - 1)
@@ -21,3 +31,7 @@ def is_monotonic(nums: list[int]) -> bool:
2131
print(is_monotonic([1, 2, 2, 3])) # Output: True
2232
print(is_monotonic([6, 5, 4, 4])) # Output: True
2333
print(is_monotonic([1, 3, 2])) # Output: False
34+
35+
import doctest
36+
37+
doctest.testmod()

0 commit comments

Comments
 (0)