From afb1cc943424e4145c365b8503f9b30655effa6f Mon Sep 17 00:00:00 2001 From: Afro Date: Thu, 21 Dec 2023 21:19:14 -0500 Subject: [PATCH] add more unit tests for `utils:math` and `omega-flowey:reset`/`omega-flowey:setup` (#34) - also updates `packtest_runner` to latest version so we can use latest `packtest` features --- .github/workflows/validate.yml | 3 +- .../tests/reset/should_wipe_scores.mcfunction | 16 ++++++ .../tests/setup/should_add_teams.mcfunction | 20 ++++++++ .../setup/should_reset_group_ids.mcfunction | 20 ++++++++ .../math/vector/dot_macro.mcfunction | 22 ++++---- .../data/utils/tests/math/max.mcfunction | 8 +-- .../data/utils/tests/math/min.mcfunction | 8 +-- .../utils/tests/math/vector/dot.mcfunction | 50 +++++++++++++++++++ 8 files changed, 123 insertions(+), 24 deletions(-) create mode 100644 datapacks/omega-flowey/data/omega-flowey/tests/reset/should_wipe_scores.mcfunction create mode 100644 datapacks/omega-flowey/data/omega-flowey/tests/setup/should_add_teams.mcfunction create mode 100644 datapacks/omega-flowey/data/omega-flowey/tests/setup/should_reset_group_ids.mcfunction create mode 100644 datapacks/omega-flowey/data/utils/tests/math/vector/dot.mcfunction diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 66b9529b7..e188ee362 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -8,6 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: CarbonSmasher/packtest_runner@9d13d673bf9d3f2fad2b833d036e5e12ff65e056 + - uses: CarbonSmasher/packtest_runner@86d606f25d2bd2faa08b017326fe99964ac3aa5c with: packs: 'datapacks/omega-flowey' + packtest-url: 'https://github.com/misode/packtest/releases/download/v1.0.0-beta5/packtest-1.0.0-beta5.jar' diff --git a/datapacks/omega-flowey/data/omega-flowey/tests/reset/should_wipe_scores.mcfunction b/datapacks/omega-flowey/data/omega-flowey/tests/reset/should_wipe_scores.mcfunction new file mode 100644 index 000000000..33fc84983 --- /dev/null +++ b/datapacks/omega-flowey/data/omega-flowey/tests/reset/should_wipe_scores.mcfunction @@ -0,0 +1,16 @@ +# @batch omega-flowey:setup + +## should wipe any preexisting scores + +scoreboard objectives add some.objective dummy +scoreboard players set #omega-flowey:reset math.0 1 +scoreboard players set #omega-flowey:reset some.objective -124 +assert score #omega-flowey:reset math.0 matches 1 +assert score #omega-flowey:reset some.objective matches -124 +function omega-flowey:reset + +execute store success score #omega-flowey:reset math.1 run scoreboard players get #omega-flowey:reset math.0 +assert score #omega-flowey:reset math.1 matches 0 + +execute store success score #omega-flowey:reset math.1 run scoreboard players get #omega-flowey:reset some.objective +assert score #omega-flowey:reset math.1 matches 0 diff --git a/datapacks/omega-flowey/data/omega-flowey/tests/setup/should_add_teams.mcfunction b/datapacks/omega-flowey/data/omega-flowey/tests/setup/should_add_teams.mcfunction new file mode 100644 index 000000000..d4e5cfe13 --- /dev/null +++ b/datapacks/omega-flowey/data/omega-flowey/tests/setup/should_add_teams.mcfunction @@ -0,0 +1,20 @@ +# @batch omega-flowey:setup + +## should add the `player` team +function omega-flowey:reset + +team remove player + +# create an entity with a group id +summon minecraft:pig ~ ~ ~ { Tags: ["omega-flowey", "test.setup.should-add-teams"], DeathLootTable: empty, NoAI: 1, PersistenceRequired: 1, } + +# should not be able to join team that doesn't exist +execute store success score #omega-flowey:setup math.0 as @e[tag=test.setup.should-add-teams] run team join player +assert score #omega-flowey:setup math.0 matches 0 + +# add the team +function omega-flowey:setup + +# should be able to join team that exists +execute store success score #omega-flowey:setup math.0 as @e[tag=test.setup.should-add-teams] run team join player +assert score #omega-flowey:setup math.0 matches 1 diff --git a/datapacks/omega-flowey/data/omega-flowey/tests/setup/should_reset_group_ids.mcfunction b/datapacks/omega-flowey/data/omega-flowey/tests/setup/should_reset_group_ids.mcfunction new file mode 100644 index 000000000..260692c88 --- /dev/null +++ b/datapacks/omega-flowey/data/omega-flowey/tests/setup/should_reset_group_ids.mcfunction @@ -0,0 +1,20 @@ +# @batch omega-flowey:setup + +## should wipe any preexisting scores + +function omega-flowey:reset + +# create an entity with a group id +summon minecraft:marker ~ ~ ~ {Tags:["omega-flowey","groupable","test.setup.should-reset-group-ids"]} + +assert score #group.id.next group.id matches 0 +execute as @e[tag=test.setup.should-reset-group-ids] run function entity:group/set +assert score #group.id.next group.id matches 1 + +# killing `groupable` entities should not immediately reset #group.id.next +kill @e[tag=test.setup.should-reset-group-ids] +assert score #group.id.next group.id matches 1 + +function omega-flowey:setup + +assert score #group.id.next group.id matches 0 diff --git a/datapacks/omega-flowey/data/utils/functions/math/vector/dot_macro.mcfunction b/datapacks/omega-flowey/data/utils/functions/math/vector/dot_macro.mcfunction index cbc3a14ee..62de37c18 100644 --- a/datapacks/omega-flowey/data/utils/functions/math/vector/dot_macro.mcfunction +++ b/datapacks/omega-flowey/data/utils/functions/math/vector/dot_macro.mcfunction @@ -1,15 +1,15 @@ -scoreboard players set @s math.0 0 +scoreboard players set #utils:math.vector.dot math.0 0 -$execute store result storage utils:math.vector.dot out float 1 run data get storage utils:math.vector.dot u.x $(x) -execute store result score @s math.1 run data get storage utils:math.vector.dot out 100 -scoreboard players operation @s math.0 += @s math.1 +$execute store result storage utils:math.vector.dot out float $(x) run data get storage utils:math.vector.dot u.x 100 +execute store result score #utils:math.vector.dot math.1 run data get storage utils:math.vector.dot out +scoreboard players operation #utils:math.vector.dot math.0 += #utils:math.vector.dot math.1 -$execute store result storage utils:math.vector.dot out float 1 run data get storage utils:math.vector.dot u.y $(y) -execute store result score @s math.1 run data get storage utils:math.vector.dot out 100 -scoreboard players operation @s math.0 += @s math.1 +$execute store result storage utils:math.vector.dot out float $(y) run data get storage utils:math.vector.dot u.y 100 +execute store result score #utils:math.vector.dot math.1 run data get storage utils:math.vector.dot out +scoreboard players operation #utils:math.vector.dot math.0 += #utils:math.vector.dot math.1 -$execute store result storage utils:math.vector.dot out float 1 run data get storage utils:math.vector.dot u.z $(z) -execute store result score @s math.1 run data get storage utils:math.vector.dot out 100 -scoreboard players operation @s math.0 += @s math.1 +$execute store result storage utils:math.vector.dot out float $(z) run data get storage utils:math.vector.dot u.z 100 +execute store result score #utils:math.vector.dot math.1 run data get storage utils:math.vector.dot out +scoreboard players operation #utils:math.vector.dot math.0 += #utils:math.vector.dot math.1 -execute store result storage utils:math.vector.dot out int 1 run scoreboard players get @s math.0 +execute store result storage utils:math.vector.dot out int 1 run scoreboard players get #utils:math.vector.dot math.0 diff --git a/datapacks/omega-flowey/data/utils/tests/math/max.mcfunction b/datapacks/omega-flowey/data/utils/tests/math/max.mcfunction index 18cd8ae5e..f93d168ef 100644 --- a/datapacks/omega-flowey/data/utils/tests/math/max.mcfunction +++ b/datapacks/omega-flowey/data/utils/tests/math/max.mcfunction @@ -4,24 +4,20 @@ data remove storage utils:math.max a data remove storage utils:math.max b data remove storage utils:math.max out -scoreboard players reset * -function omega-flowey:setup +function omega-flowey:reset -# cases +## cases data merge storage utils:math.max { a: 10, b: 10 } function utils:math/max execute store result score #utils:math.max math.0 run data get storage utils:math.max out - assert score #utils:math.max math.0 matches 10 data merge storage utils:math.max { a: 0, b: 1 } function utils:math/max execute store result score #utils:math.max math.0 run data get storage utils:math.max out - assert score #utils:math.max math.0 matches 1 data merge storage utils:math.max { a: 2, b: 1 } function utils:math/max execute store result score #utils:math.max math.0 run data get storage utils:math.max out - assert score #utils:math.max math.0 matches 2 diff --git a/datapacks/omega-flowey/data/utils/tests/math/min.mcfunction b/datapacks/omega-flowey/data/utils/tests/math/min.mcfunction index 88e1cc2dd..6dab64f83 100644 --- a/datapacks/omega-flowey/data/utils/tests/math/min.mcfunction +++ b/datapacks/omega-flowey/data/utils/tests/math/min.mcfunction @@ -4,24 +4,20 @@ data remove storage utils:math.min a data remove storage utils:math.min b data remove storage utils:math.min out -scoreboard players reset * -function omega-flowey:setup +function omega-flowey:reset -# cases +## cases data merge storage utils:math.min { a: 10, b: 10 } function utils:math/min execute store result score #utils:math.min math.0 run data get storage utils:math.min out - assert score #utils:math.min math.0 matches 10 data merge storage utils:math.min { a: 0, b: 1 } function utils:math/min execute store result score #utils:math.min math.0 run data get storage utils:math.min out - assert score #utils:math.min math.0 matches 0 data merge storage utils:math.min { a: 2, b: 1 } function utils:math/min execute store result score #utils:math.min math.0 run data get storage utils:math.min out - assert score #utils:math.min math.0 matches 1 diff --git a/datapacks/omega-flowey/data/utils/tests/math/vector/dot.mcfunction b/datapacks/omega-flowey/data/utils/tests/math/vector/dot.mcfunction new file mode 100644 index 000000000..73fd1b434 --- /dev/null +++ b/datapacks/omega-flowey/data/utils/tests/math/vector/dot.mcfunction @@ -0,0 +1,50 @@ +# @batch utils:math + +# setup +data remove storage utils:math.vector.dot u +data remove storage utils:math.vector.dot v +data remove storage utils:math.vector.dot out +function omega-flowey:reset + +## cases +# 0-vectors +data merge storage utils:math.vector.dot { u: { x: 0, y: 0, z: 0 }, v: { x: 0, y: 0, z: 0 } } +function utils:math/vector/dot +execute store result score #utils:math.vector.dot math.0 run data get storage utils:math.vector.dot out +assert score #utils:math.vector.dot math.0 matches 0 + +# mismatched axes -> 0 +data merge storage utils:math.vector.dot { u: { x: 1, y: 0, z: 0 }, v: { x: 0, y: 1, z: 0 } } +function utils:math/vector/dot +execute store result score #utils:math.vector.dot math.0 run data get storage utils:math.vector.dot out +assert score #utils:math.vector.dot math.0 matches 0 + +# single axis +data merge storage utils:math.vector.dot { u: { x: 1, y: 0, z: 0 }, v: { x: 1, y: 0, z: 0 } } +function utils:math/vector/dot +execute store result score #utils:math.vector.dot math.0 run data get storage utils:math.vector.dot out +assert score #utils:math.vector.dot math.0 matches 100 + +# negative values +data merge storage utils:math.vector.dot { u: { x: -1, y: 0, z: 0 }, v: { x: 1, y: 0, z: 0 } } +function utils:math/vector/dot +execute store result score #utils:math.vector.dot math.0 run data get storage utils:math.vector.dot out +assert score #utils:math.vector.dot math.0 matches -100 + +# positive + negative values +data merge storage utils:math.vector.dot { u: { x: 2, y: 0, z: 5 }, v: { x: 1, y: 0, z: -1 } } +function utils:math/vector/dot +execute store result score #utils:math.vector.dot math.0 run data get storage utils:math.vector.dot out +assert score #utils:math.vector.dot math.0 matches -300 + +# full vectors +data merge storage utils:math.vector.dot { u: { x: 1, y: 2, z: 3 }, v: { x: 4, y: 5, z: 6 } } +function utils:math/vector/dot +execute store result score #utils:math.vector.dot math.0 run data get storage utils:math.vector.dot out +assert score #utils:math.vector.dot math.0 matches 3200 + +# supports decimal values up to 100th place +data merge storage utils:math.vector.dot { u: { x: 1.5, y: 2.1, z: 3.12 }, v: { x: 3, y: 5, z: 7 } } +function utils:math/vector/dot +execute store result score #utils:math.vector.dot math.0 run data get storage utils:math.vector.dot out +assert score #utils:math.vector.dot math.0 matches 3684