We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 27: Testing
Day 27: Testing
Sort by
recency
|
218 Discussions
|
Please Login in order to post a comment
In Java8
def minimum_index(seq): if len(seq) == 0: raise ValueError("Cannot get the minimum value index from an empty sequence") min_idx = 0 for i in range(1, len(seq)): if seq[i] < seq[min_idx]: min_idx = i return min_idx
class TestDataEmptyArray(object):
class TestDataUniqueValues(object): data = [] for i in range(5): data.append(i) data[::-1]
@staticmethod def get_array(): return TestDataUniqueValues.data @staticmethod def get_expected_result(): data = TestDataUniqueValues.get_array() return data.index(min(data)) # complete this function
class TestDataExactlyTwoDifferentMinimums(object): data = [] for i in range(5): data.append(i) data[::-1] data.insert(0,0)
def TestWithEmptyArray(): try: seq = TestDataEmptyArray.get_array() result = minimum_index(seq) except ValueError as e: pass else: assert False
def TestWithUniqueValues(): seq = TestDataUniqueValues.get_array() assert len(seq) >= 2
def TestiWithExactyTwoDifferentMinimums(): seq = TestDataExactlyTwoDifferentMinimums.get_array() assert len(seq) >= 2 tmp = sorted(seq) assert tmp[0] == tmp[1] and (len(tmp) == 2 or tmp[1] < tmp[2])
TestWithEmptyArray() TestWithUniqueValues() TestiWithExactyTwoDifferentMinimums() print("OK")
My Python Solution: