developer_debug_tools 0.1.1

Tools for developer to debug their code
Documentation
use developer_debug_tools::print_recursion_tree;



#[print_recursion_tree()]
fn method_with_generics<T1, T2>(_t1: T1, _t2: T2) -> u32 {
    0
}

#[print_recursion_tree()]
fn test_with_generics_without_returnval<T1, T2>(_t1: T1, _t2: T2) {}

#[test]
fn test_fibonacci_recursive() {
    use indoc::indoc;
    assert_eq!(0, fibonacci_recursive(0));
    assert_eq!(0, __debug_recursion__get_counter_fibonacci_recursive());
    let tree_output = indoc! {"fibonacci_recursive
                                     └─ 0
                                        └─ =0
                                    "};
    assert_eq!(
        tree_output,
        __debug_recursion__get_tree_fibonacci_recursive()
    );

    assert_eq!(1, fibonacci_recursive(1));
    assert_eq!(0, __debug_recursion__get_counter_fibonacci_recursive());
    let tree_output = indoc! {"fibonacci_recursive
                                     └─ 1
                                        └─ =1
                                    "};
    assert_eq!(
        tree_output,
        __debug_recursion__get_tree_fibonacci_recursive()
    );

    assert_eq!(1, fibonacci_recursive(2));
    assert_eq!(2, __debug_recursion__get_counter_fibonacci_recursive());
    let tree_output = indoc! {"fibonacci_recursive
                                    └─ 2
                                       ├─ 1
                                       │  └─ =1
                                       ├─ 0
                                       │  └─ =0
                                       └─ =1
                                    "};
    assert_eq!(
        tree_output,
        __debug_recursion__get_tree_fibonacci_recursive()
    );

    assert_eq!(2, fibonacci_recursive(3));
    assert_eq!(4, __debug_recursion__get_counter_fibonacci_recursive());
    let tree_output = indoc! {"fibonacci_recursive
                                    └─ 3
                                       ├─ 2
                                       │  ├─ 1
                                       │  │  └─ =1
                                       │  ├─ 0
                                       │  │  └─ =0
                                       │  └─ =1
                                       ├─ 1
                                       │  └─ =1
                                       └─ =2
                                    "};
    assert_eq!(
        tree_output,
        __debug_recursion__get_tree_fibonacci_recursive()
    );
}

#[print_recursion_tree(print_each_pass, print_recursion_counter)]
fn fibonacci_recursive(n: u16) -> u16 {
    if n <= 1 {
        return n;
    } else {
        return fibonacci_recursive(n - 1) + fibonacci_recursive(n - 2);
    }
}

#[test]
fn test_method_with_generics() {
    let result = test_without_generics(2, 2);
    assert_eq!(result, 0);
}

#[print_recursion_tree(print_recursion_counter, print_each_pass)]
fn test_without_generics(t1: u32, t2: u32) -> u32 {
    if t1 == 0 {
        return 1;
    }

    if t2 == 0 {
        return 2;
    }

    if t1 != 0 {
        test_without_generics(t1 - 1, t2);
    }

    if t2 != 0 {
        test_without_generics(t1, t2 - 1);
    }

    return 0;
}

#[print_recursion_tree()]
fn test_without_generics_without_returnval(_t1: u32, _t2: u32) {}