Ejemplo n.º 1
0
        "or find numbers pair with  specified sum")

    subparsers = parser.add_subparsers(help='sub-command help')

    parser_fib = subparsers.add_parser(
        "fib", help="Print predetermined count of fibonacci numbers")
    parser_fib.add_argument("--number",
                            "-n",
                            action="store",
                            help="A number for print",
                            type=int)
    parser_fib.set_defaults(which='fib')

    parser_pairs = subparsers.add_parser(
        "print_pairs", help="Return pairs with specified sum.")
    parser_pairs.add_argument(
        "--arguments",
        "-arg",
        action='store',
        nargs='+',
        help="Sequence of numbers, should be like: 1 2 3 7 8 9",
        type=int)
    parser_pairs.set_defaults(which="print_pairs")

    args = parser.parse_args()

    if args.which == "fib":
        print(fib(args.number))
    elif args.which == "print_pairs":
        print(print_pairs(*args.arguments))
def test_lengh():
    assert len(fib(7)) == 7
Ejemplo n.º 3
0
    group = parser.add_argument_group("Parameters")
    group.add_argument("--fib",
                       "-f",
                       action='store_true',
                       help="to run fibonachi")
    group.add_argument("--number",
                       "-n",
                       action='store',
                       help="Number of Fibonacci sequence",
                       type=int,
                       required=False)
    group.add_argument("--pairs",
                       "-p",
                       action='store_true',
                       help="to run pairs")
    group.add_argument(
        "--list",
        "-l",
        action='store',
        nargs='+',
        help="List of int with space delimiter. For example 1 2 3 34 678 ",
        type=int,
        required=False)
    args = parser.parse_args()
    if args.fib:
        str_fib = str(fib(args.number)).strip('[]')
        print(str_fib)

    elif args.pairs:
        print(pair(*args.list))
def test_output_type():
    assert type(fib(7)) is list
def test_arguments(test_input, expected):
    assert len(fib(test_input)) == expected
Ejemplo n.º 6
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description="App can return a Fibonacci sequence with given length "
        "or find numbers pair with  specified sum")

    subparsers = parser.add_subparsers(help='sub-command help')

    parser_fib = subparsers.add_parser(
        'fib', help='Print given number of members of Fibonacci sequence')
    parser_fib.add_argument("number",
                            help="The required number of sequence members",
                            type=int)
    parser_fib.set_defaults(which='fib')

    parser_pairs = subparsers.add_parser(
        'pairs', help='Return pairs with specified sum.')
    parser_pairs.set_defaults(which='pairs')
    parser_pairs.add_argument('-n',
                              '--numbers',
                              nargs="+",
                              type=int,
                              help='List of numbers to check.')

    args = parser.parse_args()

    if args.which == 'fib':
        fib(args.number)
    elif args.which == 'pairs':
        pairs(*args.numbers)
Ejemplo n.º 7
0
def test_count(test_input, expected):
    assert fib(test_input).__len__() == expected
Ejemplo n.º 8
0
def test_list(test_input, expected):
    assert fib(test_input) == expected