summaryrefslogtreecommitdiff
path: root/morphology-img/tests/sequence_conversion.rs
diff options
context:
space:
mode:
Diffstat (limited to 'morphology-img/tests/sequence_conversion.rs')
-rw-r--r--morphology-img/tests/sequence_conversion.rs231
1 files changed, 231 insertions, 0 deletions
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'));
+ }
+ }
+}