mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-02-12 04:39:19 +00:00
38 lines
1.0 KiB
Rust
38 lines
1.0 KiB
Rust
// quiz3.rs
|
|
//
|
|
// This quiz tests:
|
|
// - Generics
|
|
// - Traits
|
|
//
|
|
// An imaginary magical school has a new report card generation system written
|
|
// in Rust! Currently the system only supports creating report cards where the
|
|
// student's grade is represented numerically (e.g. 1.0 -> 5.5). However, the
|
|
// school also issues alphabetical grades (A+ -> F-) and needs to be able to
|
|
// print both types of report card!
|
|
//
|
|
// Make the necessary code changes in the struct ReportCard and the impl block
|
|
// to support alphabetical report cards. Change the Grade in the second test to
|
|
// "A+" to show that your changes allow alphabetical grades.
|
|
//
|
|
// Execute `rustlings hint quiz3` or use the `hint` watch subcommand for a hint.
|
|
|
|
pub fn times_two(num: i32) -> i32 {
|
|
num * 2
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn returns_twice_of_positive_numbers() {
|
|
assert_eq!(times_two(4), 8);
|
|
}
|
|
|
|
#[test]
|
|
fn returns_twice_of_negative_numbers() {
|
|
// TODO write an assert for `times_two(-4)`
|
|
assert_eq!(times_two(-4), -8);
|
|
}
|
|
}
|