Skip to content

Commit

Permalink
saddle-points: Type Specification
Browse files Browse the repository at this point in the history
Specify the input type to align the output type for easier unit testing.
  • Loading branch information
yctai1994 committed Jan 13, 2024
1 parent a7b8bc8 commit 67c8787
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions exercises/practice/saddle-points/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ include("saddle-points.jl")

@testset verbose = true "Saddle Points" begin
@testset "Can identify single saddle point" begin
M = [9 8 7; 5 3 2; 6 6 7]
@test saddlepoints(M) == [(2, 1)]
M = Int[9 8 7; 5 3 2; 6 6 7]
@test saddlepoints(M) == NTuple{2,Int}[(2, 1)]
end

@testset "Can identify that empty matrix has no saddle points" begin
M = []
@test saddlepoints(M) == []
M = Int[]
@test saddlepoints(M) == NTuple{2,Int}[]
end

@testset "Can identify lack of saddle points when there are none" begin
M = [1 2 3; 3 1 2; 2 3 1]
@test saddlepoints(M) == []
M = Int[1 2 3; 3 1 2; 2 3 1]
@test saddlepoints(M) == NTuple{2,Int}[]
end

@testset "Can identify multiple saddle points in a column" begin
M = [4 5 4; 3 5 5; 1 5 4]
@test saddlepoints(M) == [(1, 2), (2, 2), (3, 2)]
M = Int[4 5 4; 3 5 5; 1 5 4]
@test saddlepoints(M) == NTuple{2,Int}[(1, 2), (2, 2), (3, 2)]
end

@testset "Can identify multiple saddle points in a row" begin
M = [6 7 8; 5 5 5; 7 5 6]
@test saddlepoints(M) == [(2, 1), (2, 2), (2, 3)]
M = Int[6 7 8; 5 5 5; 7 5 6]
@test saddlepoints(M) == NTuple{2,Int}[(2, 1), (2, 2), (2, 3)]
end

@testset "Can identify saddle point in bottom right corner" begin
M = [8 7 9; 6 7 6; 3 2 5]
@test saddlepoints(M) == [(3, 3)]
M = Int[8 7 9; 6 7 6; 3 2 5]
@test saddlepoints(M) == NTuple{2,Int}[(3, 3)]
end

@testset "Can identify saddle points in a non square matrix" begin
M = [3 1 3; 3 2 4]
@test saddlepoints(M) == [(1, 1), (1, 3)]
M = Int[3 1 3; 3 2 4]
@test saddlepoints(M) == NTuple{2,Int}[(1, 1), (1, 3)]
end

@testset "Can identify that saddle points in a single column matrix are those with the minimum value" begin
M = reshape([2, 1, 4, 1], :, 1)
@test saddlepoints(M) == [(2, 1), (4, 1)]
M = reshape(Int[2, 1, 4, 1], :, 1)
@test saddlepoints(M) == NTuple{2,Int}[(2, 1), (4, 1)]
end

@testset "Can identify that saddle points in a single row matrix are those with the maximum value" begin
M = [2 5 3 5]
@test saddlepoints(M) == [(1, 2), (1, 4)]
M = Int[2 5 3 5]
@test saddlepoints(M) == NTuple{2,Int}[(1, 2), (1, 4)]
end
end

0 comments on commit 67c8787

Please sign in to comment.