Skip to content

Commit

Permalink
test_create_guitar_compositions
Browse files Browse the repository at this point in the history
  • Loading branch information
noahbaculi committed Jul 26, 2023
1 parent 2f88b6a commit e8fa9dd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- run: cargo build
- run: cargo clippy -- -D warnings
- run: cargo build --examples --benches
- run: cargo clippy --examples --benches -- -D warnings

test:
name: Test
Expand Down
42 changes: 41 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct CompositionInput {
}

#[wasm_bindgen(getter_with_clone)]
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Composition {
pub tab: String,
pub max_fret_span: u8,
Expand Down Expand Up @@ -75,3 +75,43 @@ pub fn create_guitar_compositions(composition_input: CompositionInput) -> Result

Ok(compositions)
}
#[cfg(test)]
mod test_create_guitar_compositions {
use super::*;

#[test]
fn test_create_guitar_compositions_valid_input() {
let composition_input = CompositionInput {
pitches: "E2\nA2\nD3\nG3\nB3\nE4".to_owned(),
tuning_name: "standard".to_string(),
guitar_num_frets: 20,
guitar_capo: 0,
num_arrangements: 1,
width: 24,
padding: 2,
playback_index: Some(3),
};

let compositions = create_guitar_compositions(composition_input).unwrap();
let expected_composition = Composition {
tab: " ▼\n-----------------0------\n--------------0---------\n-----------0------------\n--------0---------------\n-----0------------------\n--0---------------------\n\n".to_owned(),
max_fret_span: 0,
};

assert_eq!(compositions[0], expected_composition);
}
#[test]
fn test_error() {
let composition_input = CompositionInput {
pitches: "E2\nA2\nD3\n???\nG3\nB3\nE4".to_owned(),
tuning_name: "standard".to_string(),
guitar_num_frets: 20,
guitar_capo: 0,
num_arrangements: 1,
width: 20,
padding: 2,
playback_index: Some(3),
};
assert!(create_guitar_compositions(composition_input).is_err());
}
}

0 comments on commit e8fa9dd

Please sign in to comment.