File tree Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -9,10 +9,10 @@ fn is_prime(n: u32) -> bool {
9
9
return true ;
10
10
}
11
11
12
- pub fn nth ( n : u32 ) -> Result < u32 , ( ) > {
12
+ pub fn nth ( n : u32 ) -> Option < u32 > {
13
13
match n {
14
- 0 => Err ( ( ) ) ,
15
- 1 => Ok ( 2 ) ,
14
+ 0 => None ,
15
+ 1 => Some ( 2 ) ,
16
16
_ => {
17
17
let mut count: u32 = 1 ;
18
18
let mut candidate: u32 = 1 ;
@@ -22,7 +22,7 @@ pub fn nth(n: u32) -> Result<u32, ()> {
22
22
count += 1 ;
23
23
}
24
24
}
25
- Ok ( candidate)
25
+ Some ( candidate)
26
26
}
27
27
}
28
28
}
Original file line number Diff line number Diff line change
1
+ pub fn nth ( n : u32 ) -> Option < u32 > {
2
+ unimplemented ! ( "What is the {}th prime number?" , n)
3
+ }
Original file line number Diff line number Diff line change @@ -2,29 +2,29 @@ extern crate nth_prime as np;
2
2
3
3
#[ test]
4
4
fn test_first_prime ( ) {
5
- assert_eq ! ( np:: nth( 1 ) , Ok ( 2 ) ) ;
5
+ assert_eq ! ( np:: nth( 1 ) , Some ( 2 ) ) ;
6
6
}
7
7
8
8
#[ test]
9
9
#[ ignore]
10
10
fn test_second_prime ( ) {
11
- assert_eq ! ( np:: nth( 2 ) , Ok ( 3 ) ) ;
11
+ assert_eq ! ( np:: nth( 2 ) , Some ( 3 ) ) ;
12
12
}
13
13
14
14
#[ test]
15
15
#[ ignore]
16
16
fn test_sixth_prime ( ) {
17
- assert_eq ! ( np:: nth( 6 ) , Ok ( 13 ) ) ;
17
+ assert_eq ! ( np:: nth( 6 ) , Some ( 13 ) ) ;
18
18
}
19
19
20
20
#[ test]
21
21
#[ ignore]
22
22
fn test_big_prime ( ) {
23
- assert_eq ! ( np:: nth( 10001 ) , Ok ( 104743 ) ) ;
23
+ assert_eq ! ( np:: nth( 10001 ) , Some ( 104743 ) ) ;
24
24
}
25
25
26
26
#[ test]
27
27
#[ ignore]
28
28
fn test_zeroth_prime ( ) {
29
- assert ! ( np:: nth( 0 ) . is_err ( ) ) ;
29
+ assert_eq ! ( np:: nth( 0 ) , None ) ;
30
30
}
You can’t perform that action at this time.
0 commit comments