1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-07-06 14:35:36 +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:
Dustin J. Mitchell
2025-02-18 15:13:16 -05:00
committed by GitHub
parent 699c5137c7
commit 44a79741ff
38 changed files with 138 additions and 144 deletions

View File

@ -4,6 +4,6 @@ version = "0.1.0"
edition = "2021"
publish = false
[[bin]]
name = "binary-tree"
[lib]
name = "binary_tree"
path = "exercise.rs"

View File

@ -14,7 +14,7 @@ Implement the following types, so that the given tests pass.
Extra Credit: implement an iterator over a binary tree that returns the values
in order.
```rust,editable,ignore
```rust,compile_fail,editable
{{#include exercise.rs:types}}
// Implement `new`, `insert`, `len`, and `has` for `Subtree`.

View File

@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#![allow(dead_code)]
// ANCHOR: solution
use std::cmp::Ordering;
@ -96,14 +97,6 @@ impl<T: Ord> Node<T> {
}
}
fn main() {
let mut tree = BinaryTree::new();
tree.insert("foo");
assert_eq!(tree.len(), 1);
tree.insert("bar");
assert!(tree.has(&"foo"));
}
// ANCHOR: tests
#[cfg(test)]
mod tests {