diff --git a/Cargo.lock b/Cargo.lock index cf767bf..a7fa288 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1254,9 +1254,6 @@ dependencies = [ [[package]] name = "primitive-data-types" version = "0.1.0" -dependencies = [ - "syntest", -] [[package]] name = "printing-hello-world" diff --git a/challenges/primitive-data-types/Cargo.toml b/challenges/primitive-data-types/Cargo.toml index 219c6fe..7148eaa 100644 --- a/challenges/primitive-data-types/Cargo.toml +++ b/challenges/primitive-data-types/Cargo.toml @@ -2,6 +2,3 @@ name = "primitive-data-types" version = "0.1.0" edition = "2021" - -[dev-dependencies] -syntest = { version = "0.1.0", path = "../../crates/syntest" } diff --git a/challenges/primitive-data-types/src/lib.rs b/challenges/primitive-data-types/src/lib.rs index 65b965d..4cc8d7f 100644 --- a/challenges/primitive-data-types/src/lib.rs +++ b/challenges/primitive-data-types/src/lib.rs @@ -1,8 +1,10 @@ #[allow(warnings)] -pub fn data_types() { +pub fn data_types() -> (u8, f64, bool, char) { let x: u8 = 42; - let y: f64 = 3.224242422424; + let y: f64 = 3.14; let z: bool = false; - let a: char = '7'; + let a: char = 'a'; + + (x, y, z, a) } diff --git a/challenges/primitive-data-types/src/starter.rs b/challenges/primitive-data-types/src/starter.rs index 4104e59..eeae17b 100644 --- a/challenges/primitive-data-types/src/starter.rs +++ b/challenges/primitive-data-types/src/starter.rs @@ -1,9 +1,11 @@ -pub fn data_types() { - // 1. Define variable `x` of type `u8` +pub fn data_types() -> (u8, f64, bool, char) { + // 1. Define variable of type `u8` and value `42` - // 2. Define variable `y` of type `f64` + // 2. Define variable of type `f64` and value `3.14` - // 3. Define variable `z` of type `bool` + // 3. Define variable of type `bool` and value `false` - // 4. Define variable `a` of type `char` + // 4. Define variable of type `char` and value `'a'` + + // 5. Return a tuple with the variables in the order they were defined } diff --git a/challenges/primitive-data-types/tests/tests.rs b/challenges/primitive-data-types/tests/tests.rs index 5398546..f8125d0 100644 --- a/challenges/primitive-data-types/tests/tests.rs +++ b/challenges/primitive-data-types/tests/tests.rs @@ -1,51 +1,11 @@ -#[cfg(test)] +use primitive_data_types::*; -mod tests { - use primitive_data_types::*; - use syntest::{parse_quote, Pat, Stmt, Syntest}; +#[test] +fn test_compiles() { + let (x, y, z, a) = data_types(); - #[test] - fn test_compiles() { - data_types(); - } - - #[test] - fn test_annotations() { - let syntest = Syntest::new("data_types", "./src/lib.rs"); - - let pats_actual = syntest.get_pats(); - let stmts_expected: [Stmt; 4] = [ - parse_quote! { - let x: u8 = 42; - }, - parse_quote! { - let y: f64 = 3.14; - }, - parse_quote! { - let z: bool = true; - }, - parse_quote! { - let a: char = 'R'; - }, - ]; - - let mut expected_count = 0; - for (pat_actual, stmt_expected) in pats_actual.iter().zip(stmts_expected.iter()) { - if let Stmt::Local(local_expected) = stmt_expected { - if let Pat::Type(type_expected) = &local_expected.pat { - if let Pat::Ident(ident_expected) = &*type_expected.pat { - let pat_expected = &local_expected.pat; - assert_eq!( - pat_actual, pat_expected, - "Wrong type annotated for {}", - ident_expected.ident - ); - expected_count += 1; - } - } - } - } - - assert_eq!(expected_count, stmts_expected.len()); - } + assert_eq!(x, 42, "Expected x to be 42"); + assert_eq!(y, 3.14, "Expected y to be 3.14"); + assert_eq!(z, false, "Expected z to be false"); + assert_eq!(a, 'a', "Expected a to be 'a'"); }