summaryrefslogtreecommitdiff
path: root/morphology-img/tests
diff options
context:
space:
mode:
authorjacksonfu14 <jackson@fashionunited.com>2025-11-16 16:21:37 +0100
committerJackson Moore <jacksonmoore@tuta.io>2025-11-16 16:21:37 +0100
commit3505cc56367feabc60aaffe5e2b899d4d5d00531 (patch)
tree923921a2113ccb8ad9bac1af0a7c8ab13fa5cd8e /morphology-img/tests
parent6aeb5a91c42446b5ea68ec81dd01079a74787c96 (diff)
feature: convert sequences to ly markup
Diffstat (limited to 'morphology-img/tests')
-rw-r--r--morphology-img/tests/note_types.rs (renamed from morphology-img/tests/pitch.rs)10
-rw-r--r--morphology-img/tests/notes_to_markup.rs128
-rw-r--r--morphology-img/tests/pitch_conversion.rs192
-rw-r--r--morphology-img/tests/sequence_conversion.rs231
4 files changed, 552 insertions, 9 deletions
diff --git a/morphology-img/tests/pitch.rs b/morphology-img/tests/note_types.rs
index 986cebc..dad9753 100644
--- a/morphology-img/tests/pitch.rs
+++ b/morphology-img/tests/note_types.rs
@@ -1,4 +1,4 @@
-use morphology_img::pitch::{LilyPondPitch, LilyPondNote, Duration};
+use morphology_img::note::{LilyPondPitch, LilyPondNote, Duration};
#[test]
fn test_lilypond_pitch_creation() {
@@ -41,14 +41,6 @@ fn test_lilypond_note_with_different_duration() {
}
#[test]
-fn test_lilypond_note_with_flat() {
- let pitch = LilyPondPitch::new("bes,");
- let duration = Duration::QUARTER;
- let note = LilyPondNote::new(pitch, duration);
- assert_eq!(note.as_str(), "bes,4");
-}
-
-#[test]
fn test_pitch_equality() {
let pitch1 = LilyPondPitch::new("c'");
let pitch2 = LilyPondPitch::new("c'");
diff --git a/morphology-img/tests/notes_to_markup.rs b/morphology-img/tests/notes_to_markup.rs
new file mode 100644
index 0000000..c540691
--- /dev/null
+++ b/morphology-img/tests/notes_to_markup.rs
@@ -0,0 +1,128 @@
+use morphology_img::note::{LilyPondPitch, LilyPondNote, Duration, notes_to_markup};
+
+#[test]
+fn test_empty_vector() {
+ let notes: Vec<LilyPondNote> = vec![];
+ assert_eq!(notes_to_markup(&notes), "");
+}
+
+#[test]
+fn test_single_note() {
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::QUARTER),
+ ];
+ assert_eq!(notes_to_markup(&notes), "c'4");
+}
+
+#[test]
+fn test_multiple_notes() {
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("d'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("e'"), Duration::QUARTER),
+ ];
+ assert_eq!(notes_to_markup(&notes), "c'4 d'4 e'4");
+}
+
+#[test]
+fn test_example_from_preliminary_overview() {
+ // From overview: ["f'4", "f4", "e4", "b4"]
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("f'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("f"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("e"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("b"), Duration::QUARTER),
+ ];
+ assert_eq!(notes_to_markup(&notes), "f'4 f4 e4 b4");
+}
+
+#[test]
+fn test_notes_with_octave_markers_up() {
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("c''"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("c'''"), Duration::QUARTER),
+ ];
+ assert_eq!(notes_to_markup(&notes), "c'4 c''4 c'''4");
+}
+
+#[test]
+fn test_notes_with_octave_markers_down() {
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("b"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("b,"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("b,,"), Duration::QUARTER),
+ ];
+ assert_eq!(notes_to_markup(&notes), "b4 b,4 b,,4");
+}
+
+#[test]
+fn test_notes_with_different_durations() {
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::new(4)),
+ LilyPondNote::new(LilyPondPitch::new("d'"), Duration::new(8)),
+ LilyPondNote::new(LilyPondPitch::new("e'"), Duration::new(2)),
+ ];
+ assert_eq!(notes_to_markup(&notes), "c'4 d'8 e'2");
+}
+
+#[test]
+fn test_mixed_pitches_and_durations() {
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("f'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("a,"), Duration::new(8)),
+ LilyPondNote::new(LilyPondPitch::new("c''"), Duration::new(2)),
+ LilyPondNote::new(LilyPondPitch::new("b"), Duration::QUARTER),
+ ];
+ assert_eq!(notes_to_markup(&notes), "f'4 a,8 c''2 b4");
+}
+
+#[test]
+fn test_long_sequence() {
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("d'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("e'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("f'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("g'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("a'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("b'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("c''"), Duration::QUARTER),
+ ];
+ assert_eq!(notes_to_markup(&notes), "c'4 d'4 e'4 f'4 g'4 a'4 b'4 c''4");
+}
+
+#[test]
+fn test_duplicate_notes() {
+ // Test with repeated notes
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::QUARTER),
+ ];
+ assert_eq!(notes_to_markup(&notes), "c'4 c'4 c'4");
+}
+
+#[test]
+fn test_spacing_is_single_space() {
+ // Verify that notes are separated by exactly one space
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("d'"), Duration::QUARTER),
+ ];
+ let markup = notes_to_markup(&notes);
+ assert_eq!(markup, "c'4 d'4");
+ // Count spaces
+ assert_eq!(markup.matches(' ').count(), 1);
+}
+
+#[test]
+fn test_no_leading_or_trailing_spaces() {
+ let notes = vec![
+ LilyPondNote::new(LilyPondPitch::new("c'"), Duration::QUARTER),
+ LilyPondNote::new(LilyPondPitch::new("d'"), Duration::QUARTER),
+ ];
+ let markup = notes_to_markup(&notes);
+ assert!(!markup.starts_with(' '));
+ assert!(!markup.ends_with(' '));
+}
diff --git a/morphology-img/tests/pitch_conversion.rs b/morphology-img/tests/pitch_conversion.rs
new file mode 100644
index 0000000..667bf17
--- /dev/null
+++ b/morphology-img/tests/pitch_conversion.rs
@@ -0,0 +1,192 @@
+use morphology_img::note::integer_to_pitch_name;
+
+// Zero case
+#[test]
+fn test_zero_maps_to_b() {
+ assert_eq!(integer_to_pitch_name(0).as_str(), "b");
+}
+
+// Positive cases - basic
+#[test]
+fn test_positive_one_maps_to_c_prime() {
+ assert_eq!(integer_to_pitch_name(1).as_str(), "c'");
+}
+
+#[test]
+fn test_positive_two_maps_to_d_prime() {
+ assert_eq!(integer_to_pitch_name(2).as_str(), "d'");
+}
+
+#[test]
+fn test_positive_three_maps_to_e_prime() {
+ assert_eq!(integer_to_pitch_name(3).as_str(), "e'");
+}
+
+#[test]
+fn test_positive_four_maps_to_f_prime() {
+ assert_eq!(integer_to_pitch_name(4).as_str(), "f'");
+}
+
+#[test]
+fn test_positive_five_maps_to_g_prime() {
+ assert_eq!(integer_to_pitch_name(5).as_str(), "g'");
+}
+
+#[test]
+fn test_positive_six_maps_to_a_prime() {
+ assert_eq!(integer_to_pitch_name(6).as_str(), "a'");
+}
+
+#[test]
+fn test_positive_seven_maps_to_b_prime() {
+ assert_eq!(integer_to_pitch_name(7).as_str(), "b'");
+}
+
+// Negative cases - basic
+#[test]
+fn test_negative_one_maps_to_a() {
+ assert_eq!(integer_to_pitch_name(-1).as_str(), "a");
+}
+
+#[test]
+fn test_negative_two_maps_to_g() {
+ assert_eq!(integer_to_pitch_name(-2).as_str(), "g");
+}
+
+#[test]
+fn test_negative_three_maps_to_f() {
+ assert_eq!(integer_to_pitch_name(-3).as_str(), "f");
+}
+
+#[test]
+fn test_negative_four_maps_to_e() {
+ assert_eq!(integer_to_pitch_name(-4).as_str(), "e");
+}
+
+#[test]
+fn test_negative_five_maps_to_d() {
+ assert_eq!(integer_to_pitch_name(-5).as_str(), "d");
+}
+
+#[test]
+fn test_negative_six_maps_to_c() {
+ assert_eq!(integer_to_pitch_name(-6).as_str(), "c");
+}
+
+#[test]
+fn test_negative_seven_maps_to_b_comma() {
+ assert_eq!(integer_to_pitch_name(-7).as_str(), "b,");
+}
+
+// Multiple octaves up
+#[test]
+fn test_eight_maps_to_c_double_prime() {
+ assert_eq!(integer_to_pitch_name(8).as_str(), "c''");
+}
+
+#[test]
+fn test_fourteen_maps_to_b_double_prime() {
+ assert_eq!(integer_to_pitch_name(14).as_str(), "b''");
+}
+
+#[test]
+fn test_fifteen_maps_to_c_triple_prime() {
+ assert_eq!(integer_to_pitch_name(15).as_str(), "c'''");
+}
+
+#[test]
+fn test_twenty_one_maps_to_b_triple_prime() {
+ assert_eq!(integer_to_pitch_name(21).as_str(), "b'''");
+}
+
+// Multiple octaves down
+#[test]
+fn test_negative_eight_maps_to_a_comma() {
+ assert_eq!(integer_to_pitch_name(-8).as_str(), "a,");
+}
+
+#[test]
+fn test_negative_fourteen_maps_to_b_double_comma() {
+ assert_eq!(integer_to_pitch_name(-14).as_str(), "b,,");
+}
+
+#[test]
+fn test_negative_fifteen_maps_to_a_double_comma() {
+ assert_eq!(integer_to_pitch_name(-15).as_str(), "a,,");
+}
+
+#[test]
+fn test_negative_twenty_one_maps_to_b_triple_comma() {
+ assert_eq!(integer_to_pitch_name(-21).as_str(), "b,,,");
+}
+
+// Edge cases across octave boundaries
+#[test]
+fn test_octave_boundary_b_to_c_ascending() {
+ // B at reference octave
+ assert_eq!(integer_to_pitch_name(0).as_str(), "b");
+ // C in next octave
+ assert_eq!(integer_to_pitch_name(1).as_str(), "c'");
+}
+
+#[test]
+fn test_octave_boundary_c_to_b_descending() {
+ // C at reference octave
+ assert_eq!(integer_to_pitch_name(-6).as_str(), "c");
+ // B in octave below
+ assert_eq!(integer_to_pitch_name(-7).as_str(), "b,");
+}
+
+#[test]
+fn test_complete_ascending_scale_from_b() {
+ let expected = vec!["b", "c'", "d'", "e'", "f'", "g'", "a'", "b'"];
+ for (i, expected_pitch) in expected.iter().enumerate() {
+ assert_eq!(
+ integer_to_pitch_name(i as i32).as_str(),
+ *expected_pitch,
+ "Failed at index {}", i
+ );
+ }
+}
+
+#[test]
+fn test_complete_descending_scale_from_b() {
+ let expected = vec!["b", "a", "g", "f", "e", "d", "c", "b,"];
+ for (i, expected_pitch) in expected.iter().enumerate() {
+ assert_eq!(
+ integer_to_pitch_name(-(i as i32)).as_str(),
+ *expected_pitch,
+ "Failed at index -{}", i
+ );
+ }
+}
+
+#[test]
+fn test_example_from_preliminary_overview() {
+ // From the preliminary overview: [4, -3, -4, 0] becomes ["f'", "f", "e", "b"]
+ assert_eq!(integer_to_pitch_name(4).as_str(), "f'");
+ assert_eq!(integer_to_pitch_name(-3).as_str(), "f");
+ assert_eq!(integer_to_pitch_name(-4).as_str(), "e");
+ assert_eq!(integer_to_pitch_name(0).as_str(), "b");
+}
+
+#[test]
+fn test_symmetry_property() {
+ // Test that going up 7 and down 7 from reference gives B in adjacent octaves
+ assert_eq!(integer_to_pitch_name(7).as_str(), "b'");
+ assert_eq!(integer_to_pitch_name(-7).as_str(), "b,");
+}
+
+#[test]
+fn test_large_positive_value() {
+ // Test a very large value to ensure no overflow
+ // 100 + 6 = 106; 106 / 7 = 15 remainder 1; pitch_index = 1 (d), octave = 15
+ assert_eq!(integer_to_pitch_name(100).as_str(), "d'''''''''''''''");
+}
+
+#[test]
+fn test_large_negative_value() {
+ // Test a very large negative value
+ // -100 + 6 = -94; -94.div_euclid(7) = -14; -94.rem_euclid(7) = 4 (g)
+ assert_eq!(integer_to_pitch_name(-100).as_str(), "g,,,,,,,,,,,,,,");
+}
diff --git a/morphology-img/tests/sequence_conversion.rs b/morphology-img/tests/sequence_conversion.rs
new file mode 100644
index 0000000..9889448
--- /dev/null
+++ b/morphology-img/tests/sequence_conversion.rs
@@ -0,0 +1,231 @@
+use meta_affine::{Sequence, Value};
+use morphology_img::note::sequence_to_notes;
+
+#[test]
+fn test_example_from_preliminary_overview() {
+ // Example from preliminary overview: [(1,0), (-1,1), (-1,0), (0,0)]
+ // Length = 4
+ // Expected integers: [4, -3, -4, 0]
+ // Expected pitches: ["f'", "f", "e", "b"]
+ // Expected notes: ["f'4", "f4", "e4", "b4"]
+
+ let seq = Sequence::new(vec![
+ Value::new(1, 0),
+ Value::new(-1, 1),
+ Value::new(-1, 0),
+ Value::new(0, 0),
+ ]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 4);
+ assert_eq!(notes[0].as_str(), "f'4");
+ assert_eq!(notes[1].as_str(), "f4");
+ assert_eq!(notes[2].as_str(), "e4");
+ assert_eq!(notes[3].as_str(), "b4");
+}
+
+#[test]
+fn test_single_element_sequence() {
+ // Single origin value
+ let seq = Sequence::new(vec![Value::origin()]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 1);
+ // (0 * 1) + 0 = 0 -> "b"
+ assert_eq!(notes[0].as_str(), "b4");
+}
+
+#[test]
+fn test_sequence_with_all_zeros() {
+ // All origin values
+ let seq = Sequence::new(vec![
+ Value::origin(),
+ Value::origin(),
+ Value::origin(),
+ ]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 3);
+ // All should be (0 * 3) + 0 = 0 -> "b"
+ assert_eq!(notes[0].as_str(), "b4");
+ assert_eq!(notes[1].as_str(), "b4");
+ assert_eq!(notes[2].as_str(), "b4");
+}
+
+#[test]
+fn test_sequence_with_positive_outer() {
+ // Sequence with positive outer values
+ let seq = Sequence::new(vec![
+ Value::new(1, 0),
+ Value::new(0, 0),
+ ]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 2);
+ // (1 * 2) + 0 = 2 -> "d'"
+ assert_eq!(notes[0].as_str(), "d'4");
+ // (0 * 2) + 0 = 0 -> "b"
+ assert_eq!(notes[1].as_str(), "b4");
+}
+
+#[test]
+fn test_sequence_with_negative_outer() {
+ // Sequence with negative outer values
+ let seq = Sequence::new(vec![
+ Value::new(-1, 0),
+ Value::new(0, 0),
+ ]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 2);
+ // (-1 * 2) + 0 = -2 -> "g"
+ assert_eq!(notes[0].as_str(), "g4");
+ // (0 * 2) + 0 = 0 -> "b"
+ assert_eq!(notes[1].as_str(), "b4");
+}
+
+#[test]
+fn test_sequence_with_inner_values() {
+ // Sequence with various inner values
+ let seq = Sequence::new(vec![
+ Value::new(0, 1),
+ Value::new(0, -1),
+ Value::new(0, 0),
+ ]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 3);
+ // (0 * 3) + 1 = 1 -> "c'"
+ assert_eq!(notes[0].as_str(), "c'4");
+ // (0 * 3) + (-1) = -1 -> "a"
+ assert_eq!(notes[1].as_str(), "a4");
+ // (0 * 3) + 0 = 0 -> "b"
+ assert_eq!(notes[2].as_str(), "b4");
+}
+
+#[test]
+fn test_sequence_with_mixed_values() {
+ // Sequence with mix of outer and inner values
+ let seq = Sequence::new(vec![
+ Value::new(2, 3),
+ Value::new(-1, -2),
+ Value::new(1, 1),
+ Value::new(0, 0),
+ ]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 4);
+ // (2 * 4) + 3 = 11 -> "f''"
+ assert_eq!(notes[0].as_str(), "f''4");
+ // (-1 * 4) + (-2) = -6 -> "c"
+ assert_eq!(notes[1].as_str(), "c4");
+ // (1 * 4) + 1 = 5 -> "g'"
+ assert_eq!(notes[2].as_str(), "g'4");
+ // (0 * 4) + 0 = 0 -> "b"
+ assert_eq!(notes[3].as_str(), "b4");
+}
+
+#[test]
+fn test_sequence_length_two() {
+ // Test a simple length-2 sequence
+ let seq = Sequence::new(vec![
+ Value::new(1, 0),
+ Value::new(0, 0),
+ ]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 2);
+ assert_eq!(notes[0].as_str(), "d'4");
+ assert_eq!(notes[1].as_str(), "b4");
+}
+
+#[test]
+fn test_length_affects_pitch_calculation() {
+ // Test that sequence length affects the pitch calculation
+ // Value (1, 0) with length 2 vs length 4 should give different pitches
+
+ let seq2 = Sequence::new(vec![
+ Value::new(1, 0),
+ Value::new(0, 0),
+ ]);
+ let notes2 = sequence_to_notes(&seq2);
+ // (1 * 2) + 0 = 2
+ assert_eq!(notes2[0].as_str(), "d'4");
+
+ let seq4 = Sequence::new(vec![
+ Value::new(1, 0),
+ Value::new(0, 0),
+ Value::new(0, 0),
+ Value::new(0, 0),
+ ]);
+ let notes4 = sequence_to_notes(&seq4);
+ // (1 * 4) + 0 = 4
+ assert_eq!(notes4[0].as_str(), "f'4");
+}
+
+#[test]
+fn test_extreme_values() {
+ // Test with extreme positive and negative values
+ let seq = Sequence::new(vec![
+ Value::new(10, 5),
+ Value::new(-10, -5),
+ Value::new(0, 0),
+ ]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 3);
+ // (10 * 3) + 5 = 35 -> "b'''''"
+ assert_eq!(notes[0].as_str(), "b'''''4");
+ // (-10 * 3) + (-5) = -35 -> "b,,,,"
+ assert_eq!(notes[1].as_str(), "b,,,,,4");
+ // (0 * 3) + 0 = 0 -> "b"
+ assert_eq!(notes[2].as_str(), "b4");
+}
+
+#[test]
+fn test_empty_sequence() {
+ // Edge case: empty sequence
+ let seq = Sequence::new(vec![]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 0);
+}
+
+#[test]
+fn test_notes_preserve_sequence_order() {
+ // Verify that notes maintain the same order as input sequence
+ let seq = Sequence::new(vec![
+ Value::new(3, 1),
+ Value::new(2, 2),
+ Value::new(1, 3),
+ Value::new(0, 4),
+ Value::new(-1, 5),
+ Value::new(0, 0),
+ ]);
+
+ let notes = sequence_to_notes(&seq);
+
+ assert_eq!(notes.len(), 6);
+ // Verify they're all different (order matters)
+ for i in 0..notes.len() {
+ for j in (i+1)..notes.len() {
+ // Most should be different, though some might coincidentally match
+ // The important thing is the order is preserved
+ let note_i = notes[i].as_str();
+ let note_j = notes[j].as_str();
+ // Just verify we got valid notes for all positions
+ assert!(note_i.ends_with('4'));
+ assert!(note_j.ends_with('4'));
+ }
+ }
+}