-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recipe coverage graph test #2030
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
af2a7bc
Refactor recipe graph to use in tests
xsebek 0eebaae
Use recipe graph in recipe coverage
xsebek 17c917d
Move to integration
xsebek 9ebb6f2
Sort nonCoveredEntities
xsebek a0d4119
remove expected failure form unit test deps
xsebek 45f10c6
Add test per recipe
xsebek 047ba3a
Update recipe graph with yields
xsebek 9b3c18a
Update with new recipes
xsebek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Ensure recipe coverage for all entities. | ||
module TestRecipeCoverage (testRecipeCoverage) where | ||
|
||
import Control.Lens (view) | ||
import Data.List qualified as List | ||
import Data.Set qualified as Set | ||
import Data.Text qualified as T | ||
import Swarm.Doc.Gen | ||
import Swarm.Game.Entity (Entity, EntityName, entityName) | ||
import Swarm.Util (quote) | ||
import Test.Tasty | ||
import Test.Tasty.ExpectedFailure (expectFailBecause) | ||
import Test.Tasty.HUnit | ||
|
||
-- | Generate test tree to check that each entity either has a reachable | ||
-- recipe or is in the world or starting base robot inventory. | ||
-- | ||
-- If you added a recipe, thank you, please remove the entity from the list | ||
-- of known uncraftable entities. | ||
-- If you are not sure why an entity with a recipe is unreachable, check out | ||
-- the dot graph of entity recipes in 'Swarm.Doc.Gen' that this test uses. | ||
testRecipeCoverage :: IO TestTree | ||
testRecipeCoverage = do | ||
graphData <- classicScenarioRecipeGraphData | ||
let sortE = List.sortOn (T.unpack . view entityName) | ||
allEntities = sortE . Set.toList $ rgAllEntities graphData | ||
nonCovered = getNonCoveredEntities graphData | ||
return . testGroup "Ensure all entities have recipes" $ | ||
map (\e -> expectNonCovered e $ checkCoverage nonCovered e) allEntities | ||
where | ||
checkCoverage :: Set.Set Entity -> Entity -> TestTree | ||
checkCoverage s e = | ||
let name = view entityName e | ||
in testCase (T.unpack name) $ do | ||
assertBool (errMessage name) (name `elem` ignoredEntities || e `Set.notMember` s) | ||
where | ||
errMessage missing = T.unpack $ "Can not make " <> quote missing <> " from starting entities." | ||
|
||
expectNonCovered :: Entity -> TestTree -> TestTree | ||
expectNonCovered e = | ||
let name = T.toCaseFold (view entityName e) | ||
in if name `elem` nonCoveredList | ||
then expectFailBecause "More recipes needed (#1268)" | ||
else id | ||
|
||
-- | Known non-covered entities that need a recipe. | ||
nonCoveredList :: [EntityName] | ||
nonCoveredList = | ||
map | ||
T.toCaseFold | ||
[ "Elmer's glue" | ||
, "ash" | ||
, "binoculars" | ||
, "blueprint" | ||
, "caliper" | ||
, "decoder ring" | ||
, "linotype" | ||
, "tape drive" | ||
, "wedge" | ||
] | ||
|
||
getNonCoveredEntities :: RecipeGraphData -> Set.Set Entity | ||
getNonCoveredEntities graphData = rgAllEntities graphData `Set.difference` Set.unions (rgLevels graphData) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@byorgey I think you updated the graph display to Dot, but not the levels computation.
If Dot could lay out the graph well, the levels would not even be needed. But because we have so many connections, the levels at least group together nodes in order.