From a7b8bc8fe36ff7fa9e76f5c6045dec4a8f1c4ce0 Mon Sep 17 00:00:00 2001 From: yctai1994 Date: Sat, 13 Jan 2024 14:23:49 +0900 Subject: [PATCH] add: verbose testing - pythagorean-triplet - collatz-conjecture - hello-world - complex-numbers - raindrops --- .../practice/collatz-conjecture/runtests.jl | 18 +-- .../practice/complex-numbers/runtests.jl | 118 +++++++++--------- exercises/practice/hello-world/runtests.jl | 6 +- .../practice/pythagorean-triplet/runtests.jl | 72 +++++------ exercises/practice/raindrops/runtests.jl | 118 +++++++++--------- 5 files changed, 171 insertions(+), 161 deletions(-) diff --git a/exercises/practice/collatz-conjecture/runtests.jl b/exercises/practice/collatz-conjecture/runtests.jl index 5d0a1c26..90bd274d 100644 --- a/exercises/practice/collatz-conjecture/runtests.jl +++ b/exercises/practice/collatz-conjecture/runtests.jl @@ -2,12 +2,14 @@ using Test include("collatz-conjecture.jl") -# canonical data -@testset "Canonical data" begin - @test collatz_steps(1) == 0 - @test collatz_steps(16) == 4 - @test collatz_steps(12) == 9 - @test collatz_steps(1000000) == 152 - @test_throws DomainError collatz_steps(0) - @test_throws DomainError collatz_steps(-15) +@testset verbose = true "Collatz Conjecture" begin + # canonical data + @testset "Canonical data" begin + @test collatz_steps(1) == 0 + @test collatz_steps(16) == 4 + @test collatz_steps(12) == 9 + @test collatz_steps(1000000) == 152 + @test_throws DomainError collatz_steps(0) + @test_throws DomainError collatz_steps(-15) + end end diff --git a/exercises/practice/complex-numbers/runtests.jl b/exercises/practice/complex-numbers/runtests.jl index 6560f2f1..1179bbc8 100644 --- a/exercises/practice/complex-numbers/runtests.jl +++ b/exercises/practice/complex-numbers/runtests.jl @@ -2,74 +2,76 @@ using Test include("complex-numbers.jl") -@test ComplexNumber <: Number +@testset verbose = true "Complex Numbers" begin + @test ComplexNumber <: Number -@test ComplexNumber(0, 1)^2 == ComplexNumber(-1, 0) + @test ComplexNumber(0, 1)^2 == ComplexNumber(-1, 0) -@testset "Arithmetic" begin - @testset "Addition" begin - @test ComplexNumber(1, 0) + ComplexNumber(2, 0) == ComplexNumber(3, 0) - @test ComplexNumber(0, 1) + ComplexNumber(0, 2) == ComplexNumber(0, 3) - @test ComplexNumber(1, 2) + ComplexNumber(3, 4) == ComplexNumber(4, 6) - end + @testset "Arithmetic" begin + @testset "Addition" begin + @test ComplexNumber(1, 0) + ComplexNumber(2, 0) == ComplexNumber(3, 0) + @test ComplexNumber(0, 1) + ComplexNumber(0, 2) == ComplexNumber(0, 3) + @test ComplexNumber(1, 2) + ComplexNumber(3, 4) == ComplexNumber(4, 6) + end - @testset "Subtraction" begin - @test ComplexNumber(1, 0) - ComplexNumber(2, 0) == ComplexNumber(-1, 0) - @test ComplexNumber(0, 1) - ComplexNumber(0, 2) == ComplexNumber(0, -1) - @test ComplexNumber(1, 2) - ComplexNumber(3, 4) == ComplexNumber(-2, -2) - end + @testset "Subtraction" begin + @test ComplexNumber(1, 0) - ComplexNumber(2, 0) == ComplexNumber(-1, 0) + @test ComplexNumber(0, 1) - ComplexNumber(0, 2) == ComplexNumber(0, -1) + @test ComplexNumber(1, 2) - ComplexNumber(3, 4) == ComplexNumber(-2, -2) + end - @testset "Multiplication" begin - @test ComplexNumber(1, 0) * ComplexNumber(2, 0) == ComplexNumber(2, 0) - @test ComplexNumber(0, 1) * ComplexNumber(0, 2) == ComplexNumber(-2, 0) - @test ComplexNumber(1, 2) * ComplexNumber(3, 4) == ComplexNumber(-5, 10) - end + @testset "Multiplication" begin + @test ComplexNumber(1, 0) * ComplexNumber(2, 0) == ComplexNumber(2, 0) + @test ComplexNumber(0, 1) * ComplexNumber(0, 2) == ComplexNumber(-2, 0) + @test ComplexNumber(1, 2) * ComplexNumber(3, 4) == ComplexNumber(-5, 10) + end - @testset "Division" begin - @test ComplexNumber(1, 0) / ComplexNumber(2, 0) == ComplexNumber(0.5, 0) - @test ComplexNumber(0, 1) / ComplexNumber(0, 2) == ComplexNumber(0.5, 0) - @test ComplexNumber(1, 2) / ComplexNumber(3, 4) ≈ ComplexNumber(0.44, 0.08) + @testset "Division" begin + @test ComplexNumber(1, 0) / ComplexNumber(2, 0) == ComplexNumber(0.5, 0) + @test ComplexNumber(0, 1) / ComplexNumber(0, 2) == ComplexNumber(0.5, 0) + @test ComplexNumber(1, 2) / ComplexNumber(3, 4) ≈ ComplexNumber(0.44, 0.08) + end end -end -@testset "Absolute value" begin - @test abs(ComplexNumber(5, 0)) == 5 - @test abs(ComplexNumber(-5, 0)) == 5 - @test abs(ComplexNumber(0, 5)) == 5 - @test abs(ComplexNumber(0, -5)) == 5 - @test abs(ComplexNumber(3, 4)) == 5 -end + @testset "Absolute value" begin + @test abs(ComplexNumber(5, 0)) == 5 + @test abs(ComplexNumber(-5, 0)) == 5 + @test abs(ComplexNumber(0, 5)) == 5 + @test abs(ComplexNumber(0, -5)) == 5 + @test abs(ComplexNumber(3, 4)) == 5 + end -@testset "Complex conjugate" begin - @test conj(ComplexNumber(5, 0)) == ComplexNumber(5, 0) - @test conj(ComplexNumber(0, 5)) == ComplexNumber(0, -5) - @test conj(ComplexNumber(1, 1)) == ComplexNumber(1, -1) -end + @testset "Complex conjugate" begin + @test conj(ComplexNumber(5, 0)) == ComplexNumber(5, 0) + @test conj(ComplexNumber(0, 5)) == ComplexNumber(0, -5) + @test conj(ComplexNumber(1, 1)) == ComplexNumber(1, -1) + end -@testset "Real part" begin - @test real(ComplexNumber(1, 0)) == 1 - @test real(ComplexNumber(0, 1)) == 0 - @test real(ComplexNumber(1, 2)) == 1 -end + @testset "Real part" begin + @test real(ComplexNumber(1, 0)) == 1 + @test real(ComplexNumber(0, 1)) == 0 + @test real(ComplexNumber(1, 2)) == 1 + end -@testset "Imaginary part" begin - @test imag(ComplexNumber(1, 0)) == 0 - @test imag(ComplexNumber(0, 1)) == 1 - @test imag(ComplexNumber(1, 2)) == 2 -end + @testset "Imaginary part" begin + @test imag(ComplexNumber(1, 0)) == 0 + @test imag(ComplexNumber(0, 1)) == 1 + @test imag(ComplexNumber(1, 2)) == 2 + end -# Bonus A -@testset "Complex exponential" begin - @test_skip exp(ComplexNumber(0, π)) ≈ ComplexNumber(-1, 0) - @test_skip exp(ComplexNumber(0, 0)) == ComplexNumber(1, 0) - @test_skip exp(ComplexNumber(1, 0)) ≈ ComplexNumber(ℯ, 0) - @test_skip exp(ComplexNumber(log(2), π)) ≈ ComplexNumber(-2, 0) -end + # Bonus A + @testset "Complex exponential" begin + @test_skip exp(ComplexNumber(0, π)) ≈ ComplexNumber(-1.0, 0.0) atol = 1e-15 + @test_skip exp(ComplexNumber(0, 0)) == ComplexNumber(1.0, 0.0) + @test_skip exp(ComplexNumber(1, 0)) ≈ ComplexNumber(ℯ, 0.0) atol = 1e-15 + @test_skip exp(ComplexNumber(log(2), π)) ≈ ComplexNumber(-2.0, 0.0) atol = 1e-15 + end -# Bonus B -@testset "Syntax sugar jm" begin - @test_skip ComplexNumber(0, 1) == jm - @test_skip ComplexNumber(1, 0) == 1 + 0jm - @test_skip ComplexNumber(1, 1) == 1 + 1jm - @test_skip ComplexNumber(-1, 0) == jm^2 + # Bonus B + @testset "Syntax sugar jm" begin + @test_skip ComplexNumber(0, 1) == jm + @test_skip ComplexNumber(1, 0) == 1 + 0jm + @test_skip ComplexNumber(1, 1) == 1 + 1jm + @test_skip ComplexNumber(-1, 0) == jm^2 + end end diff --git a/exercises/practice/hello-world/runtests.jl b/exercises/practice/hello-world/runtests.jl index e6e1f16b..6abdee84 100644 --- a/exercises/practice/hello-world/runtests.jl +++ b/exercises/practice/hello-world/runtests.jl @@ -2,6 +2,8 @@ using Test include("hello-world.jl") -@testset "Say Hi!" begin - @test hello() == "Hello, World!" +@testset verbose = true "Hello World" begin + @testset "Say Hi!" begin + @test hello() == "Hello, World!" + end end diff --git a/exercises/practice/pythagorean-triplet/runtests.jl b/exercises/practice/pythagorean-triplet/runtests.jl index d4c3ffcd..e747147c 100644 --- a/exercises/practice/pythagorean-triplet/runtests.jl +++ b/exercises/practice/pythagorean-triplet/runtests.jl @@ -1,45 +1,47 @@ using Test include("pythagorean-triplet.jl") -@testset "triplets whose sum is 12" begin - @test pythagorean_triplets(12) == [(3, 4, 5)] -end +@testset verbose = true "Pythagorean Triplet" begin + @testset "triplets whose sum is 12" begin + @test pythagorean_triplets(12) == [(3, 4, 5)] + end -@testset "triplets whose sum is 108" begin - @test pythagorean_triplets(108) == [(27, 36, 45)] -end + @testset "triplets whose sum is 108" begin + @test pythagorean_triplets(108) == [(27, 36, 45)] + end -@testset "triplets whose sum is 1000" begin - @test pythagorean_triplets(1000) == [(200, 375, 425)] -end + @testset "triplets whose sum is 1000" begin + @test pythagorean_triplets(1000) == [(200, 375, 425)] + end -@testset "triplets whose sum is 1001" begin - @test pythagorean_triplets(1001) == [] -end + @testset "triplets whose sum is 1001" begin + @test pythagorean_triplets(1001) == [] + end -@testset "returns all matching triplets" begin - @test pythagorean_triplets(90) == [(9, 40, 41), (15, 36, 39)] -end + @testset "returns all matching triplets" begin + @test pythagorean_triplets(90) == [(9, 40, 41), (15, 36, 39)] + end -@testset "several matching triplets" begin - @test pythagorean_triplets(840) == [ - (40, 399, 401), - (56, 390, 394), - (105, 360, 375), - (120, 350, 370), - (140, 336, 364), - (168, 315, 357), - (210, 280, 350), - (240, 252, 348), - ] -end + @testset "several matching triplets" begin + @test pythagorean_triplets(840) == [ + (40, 399, 401), + (56, 390, 394), + (105, 360, 375), + (120, 350, 370), + (140, 336, 364), + (168, 315, 357), + (210, 280, 350), + (240, 252, 348), + ] + end -@testset "triplets for large number" begin - @test pythagorean_triplets(30000) == [ - (1200, 14375, 14425), - (1875, 14000, 14125), - (5000, 12000, 13000), - (6000, 11250, 12750), - (7500, 10000, 12500), - ] + @testset "triplets for large number" begin + @test pythagorean_triplets(30000) == [ + (1200, 14375, 14425), + (1875, 14000, 14125), + (5000, 12000, 13000), + (6000, 11250, 12750), + (7500, 10000, 12500), + ] + end end diff --git a/exercises/practice/raindrops/runtests.jl b/exercises/practice/raindrops/runtests.jl index c06a6180..2292e2a2 100644 --- a/exercises/practice/raindrops/runtests.jl +++ b/exercises/practice/raindrops/runtests.jl @@ -2,71 +2,73 @@ using Test include("raindrops.jl") -@testset "detect numbers" begin - @testset "the sound for 1 is 1" begin - @test raindrops(1) == "1" +@testset verbose = true "Raindrops" begin + @testset "detect numbers" begin + @testset "the sound for 1 is 1" begin + @test raindrops(1) == "1" + end + @testset "2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base" begin + @test raindrops(8) == "8" + end + @testset "the sound for 52 is 52" begin + @test raindrops(52) == "52" + end end - @testset "2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base" begin - @test raindrops(8) == "8" - end - @testset "the sound for 52 is 52" begin - @test raindrops(52) == "52" - end -end -@testset "detect pling" begin - @testset "the sound for 3 is Pling" begin - @test raindrops(3) == "Pling" - end - @testset "the sound for 6 is Pling as it has a factor 3" begin - @test raindrops(6) == "Pling" - end - @testset "the sound for 9 is Pling as it has a factor 3" begin - @test raindrops(9) == "Pling" + @testset "detect pling" begin + @testset "the sound for 3 is Pling" begin + @test raindrops(3) == "Pling" + end + @testset "the sound for 6 is Pling as it has a factor 3" begin + @test raindrops(6) == "Pling" + end + @testset "the sound for 9 is Pling as it has a factor 3" begin + @test raindrops(9) == "Pling" + end + @testset "the sound for 27 is Pling as it has a factor 3" begin + @test raindrops(27) == "Pling" + end end - @testset "the sound for 27 is Pling as it has a factor 3" begin - @test raindrops(27) == "Pling" - end -end -@testset "detect plang" begin - @testset "the sound for 5 is Plang" begin - @test raindrops(5) == "Plang" - end - @testset "the sound for 10 is Plang as it has a factor 5" begin - @test raindrops(10) == "Plang" - end - @testset "the sound for 25 is Plang as it has a factor 5" begin - @test raindrops(25) == "Plang" + @testset "detect plang" begin + @testset "the sound for 5 is Plang" begin + @test raindrops(5) == "Plang" + end + @testset "the sound for 10 is Plang as it has a factor 5" begin + @test raindrops(10) == "Plang" + end + @testset "the sound for 25 is Plang as it has a factor 5" begin + @test raindrops(25) == "Plang" + end + @testset "the sound for 3125 is Plang as it has a factor 5" begin + @test raindrops(3125) == "Plang" + end end - @testset "the sound for 3125 is Plang as it has a factor 5" begin - @test raindrops(3125) == "Plang" - end -end -@testset "detect plong" begin - @testset "the sound for 7 is Plong" begin - @test raindrops(7) == "Plong" - end - @testset "the sound for 14 is Plong as it has a factor of 7" begin - @test raindrops(14) == "Plong" - end - @testset "the sound for 49 is Plong as it has a factor 7" begin - @test raindrops(49) == "Plong" + @testset "detect plong" begin + @testset "the sound for 7 is Plong" begin + @test raindrops(7) == "Plong" + end + @testset "the sound for 14 is Plong as it has a factor of 7" begin + @test raindrops(14) == "Plong" + end + @testset "the sound for 49 is Plong as it has a factor 7" begin + @test raindrops(49) == "Plong" + end end -end -@testset "detect multiple sounds" begin - @testset "the sound for 15 is PlingPlang as it has factors 3 and 5" begin - @test raindrops(15) == "PlingPlang" - end - @testset "the sound for 21 is PlingPlong as it has factors 3 and 7" begin - @test raindrops(21) == "PlingPlong" - end - @testset "the sound for 35 is PlangPlong as it has factors 5 and 7" begin - @test raindrops(35) == "PlangPlong" - end - @testset "the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7" begin - @test raindrops(105) == "PlingPlangPlong" + @testset "detect multiple sounds" begin + @testset "the sound for 15 is PlingPlang as it has factors 3 and 5" begin + @test raindrops(15) == "PlingPlang" + end + @testset "the sound for 21 is PlingPlong as it has factors 3 and 7" begin + @test raindrops(21) == "PlingPlong" + end + @testset "the sound for 35 is PlangPlong as it has factors 5 and 7" begin + @test raindrops(35) == "PlangPlong" + end + @testset "the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7" begin + @test raindrops(105) == "PlingPlangPlong" + end end end