Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests and chords #3

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading