def testMultipleValues(self): """If the minimum or maximum value appears more than once in the list, return the first one""" value, index = MinMax()([5, 1, 8, 4, 1, 9, 1]) self.assertEqual(value, 1.0) self.assertEqual(index, 1) value, index = MinMax(type="max")([9, 6, 5, 9, 8, 4, 9]) self.assertEqual(value, 9.0) self.assertEqual(index, 0)
def testMax(self): value, index = MinMax(type="max")([3, 7, -45, 2, -1, 0]) self.assertEqual(value, 7) self.assertEqual(index, 1)
def testMixedTypes(self): value, index = MinMax()([4, 5, 3.3]) self.assertAlmostEqual(value, 3.3) self.assertEqual(index, 2)
def testNegatives(self): value, index = MinMax()([3, 7, -45, 2, -1, 0]) self.assertEqual(value, -45.0) self.assertEqual(index, 2)
def testMin(self): """An array of normal numbers, finding minimum""" value, index = MinMax()([5, 8, 4, 9, 1]) self.assertEqual(value, 1.0) self.assertEqual(index, 4)
def testOne(self): """An array of a single value""" value, index = MinMax()([100]) self.assertEqual(value, 100.0) self.assertEqual(index, 0)
def testAllSame(self): value, index = MinMax()([0]*10) self.assertEqual(value, 0.0) self.assertEqual(index, 0)
def testEmpty(self): """An empty input causes an exception""" self.assertComputeFails(MinMax(), []) self.assertComputeFails(MinMax(type="max"), [])
def testDefaultIsMin(self): """Making the Algorithm with no type defaults to min""" value, index = MinMax()([3,1,2]) self.assertEqual(value, 1.0) self.assertEqual(index, 1)
def testNonArray(self): self.assertComputeFails(MinMax()('Not an array'))
def testNonNumeric(self): self.assertComputeFails(MinMax()(['a', 1]))