Skip to content

Commit

Permalink
fix(using_as): Add test so that proper type is returned. (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanpcmcquen committed Sep 7, 2020
1 parent ee7cdc6 commit 3286c5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions exercises/conversions/using_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// It also helps with renaming imports.
//
// The goal is to make sure that the division does not fail to compile
// and returns the proper type.

// I AM NOT DONE

Expand All @@ -15,3 +16,13 @@ fn main() {
let values = [3.5, 0.3, 13.0, 11.7];
println!("{}", average(&values));
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn returns_proper_type_and_value() {
assert_eq!(average(&[3.5, 0.3, 13.0, 11.7]), 7.125);
}
}
2 changes: 1 addition & 1 deletion info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ what you've learned :)"""
[[exercises]]
name = "using_as"
path = "exercises/conversions/using_as.rs"
mode = "compile"
mode = "test"
hint = """
Use the `as` operator to cast one of the operands in the last line of the
`average` function into the expected return type."""
Expand Down

0 comments on commit 3286c5e

Please sign in to comment.