You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-25 02:06:46 +02:00
Be more consistent about tests vs. main (#2644)
The content slides all use `fn main`, with the exception of the testing segment. But with this change, where it makes sense exercises use tests instead, and not both tests and `fn main`. A small change in `book.js` supports running tests when a code sample does not have `fn main` but does have `#[test]`, so these work naturally. Fixes #1581.
This commit is contained in:
committed by
GitHub
parent
699c5137c7
commit
44a79741ff
@ -30,7 +30,5 @@ initial `n`.
|
||||
todo!("Implement this")
|
||||
}
|
||||
|
||||
{{#include exercise.rs:tests}}
|
||||
|
||||
{{#include exercise.rs:main}}
|
||||
```
|
||||
|
@ -25,15 +25,14 @@ fn collatz_length(mut n: i32) -> u32 {
|
||||
len
|
||||
}
|
||||
|
||||
// ANCHOR: tests
|
||||
// ANCHOR: main
|
||||
fn main() {
|
||||
println!("Length: {}", collatz_length(11)); // should be 15
|
||||
}
|
||||
// ANCHOR_END: main
|
||||
// ANCHOR_END: solution
|
||||
|
||||
#[test]
|
||||
fn test_collatz_length() {
|
||||
assert_eq!(collatz_length(11), 15);
|
||||
}
|
||||
// ANCHOR_END: tests
|
||||
|
||||
// ANCHOR: main
|
||||
fn main() {
|
||||
println!("Length: {}", collatz_length(11));
|
||||
}
|
||||
// ANCHOR_END: main
|
||||
|
Reference in New Issue
Block a user