Skip to content

Feature/mutable structs #12

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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: 1 addition & 1 deletion src/annotated_image.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
abstract type AbstractAnnotatedImage end

struct AnnotatedImage <: AbstractAnnotatedImage
mutable struct AnnotatedImage <: AbstractAnnotatedImage
annotations::Vector{AbstractImageAnnotation}
image_file_path::Union{String, Nothing}
image_height::Union{Int, Nothing}
Expand Down
2 changes: 1 addition & 1 deletion src/bounding_box_annotation.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct BoundingBoxAnnotation{L, T} <: AbstractObjectAnnotation{L, T}
mutable struct BoundingBoxAnnotation{L, T} <: AbstractObjectAnnotation{L, T}
rect::Rect2{T}
annotation::ImageAnnotation{L}
end
Expand Down
2 changes: 1 addition & 1 deletion src/label.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
abstract type AbstractLabel end

struct Label{T} <: AbstractLabel
mutable struct Label{T} <: AbstractLabel
value::T
attributes::Dict{String, Any}
end
Expand Down
12 changes: 12 additions & 0 deletions test/annotated_image_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ using Test
@test length(get_annotations(annotated_image)) == 2
end

@testset "Mutability" begin
annotated_image = AnnotatedImage()
annotated_image.annotations = [ImageAnnotation(1)]
annotated_image.image_file_path = "path/to/image"
annotated_image.image_height = 3
annotated_image.image_width = 4
@test annotated_image.annotations == [ImageAnnotation(1)]
@test annotated_image.image_file_path == "path/to/image"
@test annotated_image.image_height == 3
@test annotated_image.image_width == 4
end

@testset "Equality" begin
@test AnnotatedImage() == AnnotatedImage()
@test AnnotatedImage([ImageAnnotation(1)]) == AnnotatedImage([ImageAnnotation(1)])
Expand Down
8 changes: 8 additions & 0 deletions test/bounding_box_annotation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ using Test
end
end

@testset "Mutability" begin
annotation = BoundingBoxAnnotation(Point2(1.0, 2.0), 3.0, 4.0, "car")
annotation.rect = Rect2(Point2(2.0, 3.0), 4.0, 5.0)
annotation.annotation = ImageAnnotation("person")
@test annotation.rect == Rect2(Point2(2.0, 3.0), 4.0, 5.0)
@test annotation.annotation == ImageAnnotation("person")
end

@testset "Equality" begin
@test BoundingBoxAnnotation(Point2(1.0, 2.0), 3.0, 4.0, "car") == BoundingBoxAnnotation(Point2(1.0, 2.0), 3.0, 4.0, "car")
@test BoundingBoxAnnotation(Point2(1.0, 2.0), 3.0, 4.0, "car") != BoundingBoxAnnotation(Point2(1.0, 2.0), 3.0, 4.0, "person")
Expand Down
12 changes: 12 additions & 0 deletions test/label_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using ImageAnnotations
using Test

@testset "Label" begin
@testset "Mutability" begin
label = Label("person")
label.value = "car"
label.attributes = Dict("colour" => "red")
@test label.value == "car"
@test label.attributes == Dict("colour" => "red")
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using Test
include("oriented_bounding_box_annotation_tests.jl")
include("polygon_annotation_tests.jl")
include("iou_tests.jl")
include("label_tests.jl")
include("annotated_image_tests.jl")
include("data_set_tests.jl")
end