< Summary

Information
Class: MusicTheory.Theory.Interval.IntervalUtils
Assembly: MusicTheory
File(s): /home/runner/work/MusicTheory/MusicTheory/Theory/Interval/interval.cs
Line coverage
86%
Covered lines: 38
Uncovered lines: 6
Coverable lines: 44
Total lines: 83
Line coverage: 86.3%
Branch coverage
79%
Covered branches: 23
Total branches: 29
Branch coverage: 79.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetIntervalName(...)79.31%322984.61%
Between(...)100%11100%
DegreeBetween(...)100%11100%
IsEnharmonic(...)100%11100%

File(s)

/home/runner/work/MusicTheory/MusicTheory/Theory/Interval/interval.cs

#LineLine coverage
 1using MusicTheory.Theory.Pitch;
 2
 3namespace MusicTheory.Theory.Interval
 4{
 5    public enum IntervalQuality { Perfect, Major, Minor, Augmented, Diminished, DoublyAugmented, DoublyDiminished }
 6
 7    public readonly record struct IntervalName(IntervalQuality Quality, int Number)
 8    {
 9        public string ToJapaneseString() => Quality switch
 10        {
 11            IntervalQuality.Perfect => $"完全{Number}",
 12            IntervalQuality.Major => $"長{Number}",
 13            IntervalQuality.Minor => $"短{Number}",
 14            IntervalQuality.Augmented => $"増{Number}",
 15            IntervalQuality.Diminished => $"減{Number}",
 16            IntervalQuality.DoublyAugmented => $"重増{Number}",
 17            IntervalQuality.DoublyDiminished => $"重減{Number}",
 18            _ => $"?{Number}"
 19        };
 20
 21        public override string ToString() => $"{Quality} {Number}";
 22    }
 23
 24    public static class IntervalUtils
 25    {
 26    public static IntervalName GetIntervalName(FunctionalInterval ivl)
 27        {
 1228            int semitones = ivl.Semitones;
 1229            int octaves = semitones / 12;
 1230            int remainder = semitones % 12;
 1231            int number = octaves * 7 + (remainder switch
 1232            {
 233                0 => 1,
 134                1 => 2,
 135                2 => 2,
 136                3 => 2,
 137                4 => 3,
 138                5 => 3,
 139                6 => 4,
 140                7 => 4,
 141                8 => 4,
 042                9 => 5,
 143                10 => 6,
 144                11 => 6,
 045                _ => 1
 1246            });
 47
 1248            IntervalQuality quality = semitones switch
 1249            {
 150                0 => IntervalQuality.Perfect,
 151                1 => IntervalQuality.DoublyDiminished,
 152                2 => IntervalQuality.Minor,
 153                3 => IntervalQuality.Major,
 154                4 => IntervalQuality.Minor,
 155                5 => IntervalQuality.Major,
 156                6 => IntervalQuality.Perfect,
 157                7 => IntervalQuality.Augmented,
 158                8 => IntervalQuality.DoublyAugmented,
 059                9 => IntervalQuality.Perfect,
 160                10 => IntervalQuality.Minor,
 161                11 => IntervalQuality.Major,
 162                12 => IntervalQuality.Minor,
 063                13 => IntervalQuality.Major,
 064                14 => IntervalQuality.Perfect,
 065                _ => IntervalQuality.Augmented
 1266            };
 67
 1268            return new IntervalName(quality, number);
 69        }
 70
 471    public static FunctionalInterval Between(MusicTheory.Theory.Pitch.Pitch a, MusicTheory.Theory.Pitch.Pitch b) => new 
 72
 73    public static int DegreeBetween(MusicTheory.Theory.Pitch.Pitch a, MusicTheory.Theory.Pitch.Pitch b)
 74        {
 375            int aIndex = (int)a.Spelling.Letter + a.Octave * 7;
 376            int bIndex = (int)b.Spelling.Letter + b.Octave * 7;
 377            return bIndex - aIndex + 1;
 78        }
 79
 80        public static bool IsEnharmonic(MusicTheory.Theory.Pitch.Pitch a, MusicTheory.Theory.Pitch.Pitch b)
 381            => PitchUtils.ToPc(a).Pc == PitchUtils.ToPc(b).Pc;
 82    }
 83}