Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d9f2f9f

Browse files
authoredOct 14, 2024··
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
1 parent e9e7c96 commit d9f2f9f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎data_structures/arrays/monotonic_array.py

Lines changed: 13 additions & 0 deletions
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,6 @@ 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+
doctest.testmod()

0 commit comments

Comments
 (0)
Please sign in to comment.