Skip to content
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

Test and refactor item info display functions #40883

Merged
merged 12 commits into from
Jun 1, 2020

Conversation

wapcaplet
Copy link
Contributor

@wapcaplet wapcaplet commented May 27, 2020

Summary

SUMMARY: Infrastructure "Test and refactor item info display functions"

Purpose of change

To make the item::info function and its brethren cleaner, more modular, and more well-tested.

Describe the solution

Refactors existing iteminfo test cases and adds many new ones. Refactors a few item::xxx_info functions.

Removes some unnecessary/empty info output, including the following:

The "Compatible magazines:" section, previously displayed for all tools, even those with no magazines:

image

This "Ammunition" section of combat stats, previously displayed for many kinds of charged battery:

image

And this empty "Type:" section, formerly displayed for various guns when they did not have a magazine inserted (all glocks, AR pistol, all rivtech guns and many others):

image

Grants pet armor the possibility to have a get_base_env_resist, meaning their fire / acid / env protection is (supposedly) more correctly indicated in the item info panel now, at least based on my test cases - I could not reproduce the change in-game with existing pet armors.

Adds iteminfo_parts enum values to filter information:

  • BASE_OWNER - Item owner (ex. Your Followers)
  • BASE_DPS - Typical damage per second
  • FOOD_ALLERGEN - This food will cause an allergic reaction
  • BOOK_INCLUDED_RECIPES - List of recipes included in a book
  • DESCRIPTION_ALLERGEN - This clothing will cause an allergic reaction
  • DESCRIPTION_DIE - This item can be used as a die, and has N sides

Adds many new tests, including:

  • combat info
    • weapon attack ratings, moves, damage per second
  • armor fit and sizing, power armor flag
  • armor protection
    • bash/cut/bullet based on material and thickness
    • acid/fire/env require nonzero environmental protection
  • volume and weight
    • metric and imperial
  • requirements
    • strength, perception, intelligence
    • skills and levels needed
  • food info
    • fun, portions, consume time
    • fruit allergy, hidden poison, hidden hallucinogen
    • human flesh and cannibalism
  • medicine info
    • quench, fun, stim, portions, consume time, addiction
  • gun info
    • range, damage, armor piercing, critical multiplier
    • dispersion, signt dispersion
    • ammo capacity, default ammo
    • recoil, reload time, firing modes, dispersion
  • gunmod info
    • flags - reach attack, disable sights, consumable
    • sight dispersion, aim speed, damage modifier
    • compatible guns, mod location
  • bionic info
    • power storage, capacity
    • encumbrance, environmental protection
  • book info
    • for beginners, morale/fun, time per chapter
    • skill min, skill max, intelligence requirement
  • tool info, debug info, and final info

Finally, adds new test items, including suppressor, matches, apple, brewable tennis ball wine, radioactive carafe, super-juicy blueberry gum, poisonous bitter almonds, hallucinogenic nutmeg, some real-life computer literature, power armor, and meower armor.

Describe alternatives you've considered

Everyone knows the item info panel is far less than ideal. Using tabs or some other hierarchical display/navigation would be great, but even just restructuring the existing info is tricky due to the rigid way the functions are grouped and called. I hope to do some amount of refactoring of these into smaller, more modular pieces - but I consider a total iteminfo display overhaul like #38030 to be well beyond the scope of this PR.

I considered a variety of other cosmetic and phrasing changes, optimizing line-wrapping, making bullet points more consistently presented, and various other presentational improvements - but again, felt those things to be diversions, and outside scope.

Except for the removal of useless "Compatible magazines:" and "Ammunition" sections as noted above, and the relocation of a few pieces of gunmod and UPS info into more appropriate sections, there are no intended changes to the in-game info display.

Testing

tests/cata_test [iteminfo]

In-game testing with various items, to ensure their info displays as expected.

Additional context

This test suite and the item info panel itself have been my pet project since #37823, continuing with #40314 and #40686

Test results with [iteminfo] tag:

  • Before 111 assertions in 22 test cases
  • After: 399 assertions in 40 test cases

image

@anothersimulacrum anothersimulacrum added Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tests Measurement, self-control, statistics, balancing. [C++] Changes (can be) made in C++. Previously named `Code` labels May 29, 2020
@wapcaplet wapcaplet changed the title [WIP] Test and refactor item info display functions Test and refactor item info display functions May 30, 2020
@wapcaplet
Copy link
Contributor Author

wapcaplet commented May 30, 2020

There is a bad test case; I was afraid this one might fail, since the item order seems nondeterminstic:

iteminfo_test.cpp:1261: FAILED:
  CHECK( item_info_str( supp, usedon ) == "--\n" "Used on: <color_c_cyan>rifle</color> and <color_c_cyan>pistol</color>\n" )
with expansion:
  "--
  Used on: <color_c_cyan>pistol</color> and <color_c_cyan>rifle</color>
  "
  ==
  "--
  Used on: <color_c_cyan>rifle</color> and <color_c_cyan>pistol</color>
  "

Setting back to WIP to figure it out.

@wapcaplet wapcaplet changed the title Test and refactor item info display functions [WIP] Test and refactor item info display functions May 30, 2020
@jbytheway
Copy link
Contributor

It would not be a bad idea to add a new argument to enumerate_as_string to ask it to sort the strings for you. Would be useful in this case, and I bet a bunch of other places that call enumerate_as_string would use it too.

(Remember to use localized comparison)

@wapcaplet
Copy link
Contributor Author

It would not be a bad idea to add a new argument to enumerate_as_string to ask it to sort the strings for you. Would be useful in this case, and I bet a bunch of other places that call enumerate_as_string would use it too.

(Remember to use localized comparison)

I spent a while studying that function and some of its invocations, but had some difficulty understanding how it works. I'm also hesitant to change that function, since it's so widely used, and has no test cases. Making it do sorting would be nice, but looks like a minor side-project that I think would be out of scope for this PR.

For now I have simply commented out the order-dependent test that was failing.

@wapcaplet
Copy link
Contributor Author

Travis CI make+curses build is failing on this test case:

npc_test.cpp:255: FAILED:
  REQUIRE( guy != nullptr )
with expansion:
  nullptr != nullptr
with messages:
  Should not crash from infinite recursion
  NPC on acid should not acquire unstable footing status

I don't see any way my changes could be the cause of this.

@wapcaplet wapcaplet changed the title [WIP] Test and refactor item info display functions Test and refactor item info display functions May 30, 2020
@kevingranade
Copy link
Member

kevingranade commented May 30, 2020 via email

@wapcaplet
Copy link
Contributor Author

My new tests have a handful of problems with trailing whitespace in clang-tidy, which brought a couple more display bugs to my attention, and there's a conflict in src/item.cpp I need to resolve before this can be merged.

wapcaplet added 11 commits May 31, 2020 08:44
Add new entries to the iteminfo_query enum `iteminfo_parts` for several
pieces of info that did not have a part defined before, and uses those
parts to flag info for display by the item::info functions:

- BASE_OWNER - Item owner (ex. Your Followers)
- BASE_DPS - Typical damage per second
- FOOD_ALLERGEN - This food will cause an allergic reaction
- BOOK_INCLUDED_RECIPES - List of recipes included in a book
- DESCRIPTION_ALLERGEN - This clothing will cause an allergic reaction
- DESCRIPTION_DIE - This item can be used as a die, and has N sides
Including almond (poison), nutmeg (hallucinogen), apple, quiver, smart
phone, arrow, pointy stick, matches, suppressor, human thumb, brewable
tennis ball wine, radioactive carafe, super-juicy blueberry gum, some
real-life computer literature, power armor and meower armor.
This commit is the rebased summation of dozens of major changes and
additions to the iteminfo tests.

The entire approach to testing is now strongly centered around the
iteminfo_parts enum flags, to verify each piece of information in
isolation from the others.

Each test case focuses on a particular info function like `basic_info`
or `combat_info`, even though the top-level `item::info` function is
usually the only one directly invoked.

New tests include:

- armor fit, sizing, and protection
- item volume and weight, stat/skill requirements
- food and medicine info
- gun and gunmod info
- bionic, book, and tool info
- debug and final info
@kevingranade kevingranade merged commit aedec92 into CleverRaven:master Jun 1, 2020
@wapcaplet wapcaplet deleted the ii-too branch June 1, 2020 02:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Tests Measurement, self-control, statistics, balancing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants