summaryrefslogtreecommitdiff
path: root/morphology-img/tests
diff options
context:
space:
mode:
authorjacksonfu14 <jackson@fashionunited.com>2025-11-18 07:08:34 +0100
committerJackson Moore <jacksonmoore@tuta.io>2025-11-18 07:08:34 +0100
commitef99dc9a636e38f7626156c3d3e4b80e285547f8 (patch)
tree64f2c9c6673ba028d824819f8ba89311550cbd49 /morphology-img/tests
parentf0b8343ae19231d6a7e4435a114ecb210d893179 (diff)
modify sequence to ly conversion
Diffstat (limited to 'morphology-img/tests')
-rw-r--r--morphology-img/tests/file_gen.rs23
-rw-r--r--morphology-img/tests/sequence_conversion.rs83
2 files changed, 61 insertions, 45 deletions
diff --git a/morphology-img/tests/file_gen.rs b/morphology-img/tests/file_gen.rs
index e459688..167a9d8 100644
--- a/morphology-img/tests/file_gen.rs
+++ b/morphology-img/tests/file_gen.rs
@@ -456,13 +456,14 @@ fn test_generate_ly_files_preserves_order() {
let content = fs::read_to_string(path).unwrap();
// Verify the content corresponds to the right sequence
- // Sequence with Value::new(outer, 0) and length 1 gives pitch = outer * 1 + 0 = outer
- // Then integer_to_pitch_name: 5→g', 3→e', 1→c'
- // (5+6=11, 11%7=4→"g", 11/7=1→') (3+6=9, 9%7=2→"e", 9/7=1→') (1+6=7, 7%7=0→"c", 7/7=1→')
+ // Sequence with Value::new(outer, 0), max_abs_inner = 0, multiplier = 3
+ // pitch = outer * 3 + 0
+ // Then integer_to_pitch_name: 15→c''', 9→d'', 3→e'
+ // (15+6=21, 21%7=0→"c", 21/7=3→''') (9+6=15, 15%7=1→"d", 15/7=2→'') (3+6=9, 9%7=2→"e", 9/7=1→')
match i {
- 0 => assert!(content.contains("g'4"), "first file should have sequence 0 content"),
- 1 => assert!(content.contains("e'4"), "second file should have sequence 1 content"),
- 2 => assert!(content.contains("c'4"), "third file should have sequence 2 content"),
+ 0 => assert!(content.contains("c'''4"), "first file should have sequence 0 content"),
+ 1 => assert!(content.contains("d''4"), "second file should have sequence 1 content"),
+ 2 => assert!(content.contains("e'4"), "third file should have sequence 2 content"),
_ => panic!("unexpected index"),
}
}
@@ -522,12 +523,16 @@ fn test_complete_ly_generation_pipeline() {
}
// Verify specific content for first file
+ // Sequence: [(1,0), (-1,1), (-1,0), (0,0)]
+ // max_abs_inner = 1, multiplier = 4
+ // Pitches: 1*4+0=4, -1*4+1=-3, -1*4+0=-4, 0*4+0=0 → f'4 f4 e4 b4
let content0 = fs::read_to_string(&ly_paths[0]).unwrap();
assert!(content0.contains("f'4 f4 e4 b4"), "first file should have correct markup");
// Verify specific content for second file
- // Sequence has length 2: [(0,0), (1,0)]
- // Pitches: 0*2+0=0→b4, 1*2+0=2→d'4
+ // Sequence: [(0,0), (1,0)]
+ // max_abs_inner = 0, multiplier = 3
+ // Pitches: 0*3+0=0→b4, 1*3+0=3→e'4
let content1 = fs::read_to_string(&ly_paths[1]).unwrap();
- assert!(content1.contains("b4 d'4"), "second file should have correct markup");
+ assert!(content1.contains("b4 e'4"), "second file should have correct markup");
}
diff --git a/morphology-img/tests/sequence_conversion.rs b/morphology-img/tests/sequence_conversion.rs
index 30cd494..72d4c51 100644
--- a/morphology-img/tests/sequence_conversion.rs
+++ b/morphology-img/tests/sequence_conversion.rs
@@ -33,7 +33,8 @@ fn test_single_element_sequence() {
let notes = sequence_to_notes(&seq);
assert_eq!(notes.len(), 1);
- // (0 * 1) + 0 = 0 -> "b"
+ // max_abs_inner = 0, multiplier = 3
+ // (0 * 3) + 0 = 0 -> "b"
assert_eq!(notes[0].as_str(), "b4");
}
@@ -49,6 +50,7 @@ fn test_sequence_with_all_zeros() {
let notes = sequence_to_notes(&seq);
assert_eq!(notes.len(), 3);
+ // max_abs_inner = 0, multiplier = 3
// All should be (0 * 3) + 0 = 0 -> "b"
assert_eq!(notes[0].as_str(), "b4");
assert_eq!(notes[1].as_str(), "b4");
@@ -66,9 +68,10 @@ fn test_sequence_with_positive_outer() {
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"
+ // max_abs_inner = 0, multiplier = 3
+ // (1 * 3) + 0 = 3 -> "e'"
+ assert_eq!(notes[0].as_str(), "e'4");
+ // (0 * 3) + 0 = 0 -> "b"
assert_eq!(notes[1].as_str(), "b4");
}
@@ -83,9 +86,10 @@ fn test_sequence_with_negative_outer() {
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"
+ // max_abs_inner = 0, multiplier = 3
+ // (-1 * 3) + 0 = -3 -> "f"
+ assert_eq!(notes[0].as_str(), "f4");
+ // (0 * 3) + 0 = 0 -> "b"
assert_eq!(notes[1].as_str(), "b4");
}
@@ -101,11 +105,12 @@ fn test_sequence_with_inner_values() {
let notes = sequence_to_notes(&seq);
assert_eq!(notes.len(), 3);
- // (0 * 3) + 1 = 1 -> "c'"
+ // max_abs_inner = 1, multiplier = 4
+ // (0 * 4) + 1 = 1 -> "c'"
assert_eq!(notes[0].as_str(), "c'4");
- // (0 * 3) + (-1) = -1 -> "a"
+ // (0 * 4) + (-1) = -1 -> "a"
assert_eq!(notes[1].as_str(), "a4");
- // (0 * 3) + 0 = 0 -> "b"
+ // (0 * 4) + 0 = 0 -> "b"
assert_eq!(notes[2].as_str(), "b4");
}
@@ -122,13 +127,14 @@ fn test_sequence_with_mixed_values() {
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"
+ // max_abs_inner = 3, multiplier = 6
+ // (2 * 6) + 3 = 15 -> "c'''"
+ assert_eq!(notes[0].as_str(), "c'''4");
+ // (-1 * 6) + (-2) = -8 -> "a,"
+ assert_eq!(notes[1].as_str(), "a,4");
+ // (1 * 6) + 1 = 7 -> "b'"
+ assert_eq!(notes[2].as_str(), "b'4");
+ // (0 * 6) + 0 = 0 -> "b"
assert_eq!(notes[3].as_str(), "b4");
}
@@ -143,32 +149,36 @@ fn test_sequence_length_two() {
let notes = sequence_to_notes(&seq);
assert_eq!(notes.len(), 2);
- assert_eq!(notes[0].as_str(), "d'4");
+ // max_abs_inner = 0, multiplier = 3
+ assert_eq!(notes[0].as_str(), "e'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
+fn test_max_inner_affects_pitch_calculation() {
+ // Test that max_abs_inner affects the pitch calculation
+ // Value (1, 0) should give different pitches depending on other inner values
- let seq2 = Sequence::new(vec![
+ // Sequence with max_abs_inner = 0
+ let seq1 = 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 notes1 = sequence_to_notes(&seq1);
+ // max_abs_inner = 0, multiplier = 3
+ // (1 * 3) + 0 = 3
+ assert_eq!(notes1[0].as_str(), "e'4");
- let seq4 = Sequence::new(vec![
+ // Sequence with max_abs_inner = 2
+ let seq2 = Sequence::new(vec![
Value::new(1, 0),
- Value::new(0, 0),
- Value::new(0, 0),
+ Value::new(0, 2),
Value::new(0, 0),
]);
- let notes4 = sequence_to_notes(&seq4);
- // (1 * 4) + 0 = 4
- assert_eq!(notes4[0].as_str(), "f'4");
+ let notes2 = sequence_to_notes(&seq2);
+ // max_abs_inner = 2, multiplier = 5
+ // (1 * 5) + 0 = 5
+ assert_eq!(notes2[0].as_str(), "g'4");
}
#[test]
@@ -183,11 +193,12 @@ fn test_extreme_values() {
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"
+ // max_abs_inner = 5, multiplier = 8
+ // (10 * 8) + 5 = 85 -> "c'''''''''''''"
+ assert_eq!(notes[0].as_str(), "c'''''''''''''4");
+ // (-10 * 8) + (-5) = -85 -> "a,,,,,,,,,,,,"
+ assert_eq!(notes[1].as_str(), "a,,,,,,,,,,,,4");
+ // (0 * 8) + 0 = 0 -> "b"
assert_eq!(notes[2].as_str(), "b4");
}