Skip to content

Commit

Permalink
add: verbose testing
Browse files Browse the repository at this point in the history
- nucleotide-count
- rotational-cipher
- difference-of-squares
- secret-handshake
- darts
  • Loading branch information
yctai1994 committed Jan 14, 2024
1 parent 67c8787 commit e08adf4
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 157 deletions.
79 changes: 40 additions & 39 deletions exercises/practice/darts/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

38 changes: 20 additions & 18 deletions exercises/practice/difference-of-squares/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 16 additions & 14 deletions exercises/practice/nucleotide-count/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
82 changes: 42 additions & 40 deletions exercises/practice/rotational-cipher/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
94 changes: 48 additions & 46 deletions exercises/practice/secret-handshake/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e08adf4

Please sign in to comment.