File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 1
1
// tests4.rs
2
- // Correct the tests to
3
- // Do not change Rectangle::new body
2
+ // Make sure that we're testing for the correct conditions!
4
3
// Execute `rustlings hint tests4` or use the `hint` watch subcommand for a hint.
5
4
6
5
// I AM NOT DONE
@@ -11,6 +10,7 @@ struct Rectangle {
11
10
}
12
11
13
12
impl Rectangle {
13
+ // Only change the test functions themselves
14
14
pub fn new ( width : i32 , height : i32 ) -> Self {
15
15
if width < 0 || height < 0 {
16
16
panic ! ( "Rectangle width and height cannot be negative!" )
@@ -25,16 +25,21 @@ mod tests {
25
25
26
26
#[ test]
27
27
fn correct_width_and_height ( ) {
28
- let _rect = Rectangle :: new ( 10 , 10 ) ;
28
+ // This test should check if the rectangle is the size that we pass into its constructor
29
+ let rect = Rectangle :: new ( 10 , 20 ) ;
30
+ assert_eq ! ( ???, 10 ) ; // check width
31
+ assert_eq ! ( ???, 20 ) ; // check height
29
32
}
30
33
31
34
#[ test]
32
35
fn negative_width ( ) {
36
+ // This test should check if thread panics when we try to create rectangle with negative width
33
37
let _rect = Rectangle :: new ( -10 , 10 ) ;
34
38
}
35
39
36
40
#[ test]
37
41
fn negative_height ( ) {
42
+ // This test should check if thread panics when we try to create rectangle with negative height
38
43
let _rect = Rectangle :: new ( 10 , -10 ) ;
39
44
}
40
45
}
Original file line number Diff line number Diff line change @@ -813,8 +813,9 @@ path = "exercises/tests/tests4.rs"
813
813
mode = " test"
814
814
hint = """
815
815
We expect method `Rectangle::new()` to panic for negative values.
816
- To handle that you need to add special attribute to test function.
817
- You can refer to the docs: https://doc.rust-lang.org/stable/book/ch11-01-writing-tests.html"""
816
+ To handle that you need to add a special attribute to the test function.
817
+ You can refer to the docs:
818
+ https://doc.rust-lang.org/stable/book/ch11-01-writing-tests.html#checking-for-panics-with-should_panic"""
818
819
819
820
820
821
# STANDARD LIBRARY TYPES
You can’t perform that action at this time.
0 commit comments