1
exercism fetch rust perfect-numbers

tests/perfect-numbers.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
extern crate perfect_numbers;

use perfect_numbers::{Classification, classify};

macro_rules! tests {
    ($property_test_func:ident {
        $( $(#[$attr:meta])* $test_name:ident( $( $param:expr ),* ); )+
    }) => {
        $(
            $(#[$attr])*
            #[test]
            fn $test_name() {
                $property_test_func($( $param ),* )
            }
        )+
    }
}

fn test_classification(num: u64, result: Classification) {
    assert_eq!(classify(num), Ok(result));
}

#[test]
fn basic() {
    assert_eq!(classify(0), Err("Number must be positive"));
}


tests! {
    test_classification {
        #[ignore] test_1(1, Classification::Deficient);
        #[ignore] test_2(2, Classification::Deficient);
        #[ignore] test_4(4, Classification::Deficient);
        #[ignore] test_6(6, Classification::Perfect);
        #[ignore] test_12(12, Classification::Abundant);
        #[ignore] test_28(28, Classification::Perfect);
        #[ignore] test_30(30, Classification::Abundant);
        #[ignore] test_32(32, Classification::Deficient);
        #[ignore] test_33550335(33550335, Classification::Abundant);
        #[ignore] test_33550336(33550336, Classification::Perfect);
        #[ignore] test_33550337(33550337, Classification::Deficient);
    }
}