Skip to content

Commit

Permalink
Verbose Unit Testing Update (#723)
Browse files Browse the repository at this point in the history
* update to verbose unit testing

* updating top level  test description

* updating concept.wip/encounters/runtests.jl to move struct to global scope

[no important files changed]
  • Loading branch information
depial authored Apr 30, 2024
1 parent c0d3891 commit a9e391b
Show file tree
Hide file tree
Showing 79 changed files with 3,182 additions and 3,074 deletions.
98 changes: 50 additions & 48 deletions exercises/concept.wip/annalyns-infiltration/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,63 @@ if VERSION < v"1.1"
@eval eachrow(A) = (view(A, i, :) for i in axes(A, 1))
end

@testset "fast attack" begin
@test !can_do_fast_attack(true)
@test can_do_fast_attack(false)
end
@testset verbose = true "tests" begin
@testset "fast attack" begin
@test !can_do_fast_attack(true)
@test can_do_fast_attack(false)
end

@testset "spying" begin
character_state_combinations = Bool[
0 0 0 0;
0 0 1 1;
0 1 0 1;
0 1 1 1;
1 0 0 1;
1 0 1 1;
1 1 1 1;
]
@testset "spying" begin
character_state_combinations = Bool[
0 0 0 0;
0 0 1 1;
0 1 0 1;
0 1 1 1;
1 0 0 1;
1 0 1 1;
1 1 1 1;
]

for state in eachrow(character_state_combinations)
@test can_spy(state[1:3]...) == state[4]
for state in eachrow(character_state_combinations)
@test can_spy(state[1:3]...) == state[4]
end
end
end

@testset "signaling prisoner" begin
character_state_combinations = Bool[
0 0 0;
0 1 1;
1 0 0;
1 1 0;
]
@testset "signaling prisoner" begin
character_state_combinations = Bool[
0 0 0;
0 1 1;
1 0 0;
1 1 0;
]

for state in eachrow(character_state_combinations)
@test can_signal_prisoner(state[1:2]...) == state[3]
for state in eachrow(character_state_combinations)
@test can_signal_prisoner(state[1:2]...) == state[3]
end
end
end

@testset "freeing prisoner" begin
character_state_combinations = Bool[
0 0 0 0 0;
0 0 0 1 1;
0 0 1 0 1;
0 0 1 1 1;
0 1 0 0 0;
0 1 0 1 0;
0 1 1 0 0;
0 1 1 1 0;
1 0 0 0 0;
1 0 0 1 1;
1 0 1 0 0;
1 0 1 1 1;
1 1 0 0 0;
1 1 0 1 0;
1 1 1 0 0;
1 1 1 1 0;
]
@testset "freeing prisoner" begin
character_state_combinations = Bool[
0 0 0 0 0;
0 0 0 1 1;
0 0 1 0 1;
0 0 1 1 1;
0 1 0 0 0;
0 1 0 1 0;
0 1 1 0 0;
0 1 1 1 0;
1 0 0 0 0;
1 0 0 1 1;
1 0 1 0 0;
1 0 1 1 1;
1 1 0 0 0;
1 1 0 1 0;
1 1 1 0 0;
1 1 1 1 0;
]

for state in eachrow(character_state_combinations)
@test can_free_prisoner(state[1:4]...) == state[5]
for state in eachrow(character_state_combinations)
@test can_free_prisoner(state[1:4]...) == state[5]
end
end
end
26 changes: 14 additions & 12 deletions exercises/concept.wip/annalyns-infiltration2/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ include("game.jl")
# This exercise isn't about mathematical methods to determine the distribution of a random sample,
# therefore we only test that all possible values are returned at least once.

@testset "fog" begin
@test Set(is_foggy() for _ in 1:1000) == Set([true, false])
end
@testset verbose = true "tests" begin
@testset "fog" begin
@test Set(is_foggy() for _ in 1:1000) == Set([true, false])
end

@testset "distracted dog" begin
@test Set(is_dog_distracted() for _ in 1:1000) == Set([true, false])
end
@testset "distracted dog" begin
@test Set(is_dog_distracted() for _ in 1:1000) == Set([true, false])
end

@testset "loot purse" begin
@test Set(loot() for _ in 1:1000) == Set(3:13)
end
@testset "loot purse" begin
@test Set(loot() for _ in 1:1000) == Set(3:13)
end

@testset "loot crate" begin
crate = Set(["Cabbage", "Daring Dagger", "Sneaky Shoes"])
@test Set(loot(crate) for _ in 1:1000) == crate
@testset "loot crate" begin
crate = Set(["Cabbage", "Daring Dagger", "Sneaky Shoes"])
@test Set(loot(crate) for _ in 1:1000) == crate
end
end
80 changes: 41 additions & 39 deletions exercises/concept.wip/dnd-char/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,51 @@ using Test

include("dnd-character.jl")

@testset "Randomly generated ability is within range" begin
for i in 1:1000
@test 3 <= ability() <= 18
@testset verbose = true "tests" begin
@testset "Randomly generated ability is within range" begin
for i in 1:1000
@test 3 <= ability() <= 18
end
end
end

@testset "Ability modifiers are integers" begin
@test typeof(modifier(7)) <: Integer
end

@testset "Ability modifiers" begin
@test modifier(3) == -4
@test modifier(4) == -3
@test modifier(5) == -3
@test modifier(6) == -2
@test modifier(7) == -2
@test modifier(8) == -1
@test modifier(9) == -1
@test modifier(10) == 0
@test modifier(11) == 0
@test modifier(12) == 1
@test modifier(13) == 1
@test modifier(14) == 2
@test modifier(15) == 2
@test modifier(16) == 3
@test modifier(17) == 3
@test modifier(18) == 4
end
@testset "Ability modifiers are integers" begin
@test typeof(modifier(7)) <: Integer
end

@testset "Randomly generated character is valid" begin
# Helper method to check if all abilities of a character are within the expected ranges.
function ischaracter(c)
3 <= c.strength <= 18 &&
3 <= c.dexterity <= 18 &&
3 <= c.constitution <= 18 &&
3 <= c.intelligence <= 18 &&
3 <= c.wisdom <= 18 &&
3 <= c.charisma <= 18 &&
c.hitpoints == 10 + modifier(c.constitution)
@testset "Ability modifiers" begin
@test modifier(3) == -4
@test modifier(4) == -3
@test modifier(5) == -3
@test modifier(6) == -2
@test modifier(7) == -2
@test modifier(8) == -1
@test modifier(9) == -1
@test modifier(10) == 0
@test modifier(11) == 0
@test modifier(12) == 1
@test modifier(13) == 1
@test modifier(14) == 2
@test modifier(15) == 2
@test modifier(16) == 3
@test modifier(17) == 3
@test modifier(18) == 4
end

for i in 1:1000
c = DNDCharacter()
@test ischaracter(c)
@testset "Randomly generated character is valid" begin
# Helper method to check if all abilities of a character are within the expected ranges.
function ischaracter(c)
3 <= c.strength <= 18 &&
3 <= c.dexterity <= 18 &&
3 <= c.constitution <= 18 &&
3 <= c.intelligence <= 18 &&
3 <= c.wisdom <= 18 &&
3 <= c.charisma <= 18 &&
c.hitpoints == 10 + modifier(c.constitution)
end

for i in 1:1000
c = DNDCharacter()
@test ischaracter(c)
end
end
end
42 changes: 22 additions & 20 deletions exercises/concept.wip/documented-lasagna/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ function hasdocstring(s::Symbol)
haskey(meta, Docs.Binding(@__MODULE__, s))
end

@testset "solution still works" begin
@test preptime(2) == 4
@test preptime(3) == 6
@test preptime(8) == 16
@test remaining_time(30) == 30
@test remaining_time(50) == 10
@test remaining_time(60) == 0
@test total_working_time(3, 20) == 26
end

@testset "preptime has a docstring" begin
@test hasdocstring(:preptime)
end

@testset "remaining_time has a docstring" begin
@test hasdocstring(:remaining_time)
end

@testset "total_working_time has a docstring" begin
@test hasdocstring(:total_working_time)
@testset verbose = true "tests" begin
@testset "solution still works" begin
@test preptime(2) == 4
@test preptime(3) == 6
@test preptime(8) == 16
@test remaining_time(30) == 30
@test remaining_time(50) == 10
@test remaining_time(60) == 0
@test total_working_time(3, 20) == 26
end

@testset "preptime has a docstring" begin
@test hasdocstring(:preptime)
end

@testset "remaining_time has a docstring" begin
@test hasdocstring(:remaining_time)
end

@testset "total_working_time has a docstring" begin
@test hasdocstring(:total_working_time)
end
end
58 changes: 30 additions & 28 deletions exercises/concept.wip/elyses-analytic-enchantments/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,39 @@ using Test

include("enchantments.jl")

@testset "Determine if a card is present" begin
@test has_card([2, 3, 4, 5], 3)
end
@testset verbose = true "tests" begin
@testset "Determine if a card is present" begin
@test has_card([2, 3, 4, 5], 3)
end

@testset "Find the position of a card" begin
@test find_card([3], 3) == 1
@test find_card([9, 7, 3, 2], 2) == 4
@test find_card([8, 3, 9, 5], 8) == 1
@test isnothing(find_card([5, 3, 1, 9], 2))
end
@testset "Find the position of a card" begin
@test find_card([3], 3) == 1
@test find_card([9, 7, 3, 2], 2) == 4
@test find_card([8, 3, 9, 5], 8) == 1
@test isnothing(find_card([5, 3, 1, 9], 2))
end

@testset "Determine if each card is even" begin
@test !all_cards_even([1])
@test !all_cards_even([2, 5])
@test all_cards_even([2, 4, 8, 6])
end
@testset "Determine if each card is even" begin
@test !all_cards_even([1])
@test !all_cards_even([2, 5])
@test all_cards_even([2, 4, 8, 6])
end

@testset "Check if the deck contains an odd-value card" begin
@test !any_odd_cards([2, 4, 6])
@test any_odd_cards([2, 5])
@test any_odd_cards([1, 3, 5, 7])
end
@testset "Check if the deck contains an odd-value card" begin
@test !any_odd_cards([2, 4, 6])
@test any_odd_cards([2, 5])
@test any_odd_cards([1, 3, 5, 7])
end

@testset "Determine the position of the first card that is even" begin
@test first_even_card_idx([2, 4, 1, 3]) == 1
@test first_even_card_idx([1, 2]) == 2
@test isnothing(first_even_card_idx([1, 3, 5]))
end
@testset "Determine the position of the first card that is even" begin
@test first_even_card_idx([2, 4, 1, 3]) == 1
@test first_even_card_idx([1, 2]) == 2
@test isnothing(first_even_card_idx([1, 3, 5]))
end

@testset "Get the first odd card from the deck" begin
@test first_odd_card([2, 4, 1, 3]) == 1
@test first_odd_card([1, 2]) == 1
@test isnothing(first_odd_card([4, 2, 6]))
@testset "Get the first odd card from the deck" begin
@test first_odd_card([2, 4, 1, 3]) == 1
@test first_odd_card([1, 2]) == 1
@test isnothing(first_odd_card([4, 2, 6]))
end
end
Loading

0 comments on commit a9e391b

Please sign in to comment.