Skip to content

Commit

Permalink
desc
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodesdev committed Jan 13, 2025
1 parent 874d0b8 commit aba1388
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 62 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions challenges/primitive-data-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
name = "primitive-data-types"
version = "0.1.0"
edition = "2021"

[dev-dependencies]
syntest = { version = "0.1.0", path = "../../crates/syntest" }
8 changes: 5 additions & 3 deletions challenges/primitive-data-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)
}
12 changes: 7 additions & 5 deletions challenges/primitive-data-types/src/starter.rs
Original file line number Diff line number Diff line change
@@ -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
}
56 changes: 8 additions & 48 deletions challenges/primitive-data-types/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -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'");
}

0 comments on commit aba1388

Please sign in to comment.