Home Software Engineering Examine if all Values in Array are Smaller in Python

Examine if all Values in Array are Smaller in Python

0
Examine if all Values in Array are Smaller in Python

[ad_1]

The problem

You may be given an array and a restrict worth. You will need to verify that every one values within the array are beneath or equal to the restrict worth. If they’re, return true. Else, return false.

You’ll be able to assume all values within the array are numbers.

The answer in Python code

Choice 1:

def small_enough(array, restrict):
    return True if max(array)<=restrict else False

Choice 2:

def small_enough(array, restrict):
    return max(array)<=restrict

Choice 3:

def small_enough(array, restrict):
    return all(a <= restrict for a in array)

Check circumstances to validate our resolution

import take a look at
from resolution import small_enough

@take a look at.describe("Mounted Assessments")
def fixed_tests():
    @take a look at.it('Fundamental Check Circumstances')
    def basic_test_cases():

        assessments = (
            ([[66, 101] ,200], True),
            ([[78, 117, 110, 99, 104, 117, 107, 115] ,100], False),
            ([[101, 45, 75, 105, 99, 107], 107], True),
            ([[80, 117, 115, 104, 45, 85, 112, 115] ,120], True),
            ([[1, 1, 1, 1, 1, 2] ,1], False),
            ([[78, 33, 22, 44, 88, 9, 6] ,87], False),
            ([[1, 2, 3, 4, 5, 6, 7, 8, 9] ,10], True),
            ([[12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12] ,12], True),
        )
        
        for inp, exp in assessments:
            take a look at.assert_equals(small_enough(*inp), exp)

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here