Example #1
0
def process_test_cases(fd, suit_name, test_vectors):
    """
    Read test cases for benchmark suit ${suit_name} from ${fd} and evaluate them.
    """
    number_of_testcases = 0
    number_of_failures = 0
    previous_function_id = None
    for test_case in fd:
        number_of_testcases += 1

        ## A test case is a triple (function_id, test_vector_id,
        ## expected_y) separated by a single space. 
        function_id, test_vector_id, expected_y = test_case.split(" ")
        ## Do type conversion. Python gurus probably know an elegant
        ## one line solution...
        function_id = int(function_id)
        test_vector_id = int(test_vector_id)
        expected_y = float(expected_y)

        ## We cache the problem instances because creating an instance
        ## can be expensive depending on the transformation.
        if function_id != previous_function_id:
            problem = Problem(suit_name, function_id)
            previous_function_id = function_id
        test_vector = test_vectors[test_vector_id]
        y = problem(test_vector[:problem.number_of_variables])
        if not about_equal(y, expected_y):
            number_of_failures += 1
            if number_of_failures < 100:
                print("%8i %8i FAILED expected=%.8e observed=%.8e" % (function_id, test_vector_id, expected_y, y))
            elif number_of_failures == 100:
                print("... further failed tests suppressed ...")
    print("%i of %i tests passed (failure rate %.2f%%)" % (number_of_testcases - number_of_failures, number_of_testcases, (100.0 * number_of_failures) / number_of_testcases))
    if number_of_failures > 0: 
        sys.exit(-1)
Example #2
0
def process_test_cases(fd, suite_name, test_vectors):
    """
    Read test cases for benchmark suite ${suite_name} from ${fd} and evaluate them.
    """
    number_of_testcases = 0
    number_of_failures = 0
    previous_problem_index = None
    suite = Suite(suite_name, "instances:1-15", "")
    print("Testing suite", suite_name)
    for test_case in fd:
        number_of_testcases += 1

        ## A test case is a 4-tuple (deprecated_problem_index, problem_index, test_vector_id,
        ## expected_y) separated by a tab.
        deprecated_problem_index, problem_index, test_vector_id, expected_y = test_case.split("\t")
        ## Do type conversion. Python gurus probably know an elegant
        ## one line solution...
        deprecated_problem_index = int(deprecated_problem_index)
        test_vector_id = int(test_vector_id)
        expected_y = float(expected_y)

        ## We cache the problem instances because creating an instance
        ## can be expensive depending on the transformation.
        if deprecated_problem_index != previous_problem_index:
            problem = suite.get_problem(int(problem_index))
            previous_problem_index = deprecated_problem_index
        test_vector = test_vectors[test_vector_id]
        y = problem(test_vector[: problem.number_of_variables])
        if not about_equal(y, expected_y):
            number_of_failures += 1
            if number_of_failures < 100:
                print(
                    "%8i %8i FAILED expected=%.8e observed=%.8e"
                    % (deprecated_problem_index, test_vector_id, expected_y, y)
                )
            elif number_of_failures == 100:
                print("... further failed tests suppressed ...")
    print(
        "%i of %i tests passed (failure rate %.2f%%)"
        % (
            number_of_testcases - number_of_failures,
            number_of_testcases,
            (100.0 * number_of_failures) / number_of_testcases,
        )
    )
    if number_of_failures > 0:
        sys.exit(-1)
Example #3
0
def process_test_cases(fd, suite_name, test_vectors):
    """
    Read test cases for benchmark suite ${suite_name} from ${fd} and evaluate them.
    """
    number_of_testcases = 0
    number_of_failures = 0
    previous_problem_index = None
    suite = Suite(suite_name, "instances:1-15", "")
    print("Testing suite", suite_name)
    for test_case in fd:
        number_of_testcases += 1

        ## A test case is a 4-tuple (deprecated_problem_index, problem_index, test_vector_id,
        ## expected_y) separated by a tab.
        deprecated_problem_index, problem_index, test_vector_id, expected_y = test_case.split(
        )
        ## Do type conversion. Python gurus probably know an elegant
        ## one line solution...
        problem_index = int(problem_index)
        test_vector_id = int(test_vector_id)
        expected_y = float(expected_y)

        ## We cache the problem instances because creating an instance
        ## can be expensive depending on the transformation.
        if problem_index != previous_problem_index:
            problem = suite.get_problem(int(problem_index))
            previous_problem_index = problem_index
        test_vector = test_vectors[test_vector_id]
        y = problem(test_vector[:problem.number_of_variables])
        if not about_equal(y, expected_y, 4e-6):
            number_of_failures += 1
            if number_of_failures < 100:
                print("%8i %8i FAILED expected=%.8e observed=%.8e" %
                      (problem_index, test_vector_id, expected_y, y))
            elif number_of_failures == 100:
                print("... further failed tests suppressed ...")
    print("%i of %i tests passed (failure rate %.2f%%)" %
          (number_of_testcases - number_of_failures, number_of_testcases,
           (100.0 * number_of_failures) / number_of_testcases))
    if number_of_failures > 0:
        sys.exit(-1)