Test if all Values in Array are Smaller in Python

[ad_1]

The problem

You can be given an array and a restrict worth. You need to examine that every one values within the array are under 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)

Take a look at circumstances to validate our answer

import take a look at
from answer import small_enough

@take a look at.describe("Fastened Assessments")
def fixed_tests():
    @take a look at.it('Fundamental Take a look at 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