From e08adf44c0e33a6181e8c45303a35cb242fcd79e Mon Sep 17 00:00:00 2001 From: yctai1994 Date: Sun, 14 Jan 2024 20:26:45 +0900 Subject: [PATCH] add: verbose testing - nucleotide-count - rotational-cipher - difference-of-squares - secret-handshake - darts --- exercises/practice/darts/runtests.jl | 79 ++++++++-------- .../difference-of-squares/runtests.jl | 38 ++++---- .../practice/nucleotide-count/runtests.jl | 30 +++--- .../practice/rotational-cipher/runtests.jl | 82 ++++++++-------- .../practice/secret-handshake/runtests.jl | 94 ++++++++++--------- 5 files changed, 166 insertions(+), 157 deletions(-) diff --git a/exercises/practice/darts/runtests.jl b/exercises/practice/darts/runtests.jl index 9035a6b7..d07f062d 100644 --- a/exercises/practice/darts/runtests.jl +++ b/exercises/practice/darts/runtests.jl @@ -2,55 +2,56 @@ using Test include("darts.jl") -@testset "Missed target" begin - @test score(-9, 9) == 0 -end +@testset verbose = true "Darts" begin + @testset "Missed target" begin + @test score(-9, 9) == 0 + end -@testset "On the outer circle" begin - @test score(0, 10) == 1 -end + @testset "On the outer circle" begin + @test score(0, 10) == 1 + end -@testset "On the middle circle" begin - @test score(-5, 0) == 5 -end + @testset "On the middle circle" begin + @test score(-5, 0) == 5 + end -@testset "On the inner circle" begin - @test score(0, -1) == 10 -end + @testset "On the inner circle" begin + @test score(0, -1) == 10 + end -@testset "Exactly on centre" begin - @test score(0, 0) == 10 -end + @testset "Exactly on centre" begin + @test score(0, 0) == 10 + end -@testset "Near the centre" begin - @test score(-0.1, -0.1) == 10 -end + @testset "Near the centre" begin + @test score(-0.1, -0.1) == 10 + end -@testset "Just within the inner circle" begin - @test score(0.7, 0.7) == 10 -end + @testset "Just within the inner circle" begin + @test score(0.7, 0.7) == 10 + end -@testset "Just outside the inner circle" begin - @test score(0.8, -0.8) == 5 -end + @testset "Just outside the inner circle" begin + @test score(0.8, -0.8) == 5 + end -@testset "Just within the middle circle" begin - @test score(-3.5, 3.5) == 5 -end + @testset "Just within the middle circle" begin + @test score(-3.5, 3.5) == 5 + end -@testset "Just outside the middle circle" begin - @test score(-3.6, -3.6) == 1 -end + @testset "Just outside the middle circle" begin + @test score(-3.6, -3.6) == 1 + end -@testset "Just within the outer circle" begin - @test score(-7.0, 7.0) == 1 -end + @testset "Just within the outer circle" begin + @test score(-7.0, 7.0) == 1 + end -@testset "Just outside the outer circle" begin - @test score(7.1, -7.1) == 0 -end + @testset "Just outside the outer circle" begin + @test score(7.1, -7.1) == 0 + end -@testset "Asymmetric position between the inner and middle circles" begin - @test score(0.5, -4) == 5 + @testset "Asymmetric position between the inner and middle circles" begin + @test score(0.5, -4) == 5 + end end - diff --git a/exercises/practice/difference-of-squares/runtests.jl b/exercises/practice/difference-of-squares/runtests.jl index 7f9327fc..45c3061d 100644 --- a/exercises/practice/difference-of-squares/runtests.jl +++ b/exercises/practice/difference-of-squares/runtests.jl @@ -2,24 +2,26 @@ using Test include("difference-of-squares.jl") -@testset "Square the sum of the numbers up to the given number" begin - @test square_of_sum(1)::Integer == 1 - @test square_of_sum(5)::Integer == 225 - @test square_of_sum(10)::Integer == 3025 - @test square_of_sum(100)::Integer == 25502500 -end +@testset verbose = true "Difference of Squares" begin + @testset "Square the sum of the numbers up to the given number" begin + @test square_of_sum(1)::Integer == 1 + @test square_of_sum(5)::Integer == 225 + @test square_of_sum(10)::Integer == 3025 + @test square_of_sum(100)::Integer == 25502500 + end -@testset "Sum the squares of the numbers up to the given number" begin - @test sum_of_squares(1)::Integer == 1 - @test sum_of_squares(5)::Integer == 55 - @test sum_of_squares(10)::Integer == 385 - @test sum_of_squares(100)::Integer == 338350 -end + @testset "Sum the squares of the numbers up to the given number" begin + @test sum_of_squares(1)::Integer == 1 + @test sum_of_squares(5)::Integer == 55 + @test sum_of_squares(10)::Integer == 385 + @test sum_of_squares(100)::Integer == 338350 + end -@testset "Subtract sum of squares from square of sums" begin - @test difference(0)::Integer == 0 - @test difference(1)::Integer == 0 - @test difference(5)::Integer == 170 - @test difference(10)::Integer == 2640 - @test difference(100)::Integer == 25164150 + @testset "Subtract sum of squares from square of sums" begin + @test difference(0)::Integer == 0 + @test difference(1)::Integer == 0 + @test difference(5)::Integer == 170 + @test difference(10)::Integer == 2640 + @test difference(100)::Integer == 25164150 + end end diff --git a/exercises/practice/nucleotide-count/runtests.jl b/exercises/practice/nucleotide-count/runtests.jl index ad22b400..168fe914 100644 --- a/exercises/practice/nucleotide-count/runtests.jl +++ b/exercises/practice/nucleotide-count/runtests.jl @@ -2,22 +2,24 @@ using Test include("nucleotide-count.jl") -@testset "empty strand" begin - @test count_nucleotides("") == Dict('A' => 0, 'C' => 0, 'G' => 0, 'T' => 0) -end +@testset verbose = true "Nucleotide Count" begin + @testset "empty strand" begin + @test count_nucleotides("") == Dict('A' => 0, 'C' => 0, 'G' => 0, 'T' => 0) + end -@testset "strand with one nucleotide in single-character input" begin - @test count_nucleotides("G") == Dict('A' => 0, 'C' => 0, 'G' => 1, 'T' => 0) -end + @testset "strand with one nucleotide in single-character input" begin + @test count_nucleotides("G") == Dict('A' => 0, 'C' => 0, 'G' => 1, 'T' => 0) + end -@testset "strand with repeated nucleotide" begin - @test count_nucleotides("GGGGGGG") == Dict('A' => 0, 'C' => 0, 'G' => 7, 'T' => 0) -end + @testset "strand with repeated nucleotide" begin + @test count_nucleotides("GGGGGGG") == Dict('A' => 0, 'C' => 0, 'G' => 7, 'T' => 0) + end -@testset "strand with multiple nucleotides" begin - @test count_nucleotides("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC") == Dict('A' => 20, 'C' => 12, 'G' => 17, 'T' => 21) -end + @testset "strand with multiple nucleotides" begin + @test count_nucleotides("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC") == Dict('A' => 20, 'C' => 12, 'G' => 17, 'T' => 21) + end -@testset "strand with invalid nucleotides" begin - @test_throws DomainError count_nucleotides("AGXXACT") + @testset "strand with invalid nucleotides" begin + @test_throws DomainError count_nucleotides("AGXXACT") + end end diff --git a/exercises/practice/rotational-cipher/runtests.jl b/exercises/practice/rotational-cipher/runtests.jl index 4d33478c..8e4850ba 100644 --- a/exercises/practice/rotational-cipher/runtests.jl +++ b/exercises/practice/rotational-cipher/runtests.jl @@ -2,53 +2,55 @@ using Test include("rotational-cipher.jl") -@testset "rotate function" begin - @testset "rotate by n" begin - @testset "no wrap" begin - @test rotate(1, "a") == "b" - @test rotate(1, 'a') == 'b' - @test rotate(13, "m") == "z" - @test rotate(13, 'm') == 'z' +@testset verbose = true "Rotational Cipher" begin + @testset "rotate function" begin + @testset "rotate by n" begin + @testset "no wrap" begin + @test rotate(1, "a") == "b" + @test rotate(1, 'a') == 'b' + @test rotate(13, "m") == "z" + @test rotate(13, 'm') == 'z' + end + @testset "wrap around" begin + @test rotate(13, "n") == "a" + @test rotate(13, 'n') == 'a' + end end - @testset "wrap around" begin - @test rotate(13, "n") == "a" - @test rotate(13, 'n') == 'a' + + @testset "full rotation" begin + @test rotate(26, "a") == "a" + @test rotate(26, 'a') == 'a' + @test rotate(0, "a") == "a" + @test rotate(0, 'a') == 'a' end - end - @testset "full rotation" begin - @test rotate(26, "a") == "a" - @test rotate(26, 'a') == 'a' - @test rotate(0, "a") == "a" - @test rotate(0, 'a') == 'a' + @testset "full strings" begin + @test rotate(5, "OMG") == "TRL" + @test rotate(5, "O M G") == "T R L" + @test rotate(4, "Testing 1 2 3 testing") == "Xiwxmrk 1 2 3 xiwxmrk" + @test rotate(21, "Let's eat, Grandma!") == "Gzo'n zvo, Bmviyhv!" + @test rotate(13, "The quick brown fox jumps over the lazy dog.") == "Gur dhvpx oebja sbk whzcf bire gur ynml qbt." + end end - @testset "full strings" begin - @test rotate(5, "OMG") == "TRL" - @test rotate(5, "O M G") == "T R L" - @test rotate(4, "Testing 1 2 3 testing") == "Xiwxmrk 1 2 3 xiwxmrk" - @test rotate(21, "Let's eat, Grandma!") == "Gzo'n zvo, Bmviyhv!" - @test rotate(13, "The quick brown fox jumps over the lazy dog.") == "Gur dhvpx oebja sbk whzcf bire gur ynml qbt." - end -end + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # + # Additional exercises # + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# Additional exercises # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # - -# Bonus A -if isdefined(@__MODULE__, Symbol("@R13_str")) - @eval @testset "Bonus A: string literal R13" begin - @test R13"The quick brown fox jumps over the lazy dog." == "Gur dhvpx oebja sbk whzcf bire gur ynml qbt." + # Bonus A + if isdefined(@__MODULE__, Symbol("@R13_str")) + @eval @testset "Bonus A: string literal R13" begin + @test R13"The quick brown fox jumps over the lazy dog." == "Gur dhvpx oebja sbk whzcf bire gur ynml qbt." + end end -end -# Bonus B -if isdefined(@__MODULE__, Symbol("@R1_str")) - @eval @testset "Bonus B: string literals" begin - @test R5"OMG" == "TRL" - @test R4"Testing 1 2 3 testing" == "Xiwxmrk 1 2 3 xiwxmrk" - @test R21"Let's eat, Grandma!" == "Gzo'n zvo, Bmviyhv!" - @test R13"The quick brown fox jumps over the lazy dog." == "Gur dhvpx oebja sbk whzcf bire gur ynml qbt." + # Bonus B + if isdefined(@__MODULE__, Symbol("@R1_str")) + @eval @testset "Bonus B: string literals" begin + @test R5"OMG" == "TRL" + @test R4"Testing 1 2 3 testing" == "Xiwxmrk 1 2 3 xiwxmrk" + @test R21"Let's eat, Grandma!" == "Gzo'n zvo, Bmviyhv!" + @test R13"The quick brown fox jumps over the lazy dog." == "Gur dhvpx oebja sbk whzcf bire gur ynml qbt." + end end end diff --git a/exercises/practice/secret-handshake/runtests.jl b/exercises/practice/secret-handshake/runtests.jl index 5c34b127..5c64d967 100644 --- a/exercises/practice/secret-handshake/runtests.jl +++ b/exercises/practice/secret-handshake/runtests.jl @@ -2,50 +2,52 @@ using Test include("secret-handshake.jl") -@testset "wink for 1" begin - @test secret_handshake(1) == ["wink"] -end - -@testset "double blink for 10" begin - @test secret_handshake(2) == ["double blink"] -end - -@testset "close your eyes for 100" begin - @test secret_handshake(4) == ["close your eyes"] -end - -@testset "jump for 1000" begin - @test secret_handshake(8) == ["jump"] -end - -@testset "combine two actions" begin - @test secret_handshake(3) == ["wink", "double blink"] -end - -@testset "reverse two actions" begin - @test secret_handshake(19) == ["double blink", "wink"] -end - -@testset "reversing one action gives the same action" begin - @test secret_handshake(24) == ["jump"] -end - -@testset "reversing no actions still gives no actions" begin - @test secret_handshake(16) == [] -end - -@testset "all possible actions" begin - @test secret_handshake(15) == ["wink", "double blink", "close your eyes", "jump"] -end - -@testset "reverse all possible actions" begin - @test secret_handshake(31) == ["jump", "close your eyes", "double blink", "wink"] -end - -@testset "do nothing for zero" begin - @test secret_handshake(0) == [] -end - -@testset "do nothing if lower 5 bits not set" begin - @test secret_handshake(32) == [] +@testset verbose = true "Secret Handshake" begin + @testset "wink for 1" begin + @test secret_handshake(1) == ["wink"] + end + + @testset "double blink for 10" begin + @test secret_handshake(2) == ["double blink"] + end + + @testset "close your eyes for 100" begin + @test secret_handshake(4) == ["close your eyes"] + end + + @testset "jump for 1000" begin + @test secret_handshake(8) == ["jump"] + end + + @testset "combine two actions" begin + @test secret_handshake(3) == ["wink", "double blink"] + end + + @testset "reverse two actions" begin + @test secret_handshake(19) == ["double blink", "wink"] + end + + @testset "reversing one action gives the same action" begin + @test secret_handshake(24) == ["jump"] + end + + @testset "reversing no actions still gives no actions" begin + @test secret_handshake(16) == [] + end + + @testset "all possible actions" begin + @test secret_handshake(15) == ["wink", "double blink", "close your eyes", "jump"] + end + + @testset "reverse all possible actions" begin + @test secret_handshake(31) == ["jump", "close your eyes", "double blink", "wink"] + end + + @testset "do nothing for zero" begin + @test secret_handshake(0) == [] + end + + @testset "do nothing if lower 5 bits not set" begin + @test secret_handshake(32) == [] + end end