From 74b4e78ebc2a01f4d502a2e88184bc96b6847f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nero=20Blackstone=E2=80=8B?= Date: Sun, 15 Jan 2023 16:33:18 +0800 Subject: [PATCH] Implement `Base.empty!` and `Base.isempty` (#158) * Implement Base.empty! and Base.isempty * change log updated --- .gitignore | 1 + CHANGELOG.md | 2 ++ Project.toml | 2 +- src/note.jl | 2 ++ test/note.jl | 8 ++++++++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b6f8b8d..151bf6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.jl.cov *.jl.mem Manifest.toml +.vscode diff --git a/CHANGELOG.md b/CHANGELOG.md index c60e98f..fb08e95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)`. diff --git a/Project.toml b/Project.toml index 02dc1bf..06726a9 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/note.jl b/src/note.jl index 8a7290c..55feffd 100644 --- a/src/note.jl +++ b/src/note.jl @@ -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) diff --git a/test/note.jl b/test/note.jl index cb99bb1..f5eb9cb 100644 --- a/test/note.jl +++ b/test/note.jl @@ -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 \ No newline at end of file