def test_argmaxn(self): ind = argmaxn(self.value_lists, 3) assert_equal(len(ind), 3) ind = argmaxn(self.value_lists, 3) assert_equal(np.sum(ind), np.sum([4, 6, 9])) ind = argmaxn(self.value_lists, 3, order='asc') assert_equal(np.sum(ind), np.sum([3, 7, 8])) with assert_raises(ValueError): argmaxn(self.value_lists, -1) with assert_raises(ValueError): argmaxn(self.value_lists, 20)
def test_check_parameter_range(self): # verify parameter type correction with assert_raises(TypeError): check_parameter('f', 0, 100) with assert_raises(TypeError): check_parameter(1, 'f', 100) with assert_raises(TypeError): check_parameter(1, 0, 'f') with assert_raises(TypeError): check_parameter(argmaxn(value_list=[1, 2, 3], n=1), 0, 100) # if low and high are both unset with assert_raises(ValueError): check_parameter(50) # if low <= high with assert_raises(ValueError): check_parameter(50, 100, 99) with assert_raises(ValueError): check_parameter(50, 100, 100) # check one side with assert_raises(ValueError): check_parameter(50, low=100) with assert_raises(ValueError): check_parameter(50, high=0) assert_equal(True, check_parameter(50, low=10)) assert_equal(True, check_parameter(50, high=100)) # if check fails with assert_raises(ValueError): check_parameter(-1, 0, 100) with assert_raises(ValueError): check_parameter(101, 0, 100) with assert_raises(ValueError): check_parameter(0.5, 0.2, 0.3) # if check passes assert_equal(True, check_parameter(50, 0, 100)) assert_equal(True, check_parameter(0.5, 0.1, 0.8)) # if includes left or right bounds with assert_raises(ValueError): check_parameter(100, 0, 100, include_left=False, include_right=False) assert_equal(True, check_parameter(0, 0, 100, include_left=True, include_right=False)) assert_equal(True, check_parameter(0, 0, 100, include_left=True, include_right=True)) assert_equal(True, check_parameter(100, 0, 100, include_left=False, include_right=True)) assert_equal(True, check_parameter(100, 0, 100, include_left=True, include_right=True))