Skip to content

Commit c4974ac

Browse files
committed
added required changes
- fixed grammar in hint and added more specific link - added comments in test functions - changed introduction paragraph
1 parent 27b7579 commit c4974ac

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

exercises/tests/tests4.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// 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!
43
// Execute `rustlings hint tests4` or use the `hint` watch subcommand for a hint.
54

65
// I AM NOT DONE
@@ -11,6 +10,7 @@ struct Rectangle {
1110
}
1211

1312
impl Rectangle {
13+
// Only change the test functions themselves
1414
pub fn new(width: i32, height: i32) -> Self {
1515
if width < 0 || height < 0 {
1616
panic!("Rectangle width and height cannot be negative!")
@@ -25,16 +25,21 @@ mod tests {
2525

2626
#[test]
2727
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
2932
}
3033

3134
#[test]
3235
fn negative_width() {
36+
// This test should check if thread panics when we try to create rectangle with negative width
3337
let _rect = Rectangle::new(-10, 10);
3438
}
3539

3640
#[test]
3741
fn negative_height() {
42+
// This test should check if thread panics when we try to create rectangle with negative height
3843
let _rect = Rectangle::new(10, -10);
3944
}
4045
}

info.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,9 @@ path = "exercises/tests/tests4.rs"
813813
mode = "test"
814814
hint = """
815815
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"""
818819

819820

820821
# STANDARD LIBRARY TYPES

0 commit comments

Comments
 (0)