Skip to content

Commit

Permalink
Add tests and chords (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders authored Dec 31, 2023
1 parent c9d1ffb commit b9fece7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/MusicTheory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export Major_2nd, Minor_2nd, Major_3rd, Minor_3rd, Perfect_4th, Perfect_5th,
export Scale
export major_scale, natural_minor_scale, melodic_minor_scale, harmonic_minor_scale

export Chord


include("notes.jl")
include("intervals.jl")
include("scales.jl")
include("chords.jl")
end
2 changes: 1 addition & 1 deletion src/notes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ end
PitchClass(n::PitchClass) = n



Base.isless(n1::PitchClass, n2::PitchClass) = semitone(n1) < semitone(n2)
Base.isless(n1::Pitch, n2::Pitch) = semitone(n1) < semitone(n2)


Expand Down
20 changes: 20 additions & 0 deletions test/intervals.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@testset "Intervals" begin
@test Interval(C[4], D[4]) == Interval(1, Major)
@test Interval(E[4], C[4]) == Interval(2, Major)
@test Interval(B[4], C[4]) == Interval(6, Major)

@test Interval(B[4], C[5]) == Interval(1, Minor)

@test Interval(B[4], B[4]) == Interval(0, Perfect)
@test Interval(B[4], B[5]) == Interval(7, Perfect)

end

@testset "Adding intervals" begin
@test C + Interval(1, Major) == D
@test C + Interval(2, Major) == E
@test C + Interval(6, Major) == B

@test C[4] + Interval(1, Major) == D[4]
@test B[4] + Interval(1, Major) == C♯[5]
end
9 changes: 9 additions & 0 deletions test/notes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MusicTheory.NoteNames

@testset "Notes" begin
note = C[4]

@test PitchClass(note) == C
@test accidental(note) ==
@test octave(note) == 4
end
8 changes: 8 additions & 0 deletions test/scales.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@testset "Scales" begin

scale = Scale(C[4], major_scale)

scale_tones = Base.Iterators.take(scale, 8) |> collect
@test scale_tones == Pitch[C[4], D[4], E[4], F[4], G[4], A[4], B[4], C[5]]

end

0 comments on commit b9fece7

Please sign in to comment.