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,,,,,,,,,,,,,,"); }