Example #1
0
def test_fibonacci_calc_negative():
    """
    function:  test_fibonacci_calc_negative

    notes:     ensure that all assertions behave as expected.
    """
    try:
        fibonacci_calc(-1)
        ok_(False, "fibonacci_calc(-1) should fail.")
    except: pass

    try:
        fibonacci_calc("A")
        ok_(False, "fibonacci_calc('A') should fail.")
    except: pass
Example #2
0
def fibonacci_list_api():
    """
    function:  fibonacci_api

    params:    none

    returns:   flask response object suitable for return to the client.  May be an error or a valid successful reply.

    pre-requisites:  GET request requires a 'count' parameter that is parsable as a long and greater than zero.

    """
    if 'count' not in request.args or request.args['count'] in ("", None):
        return notify_error(
            "ERR_NO_ARG:  'count' argument required to /fibonacci/api",
            HTTP_ERROR_CLIENT)

    try:
        count = long(request.args.get('count', ''))
    except:
        return notify_error(
            "ERR_INVALID_TYPE:  'count' parameter must be an integer",
            HTTP_ERROR_CLIENT)

    if count < 0:
        return notify_error(
            "ERR_OUT_OF_BOUNDS:  'count' parameger must be a postitive integer",
            HTTP_ERROR_CLIENT)

    try:
        return jsonify(answer=fibonacci_calc(count))
    except Exception as ex:
        return notify_error(ex, HTTP_ERROR_SERVER)
Example #3
0
def fibonacci_list_api():
    """
    function:  fibonacci_api

    params:    none

    returns:   flask response object suitable for return to the client.  May be an error or a valid successful reply.

    pre-requisites:  GET request requires a 'count' parameter that is parsable as a long and greater than zero.

    """
    if "count" not in request.args or request.args["count"] in ("", None):
        return notify_error("ERR_NO_ARG:  'count' argument required to /fibonacci/api", HTTP_ERROR_CLIENT)

    try:
        count = long(request.args.get("count", ""))
    except:
        return notify_error("ERR_INVALID_TYPE:  'count' parameter must be an integer", HTTP_ERROR_CLIENT)

    if count < 0:
        return notify_error("ERR_OUT_OF_BOUNDS:  'count' parameger must be a postitive integer", HTTP_ERROR_CLIENT)

    try:
        return jsonify(answer=fibonacci_calc(count))
    except Exception as ex:
        return notify_error(ex, HTTP_ERROR_SERVER)
Example #4
0
def test_fibonacci_calc_negative():
    """
    function:  test_fibonacci_calc_negative

    notes:     ensure that all assertions behave as expected.
    """
    try:
        fibonacci_calc(-1)
        ok_(False, "fibonacci_calc(-1) should fail.")
    except:
        pass

    try:
        fibonacci_calc("A")
        ok_(False, "fibonacci_calc('A') should fail.")
    except:
        pass
Example #5
0
def check_fibonacci_calc_output_ok(expected_array):
    """
    function:  check_fibonacci_calc_output_ok

    notes:     take some of the boilerplate out of testing fibonacci number calculations.
                see test_fibonacci_calc() for examples
    """
    l = len(expected_array)
    out = fibonacci_calc(l)
    eq_(len(out), l, "Should be array of length %s" % l)
    eq_(out, expected_array, "Should be array %s" % l)
Example #6
0
def check_fibonacci_calc_output_ok(expected_array):
    """
    function:  check_fibonacci_calc_output_ok

    notes:     take some of the boilerplate out of testing fibonacci number calculations.
                see test_fibonacci_calc() for examples
    """
    l = len(expected_array)
    out = fibonacci_calc(l)
    eq_(len(out), l, "Should be array of length %s" % l)
    eq_(out, expected_array, "Should be array %s" % l)
Example #7
0
 def get(self, id):
     abort_if_parameter_exceeds_max_value(id)
     return fibonacci_calc(id)