From 67c878730a288bba1713226bf12718c8df2ebfc3 Mon Sep 17 00:00:00 2001 From: yctai1994 Date: Sat, 13 Jan 2024 20:37:08 +0900 Subject: [PATCH] saddle-points: Type Specification Specify the input type to align the output type for easier unit testing. --- exercises/practice/saddle-points/runtests.jl | 36 ++++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/exercises/practice/saddle-points/runtests.jl b/exercises/practice/saddle-points/runtests.jl index 5a20d1a2..f10f88c4 100644 --- a/exercises/practice/saddle-points/runtests.jl +++ b/exercises/practice/saddle-points/runtests.jl @@ -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