#![allow(warnings)]
use jazz_chord::*;
use std::collections::HashMap;
fn main() {
println!("Hello, world!");
}
#[cfg(test)]
mod tests {
use std::collections::HashMap;
use std::fmt::Display;
use jazz_chord::*;
#[test]
fn it_works() {
let chord1 = ChordQuality::from_string("ma6");
let chord2 = ChordQuality::from_string("m6");
}
#[test]
fn test_note(){
let note = Note::new("b5").unwrap();
assert_eq!(note.accidentals.data, "b");
assert_eq!(note.degree.data, "5" );
assert!(Note::new("5b").is_none());
assert!(Note::new("bb5").is_some());
let bad_note = Note::new("b");
assert_eq!(bad_note, None);
let note = Note::new("bbb5").unwrap();
println!("Note::new({:?}) accidentals:{:?} degree:{:?} frets_from_one:{:?}",note.text,note.accidentals,note.degree, note.fret());
}
#[test]
fn test_key(){
let data = "Abbb";
let bad_datas = vec!("bA","b2");
let key = Key::new(data);
if let Some(key) = key{
println!("Key::new({:?}) == {:?} frets_from_c: {:?}", data,key.clone(),key.frets_from_c());
assert_eq!(key.frets_from_c(),6);
assert_eq!(Key::new("B###").unwrap().frets_from_c(),2);
assert_eq!(Key::new("Cbbb").unwrap().frets_from_c(),9);
} else {
println!("Key::new({:?}) is invalid", data)
}
for bad_data in bad_datas {
assert_eq!(Key::new(&*String::from(bad_data)), None, "bad_data: {:?} should not be valid", bad_data);
println!("{:?} is not a valid Key", bad_data);
}
}
#[test]
fn test_chord_quality(){
let datas = vec![
("sus4", Change::from("1 4 5")),
("susb2", Change::from("1 b2 5")),
("6", Change::from("1 3 5 6")),
("mi6", Change::from("1 b3 5 6")),
("7", Change::from("1 3 5 b7")),
("ma", Change::from("1 3 5")),
("m", Change::from("1 b3 5")),
("7(b9)", Change::from("1 3 5 b7 b9")),
("7b9", Change::from("1 3 5 b7 b9")),
("13", Change::from("1 3 5 b7 9 11 13")),
("13(#5)", Change::from("1 3 #5 b7 9 11 13")),
("7sus4(b5)", Change::from("1 4 b5 b7")),
("ma9sus4(b5)", Change::from("1 4 b5 7 9")),
("9sus4(b5)", Change::from("1 4 b5 b7 9")),
("mima7", Change::from("1 b3 5 7")),
];
for data in datas.iter() {
let chord_input = data.0;
let test_change = &data.1;
let chord_change = ChordQuality::from_string(&*chord_input).unwrap_or_default().to_change();
let is_legit = chord_change == *test_change;
if !is_legit{
print!{"!!"}
}
print!("ChordQuality::from_string({:?}) => ", chord_input);
if let Some(chord) = ChordQuality::from_string(&*chord_input) {
println!("{} == {}",chord, chord.short_debug());
if !is_legit{
println!("?? {test_change} != {chord_change}");
}
}
else {
println!("Invalid ChordQuality!");
}
}
}
#[test]
fn test_other_stuff(){
let solar_distance = HashMap::from([
("Mercury", 0.4),
("Venus", 0.7),
("Earth", 1.0),
("Mars", 1.5),
]);
}
}