Skip to content

Commit

Permalink
fix: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldivis committed Oct 31, 2023
1 parent 07e5e7a commit 64a6201
Showing 1 changed file with 73 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
namespace DarkMusicConcepts;

public class ChordInvertTests
public class ChordInversionTests
{
public static IEnumerable<Note> NotesUpTo7ThOctave => Notes.All.Where(a => a.Octave <= Octave.Seven);
private static readonly IEnumerable<Note> _notesUpTo7ThOctave = Notes.All.Where(a => a.Octave <= Octave.Seven);

public class InvertCommonTriadsTests
public class CommonTriads
{
private static readonly ChordFormula[] commonTriads =
private static readonly ChordFormula[] _commonTriads =
{
ChordFormulas.Major,
ChordFormulas.Minor,
ChordFormulas.Diminished,
ChordFormulas.Augmented
};

public static IEnumerable<object[]> CommonTriadsTestData
public static IEnumerable<object[]> CommonTriadsTestData { get; } = CreateCommonTriadsTestData();

private static IEnumerable<object[]> CreateCommonTriadsTestData()
{
get
foreach (var chordFormula in _commonTriads)
{
foreach (var chordFormula in commonTriads)
foreach (var rootNote in NotesUpTo7ThOctave)
foreach (var rootNote in _notesUpTo7ThOctave)
{
yield return new object[] { chordFormula, rootNote };
}
}
}

Expand All @@ -32,7 +35,13 @@ public void Invert_Once_ShouldReturn_FirstInversion(ChordFormula chordFormula, N

var inversion1 = chord.Invert();

inversion1.Notes.Should().Equal(chord.Notes[1], chord.Notes[2], chord.Notes[0].TransposeUp(Intervals.PerfectOctave));
inversion1.Notes
.Should()
.Equal(
chord.Notes[1],
chord.Notes[2],
chord.Notes[0].TransposeUp(Intervals.PerfectOctave));

inversion1.Inversion.Should().Be(1);
}

Expand All @@ -44,8 +53,13 @@ public void Invert_Twice_ShouldReturn_SecondInversion(ChordFormula chordFormula,

var inversion2 = chord.Invert().Invert();

inversion2.Notes.Should().Equal(chord.Notes[2], chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave));
inversion2.Notes
.Should()
.Equal(
chord.Notes[2],
chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave));

inversion2.Inversion.Should().Be(2);
}

Expand All @@ -57,16 +71,20 @@ public void Invert_ThreeTimes_ShouldReturn_InitialTriad_OneOctaveHigher(ChordFor

var inversion2 = chord.Invert().Invert().Invert();

inversion2.Notes.Should().Equal(
chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave), chord.Notes[2].TransposeUp(Intervals.PerfectOctave));
inversion2.Notes
.Should()
.Equal(
chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave),
chord.Notes[2].TransposeUp(Intervals.PerfectOctave));

inversion2.Inversion.Should().Be(0);
}
}

public class InvertCommonSeventhChordsTests
public class CommonSeventhChords
{
private static readonly ChordFormula[] commonTriads =
private static readonly ChordFormula[] _commonSeventhChords =
{
ChordFormulas.DominantSeventh,
ChordFormulas.MajorSeventh,
Expand All @@ -75,13 +93,16 @@ public class InvertCommonSeventhChordsTests
ChordFormulas.DiminishedSeventh
};

public static IEnumerable<object[]> CommonSeventhChordsTestData
public static IEnumerable<object[]> CommonSeventhChordsTestData { get; } = CreateCommonSeventhChordsTestData();

private static IEnumerable<object[]> CreateCommonSeventhChordsTestData()
{
get
foreach (var chordFormula in _commonSeventhChords)
{
foreach (var chordFormula in commonTriads)
foreach (var rootNote in NotesUpTo7ThOctave)
foreach (var rootNote in _notesUpTo7ThOctave)
{
yield return new object[] { chordFormula, rootNote };
}
}
}

Expand All @@ -93,11 +114,14 @@ public void Invert_Once_ShouldReturn_FirstInversion(ChordFormula chordFormula, N

var inversion1 = chord.Invert();

inversion1.Notes.Should().Equal(
chord.Notes[1],
chord.Notes[2],
chord.Notes[3],
chord.Notes[0].TransposeUp(Intervals.PerfectOctave));
inversion1.Notes
.Should()
.Equal(
chord.Notes[1],
chord.Notes[2],
chord.Notes[3],
chord.Notes[0].TransposeUp(Intervals.PerfectOctave));

inversion1.Inversion.Should().Be(1);
}

Expand All @@ -109,11 +133,14 @@ public void Invert_Twice_ShouldReturn_SecondInversion(ChordFormula chordFormula,

var inversion2 = chord.Invert().Invert();

inversion2.Notes.Should().Equal(
chord.Notes[2],
chord.Notes[3],
chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave));
inversion2.Notes
.Should()
.Equal(
chord.Notes[2],
chord.Notes[3],
chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave));

inversion2.Inversion.Should().Be(2);
}

Expand All @@ -125,11 +152,14 @@ public void Invert_ThreeTimes_ShouldReturn_ThirdInversion(ChordFormula chordForm

var inversion2 = chord.Invert().Invert().Invert();

inversion2.Notes.Should().Equal(
chord.Notes[3],
chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave),
chord.Notes[2].TransposeUp(Intervals.PerfectOctave));
inversion2.Notes
.Should()
.Equal(
chord.Notes[3],
chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave),
chord.Notes[2].TransposeUp(Intervals.PerfectOctave));

inversion2.Inversion.Should().Be(3);
}

Expand All @@ -141,11 +171,14 @@ public void Invert_FourTimes_ShouldReturn_InitialSeventhChord_OneOctaveHigher(Ch

var inversion2 = chord.Invert().Invert().Invert().Invert();

inversion2.Notes.Should().Equal(
chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave),
chord.Notes[2].TransposeUp(Intervals.PerfectOctave),
chord.Notes[3].TransposeUp(Intervals.PerfectOctave));
inversion2.Notes
.Should()
.Equal(
chord.Notes[0].TransposeUp(Intervals.PerfectOctave),
chord.Notes[1].TransposeUp(Intervals.PerfectOctave),
chord.Notes[2].TransposeUp(Intervals.PerfectOctave),
chord.Notes[3].TransposeUp(Intervals.PerfectOctave));

inversion2.Inversion.Should().Be(0);
}
}
Expand Down

0 comments on commit 64a6201

Please sign in to comment.