Skip to content

Commit

Permalink
Implement Base.empty! and Base.isempty (#158)
Browse files Browse the repository at this point in the history
* Implement Base.empty! and Base.isempty

* change log updated
  • Loading branch information
NeroBlackstone authored Jan 15, 2023
1 parent 4554c16 commit 74b4e78
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.jl.cov
*.jl.mem
Manifest.toml
.vscode
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
# v2.4.0
* Implement `Base.empty!(::Notes)` and `Base.isempty(::Notes)`.
# v2.3.0
* New functions `is_octave`.
* Implement `Base.keys(::Notes)` and `Base.eachindex(::Notes)`.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MIDI"
uuid = "f57c4921-e30c-5f49-b073-3f2f2ada663e"
repo = "https://github.com/JuliaMusic/MIDI.jl.git"
version = "2.3.0"
version = "2.4.0"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand Down
2 changes: 2 additions & 0 deletions src/note.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ Base.getindex(n::Notes, r) = Notes(n.notes[r], n.tpq)
Base.view(n::Notes, r) = view(n.notes, r)
Base.eachindex(n::Notes) = eachindex(n.notes)
Base.keys(n::Notes) = eachindex(n)
Base.empty!(n::Notes) = empty!(n.notes)
Base.isempty(n::Notes)::Bool = isempty(n.notes)

# Pushing
Base.push!(no::Notes{N}, n::N) where {N <: AbstractNote} = push!(no.notes, n)
Expand Down
8 changes: 8 additions & 0 deletions test/note.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@ end
@test notes[index_max].pitch == name_to_pitch("D5")
min_pitch, index_min = findmin(n -> n.pitch, notes)
@test notes[index_min].pitch == name_to_pitch("C4")
end

@testset "check empty" begin
n1 = Note(name_to_pitch("C4"),0)
notes = Notes([n1])
@test !isempty(notes)
empty!(notes)
@test isempty(notes)
end

0 comments on commit 74b4e78

Please sign in to comment.