Skip to content
Closed
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
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ BaseInterfaces = "0b829d9d-522b-4e79-acc1-14feb8e2795d"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
GraphsInterfaceChecker = "3bef136c-15ff-4091-acbb-1a4aafe67608"
IGraphs = "647e90d3-2106-487c-adb4-c91fc07b96ea"
Interfaces = "85a1e053-f937-4924-92a5-1367d23b7b87"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
Expand Down
60 changes: 60 additions & 0 deletions test/interface.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# test_interface_igraphs_containers.jl
# Pattern inspired by NautyGraphs' interface test, adapted to test the
# IGraphs container interfaces using GraphsInterfaceChecker.
Comment on lines +1 to +3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid superfluous comments. LLMs in particular generate a lot of unhelpful and occasionally misleading comments. If the code is obvious, there should be no comments.


using Test
using GraphsInterfaceChecker # brings in interface definitions & helpers
using Interfaces
import BaseInterfaces # IterationInterface, ArrayInterface traits
using IGraphs

@testset "interface (IGraphs base containers)" begin
# === Vector-like interface checks (IGraphs.vtypes) ===
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests seem to already exist elsewhere in the code base. No need to repeat them. This seems to actually copy a lot of these existing tests.

for (VTs, ET, _) in IGraphs.vtypes
VT = eval(VTs)

# Provide example instances to the checker
v_samples = [VT(rand(ET, 10))]

# Declare conformance (mirrors NautyGraphs pattern)
@implements BaseInterfaces.IterationInterface VT v_samples
@implements BaseInterfaces.IterationInterface{(:indexing,)} VT v_samples
@implements BaseInterfaces.ArrayInterface VT v_samples
@implements BaseInterfaces.ArrayInterface{(:logical,:setindex!)} VT v_samples

# Run the interface tests
@test Interfaces.test(BaseInterfaces.IterationInterface, VT, v_samples)
@test Interfaces.test(BaseInterfaces.IterationInterface{(:indexing,)}, VT, v_samples)
@test Interfaces.test(BaseInterfaces.ArrayInterface, VT, v_samples)
@test Interfaces.test(BaseInterfaces.ArrayInterface{(:logical,:setindex!)}, VT, v_samples)

# Round-trip conversion checks (from IGraphs test_interfaces)
v = VT(rand(ET, 10))
@test Vector(VT(Vector(v))) == Vector(v)
@test VT(Vector(v)) == v
end

# === Matrix-like interface checks (IGraphs.mtypes) ===
for (MTs, ET, _) in IGraphs.mtypes
MT = eval(MTs)

m_samples = [MT(rand(ET, 10, 5))]

# Declare conformance
@implements BaseInterfaces.IterationInterface MT m_samples
@implements BaseInterfaces.IterationInterface{(:indexing,)} MT m_samples
@implements BaseInterfaces.ArrayInterface MT m_samples
@implements BaseInterfaces.ArrayInterface{(:logical,:setindex!)} MT m_samples

# Run the interface tests
@test Interfaces.test(BaseInterfaces.IterationInterface, MT, m_samples)
@test Interfaces.test(BaseInterfaces.IterationInterface{(:indexing,)}, MT, m_samples)
@test Interfaces.test(BaseInterfaces.ArrayInterface, MT, m_samples)
@test Interfaces.test(BaseInterfaces.ArrayInterface{(:logical,:setindex!)}, MT, m_samples)

# Round-trip conversion checks
m = MT(rand(ET, 10, 5))
@test Matrix(MT(Matrix(m))) == Matrix(m)
@test MT(Matrix(m)) == m
end
end
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using IGraphs
using TestItemRunner


include("interface.jl") # NEW
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not necessary, we are using TestItemRunner.jl which picks tests up automatically as long as they are marked appropriately. Check out its docs.


# filter for the test
testfilter = ti -> begin
exclude = Symbol[]
Expand All @@ -17,4 +20,4 @@ end

println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREADS = $(Sys.CPU_THREADS)`...")

@run_package_tests filter=testfilter
@run_package_tests filter=testfilter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your editor seems to have removed the ending newline in the file. Stack overflow has a good discussion about why ending newlines are important and why tools like github mark their omission with a warning sign. You can also set up your editor in a way that ensures that ending newlines are always present.

Loading