55 Commits

Author SHA1 Message Date
dumb-kevin 05ab42807e tests/: wrap TU-local test fixture types in anon namespaces
- addiction_test: wrap addict_effect_totals
- battery_density_test: wrap battery_chemistry_family
- comestible_test: wrap all_stats
- encumbrance_test: wrap add_trait
- invlet_test: fuse inventory_location + invlet_state + test_action enums
- throwing_test: fuse throw_test_data + throw_test_pstats, move operator<< inside anon-ns
- vehicle_test: wrap vehicle_preset, damage_preset, folded_item_damage_preset, fuse rack_activation + rack_preset
- vision_test: wrap vision_test_case
- water_movement_test: fuse 6 swimmer/swim structs into one block
- weakpoint_test: wrap weakpoint_test_data, weakpoint_expectation, weakpoint_report
2026-05-12 10:53:28 +04:00
Procyonae 703cc90a71 Remove STATIC() macro (#81780)
* Remove STATIC macro a-f

Fixes a typo in character_armor where a damage type was somehow being implicitly cast to a bool?

* Remove STATIC macro g-i

Trusts a post 0.H todo comment to do with cables, the PR was huge so I'm just hoping this got migrated properly

* Remove STATIC macro j-z

* Remove make_static.h includes

* Cleanup

* Remove STATIC macro /tests

* Remove comments yesterday me left for today me

* Update clang for STATIC macro removal

* Cleanup round 2

* Cleanup round 2

The A-Z before a-z thing gets me every time >-<
2025-07-15 13:29:50 +02:00
Maleclypse 55bdae6518 Fix #81333 Negative quench items don't dehydrate you (#81347) 2025-06-19 20:21:01 -07:00
Procyonae 61ffda4f3e Add test to ensure calorie density < ~9.02cal/g (#81051)
* Add tests to ensure calorie density <= 9kcal/g

* IWYU

* Update known_bad_calorie_density.json

* add missing mod items to known_bad_calorie

* fix calories of blood_tainted in magiclysm

* Add comestible subtype to blood_tainted

---------

Co-authored-by: Anton Simakov <67688115+GuardianDll@users.noreply.github.com>
2025-05-26 19:31:06 +02:00
moxian 2ee44002fd Mechanically IWYU the tests
python3 ~/github/include-what-you-use/iwyu_tool.py -j5 -p build $( find
src/ tests/ -maxdepth 1 -name '*.cpp' | grep -v -f
tools/iwyu/bad_files.txt )  --  -Xiwyu --comment_style=long -Xiwyu -
-max_line_length=1000 -Xiwyu --cxx17ns -Xiwyu
--mapping_file=../tools/iwyu/cata.imp   | tee out/iwyu/f-a-01.txt >
/dev/null

followed by

cat out/iwyu/f-a-02.txt | python3
~/github/include-what-you-use/fix_includes.py --reorder --nosafe_headers

followed by manual fixups of <stddef.h> -> <cstddef> and similar.

tests/generic_factory_test.cpp gets mangled very badly (IWYU bug) so
it's excluded from the list.

Code size:
includes:
$ cat obj/tiles/*.inc | wc
 288068  576136 17898260
$ cat tests/obj/tiles/*.inc | wc
 167044  334088 10465766

post-processed source (clang -E):
./make_preproc.sh src/
68567896 177775140 2134075721
./make_preproc.sh tests/
39341957 102891720 1243323710
2025-02-10 00:46:57 -08:00
Procyonae 982df19d0f Change /tests remaining uses of raw string item initialisation to use itype_id s
"remaining uses" being somewhat of an understatement -_-
2025-01-10 15:31:15 +00:00
osuphobia c10d2733a1 satisfy clang 2024-11-28 22:31:20 +08:00
osuphobia e0e19edfcc Fix an oversight, add comments to test case. 2024-11-28 20:16:06 +08:00
osuphobia 01b5fc4927 Apply suggestions from code review
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2024-11-28 19:58:26 +08:00
osuphobia 3a0dfeb524 Update effective_food_volume_and_satiety test. 2024-11-28 19:27:33 +08:00
TheMurderUnicorn c7e32122d0 Merge Proc's amendment to test
idk changing tests is scary I hope it's okay, I trust Proc
2024-11-14 16:37:10 -05:00
RenechCDDA 7729666156 Make default nutrition mostly private, with a setter 2024-10-31 23:56:16 -04:00
ehughsbaird 7d73f4d5f5 Allow specifying vitamins by weight (mass) in items (#68986)
* Privatize nutrients::vitamins

In preparation for changing how vitamins are represented/stored under
the hood, privatize the structure storing vitamins and update the code
to interface with it correctly.

The new members added to the struct are the functions
set_vitamin(), add_vitamin(), remove_vitamin() and vitamins()
The other change is to move the vitamins variable to a private variable
vitamins_

Astyle reformatted the struct with the addition of the visibility

* Allow specifying vitamins in items by weight/mass

Often, nutrition info will list vitamins by weight. Additionally, RDA,
being defined by humans, is subject to change. For these reasons, it
should be possible to specify vitamins by weight in item definitions.

To do this, vitamins need to know how weight corresponds to units, and
items need to load in weight as well as units, and convert to units as
necessary. Unfortunately, as items may be loaded before vitamins, both
the loaded weight values and units values must be stored until all data
is loaded and they can be converted to units. To facilitate this, turn
the vitamins data stored in nutrients into a map from vitamin id to a
union of int and units::mass. This can then be finalized after loading
to convert all units::mass values to units.

Some nutrients functions modified to safely handle the union type.

LIMITATIONS:
There's a lot of rounding that the whole vitamins system is subject to.
This adds some more rounding: Any fractional vitamins due to weight are
discarded. However, this is the same as the previous approach, but
happens at load time instead of when the content is being added.
Additionally, vitamins (like iron) that have an RDA of less than 1mg
cannot really benefit from this system.

Demonstrate this by adding appropriate weights to nutrition vitamins
(barring iron) and modifying some items to specify their vitamins by
weight (both normally and through relative).
2023-11-02 22:53:15 -05:00
mqrause 0aeaf4a7b0 cache nutrient results for recipes while calculating nutrient range for food info 2023-08-07 01:13:30 +02:00
Alexey 07356b65a5 Normalize TEST_CASE names (#66241)
* Convert integer parsing test to use normal TEST_CASEs

* Rename test name too similar to another

* Test to enforce normalized test names

* Normalize TEST_CASE names (scripted)
2023-06-17 13:57:19 -03:00
mqrause 8c501c12ae refactor Character::complete_craft (#63704)
Co-authored-by: mqrause <martin@qrause.de>
2023-03-11 17:04:47 -05:00
Zhilkin Serg e44f38af40 Remove excessive empty lines 2022-12-06 10:42:15 +03:00
Ava d32ee0f13c Mutation system refinements, take two (#61036)
* Mutation system refinements, take two: squashed edition

created with copious amounts of agony and ice cream

* proofreading, resolve test failure

* I realy should try magiclysm one of these days

* on second thought, no popups for now

* the github test run took TWO HOURS. AAAAH

* [wailing]
2022-10-07 05:03:02 -04:00
Martin Lange ddb698c1c1 Fix: Make graph color in health and bandaging menu consistent with sidebar (#60572)
* make HP colors in bandaging and health menu consistent with sidebar

* adapt tests for changed color scales (satiety)
2022-08-30 12:28:31 +02:00
anothersimulacrum 84bc552aa4 Healthy bounds: ensure comest actually has mut vit (#60028)
About 900 comestibles have, for whatever reason, all the mutagen
vitamins defined in their default nutrition, just with an amount of 0.
Because the test only checks if they have a mutagen vitamin defined,
instead of have any amount of it, it incorrectly flags these as mutagens
and doesn't check them.

Fix the check, and fix the item that was now causing it to fail.
2022-08-08 13:56:36 -04:00
anothersimulacrum b3c3acda8d Only check health of comestibles from 'dda' (#59094)
We don't care about making assertions for modded items, so just skip
them.
2022-07-09 02:29:48 -04:00
Fris0uman c011421762 Appease clang 2022-07-03 14:19:40 +02:00
Fris0uman 354c386632 Exclude marloss food from test 2022-07-03 12:34:10 +02:00
Fris0uman 36c2349612 skip food with mutagen vitamin 2022-07-03 12:34:09 +02:00
Fris0uman 0b4ce2c8d2 exclude drugs from test 2022-07-03 12:34:09 +02:00
Fris0uman 50d07e7953 exclude mutagens from the test 2022-07-03 12:34:09 +02:00
Fris0uman 384b4bb2aa Add test to check food health is [-1,0] 2022-07-03 12:34:09 +02:00
John Bytheway e95a4fc9b8 Promote string_id constants to global statics
Our string_id constants were a mixture of temporaries, locals, and
globals.  Pull them all out as globals, for consistency and efficiency.
The efficiency comes from the fact that each string_id instance caches
its respective int_id, and sharing one instance means that value need
not be recomputed.
2021-11-19 19:10:09 -05:00
actual-nh 26d68f695a Change recipe_permutations to 0.75-1.25 range
Using 2 sparrow eggs, while it increased the recipe average, still
did not get it within 2 standard deviations of the item's calories,
probably because the standard deviation is only 96 - probably brought
down by multiple identical-calorie other eggs in other permutations.
Adjusting the "backup" for the standard deviation-based check to
use 0.75-1.25 still catches 54 being too low, but allows it with
using 2 sparrow's eggs. (I have some suspicion the original calories
are from a commercial item, which when not deliberately otherwise
tend to be rather caloric to increase customer liking (sugar and fat).
2021-09-04 19:53:46 -04:00
actual-nh c52466b592 Check stddev of recipes in recipe_permutations
Seeing if too-narrow standard deviation is why the test still isn't
passing.
2021-09-04 19:19:49 -04:00
Kevin Granade 99e47e2867 Rearange recipe permutation test to avoid massive memory allocation. (#50140)
* Rearange recipe permutation test to avoid massive memory allocation.
* limit test parallelism on gcc ASan build to one worker.
2021-07-22 20:38:24 -07:00
mqrause e1a3575a09 private contents member and remove most item_contents.h includes 2021-07-23 00:23:22 +02:00
mqrause df54fe15b2 wrappers for item_contents::only_item and item_contents::favorite_settings_menu in item 2021-07-12 14:46:47 +02:00
mqrause 48e59d2a12 wrapper for item_contents::num_item_stacks in item 2021-07-08 13:54:47 +02:00
John Bytheway ebd549b300 Fix StringMaker ODR violations in tests
Catch2 provides a customization point for converting our types to
strings by specializing the StringMaker template.

We have some specializations in stringmaker.h, but this feature was only
working intermittently.  I finally figured out that was due to an ODR
violation.  The test files that didn't include stringmaker.h were
compiling a different specialization than the ones that did.

Re-jig the test includes so that any file including catch.hpp also
includes stringmaker.h, thereby ensuring that the custom
specializations are used everywhere and there is no ODR violation.

I achieved this by adding a new cata_catch.h header and making all
existing headers include catch.hpp via the new header.
2021-07-03 07:42:06 -07:00
Binrui Dong 9fdb7ef59c Run IWYU
* Change _ctype.h and __locale to cctype and clocale

* Change _wctype.h to cwctype in game.cpp

* Change __functional_base to functional

* Remove libcxx internal headers

* Remove UNIX system headers

* Fix clang-tidy error with -nostdinc++
2021-02-06 00:18:41 -05:00
anothersimulacrum 5a522981a6 Use calories instead of kcal in nutrients
calorie precision is only used internally, all external methods should
be dealing with kcal.

Having calorie precision just enables removing rng-based rounding from
metabolism functions, without losing detail.

There was a very minor change in the Calories of some crafted items, as
is caught in the tests.
2021-01-22 11:21:53 -08:00
Aivean 6303014b84 mass-rename flag_str_id to flag_id 2020-11-19 19:24:50 -08:00
I-am-Erk ff1aba8cf0 Introduce "chewing" to reduce the volume of low density foods (#45106)
* calculate masticated_volume to reduce problems with satiety
* adjust thresholds on stomach contents tests
2020-11-06 13:03:57 -08:00
Aivean e33e19f678 fix clang-tidy warnings 2020-10-18 22:23:50 -07:00
Aivean c32a629ceb replace all item flag constants with static string_ids
remove adapter has_flag (and related) methods that took string argument
change all remaining method signatures where item flags were passed as strings
2020-10-18 19:56:40 -07:00
Qrox 18524b9133 Fix out of bounds access in get_bar, improve satiety_bar 2020-10-04 04:11:19 +00:00
George Karfakis ba75c03d9a PR #2: Replacing the CAL/kg row of the (E)at menu with a more meaningful Satiety row. (#44490) 2020-10-02 12:18:15 +03:00
Kevin Granade c5ccf0c2c7 IWYU for tests (#42806) 2020-08-09 09:46:57 +03:00
Kevin Granade 6d1841ac67 Precompiled Catch2 header (#42453)
* Hoist catch.hpp include to the top of files

* Precompile the catch header in tests
2020-07-29 01:28:26 +03:00
Curtis Merrill 6e970427ba make comestible test clearer (#41554)
* make comestible test clearer

* Update comestible_test.cpp
2020-06-24 09:20:40 -07:00
Kevin Granade 438774d386 Global getters (#41347)
* Make Character::stat into a standalone enum class

Enables forward declaration

* Remove player centric overload and unecessary include

* Remove player.h dependency from trap.cpp

* Add singleton-like accessors for avatar, map, weather and event_bus

* use accessors to remove includes of game.h
2020-06-16 16:48:45 +03:00
ZhilkinSerg fa980f35ea Use constant references in loops+modernize loops 2020-05-29 11:06:38 +03:00
John Bytheway b83fc88b9e Convert itype_id to string_id<itype>
itype_id is (presumably) one of the oldest type ids in the game.  In
particular, it predates string_id, and was simply a typedef of
std::string.

This is bad for type safety.

Make it be a string_id specialization instead, and update the rest of
the code accordingly.
2020-05-19 21:07:40 -04:00
KorGgenT 08870bd5b9 fix comestible tests 2020-05-02 16:05:19 -04:00