Implement tests for vendors#7906
Conversation
3e6c5e7 to
e030737
Compare
|
So the current build failures appear to be due to a sourceware.org timeout, and not anything in the actual code in this PR. |
There was a problem hiding this comment.
Personally I generally prefer test that do not have a randomized outcome since they can sporadically fail making it hard to both bisect and debug and they can miss errors that then randomly block another PR for unknown reasons.
It also means you do not end up simply duplicating the games logic in the assertion but test for a very specific outcome that is mostly free of logic.
I can set a static seed, and I understand your position completely on that matter.
This will require some explanation on my part. The idea here was that I was intending to change some more vendor code in the future. The tests are to ensure that the same qlvls and item types are generated, but not necessarily the same items exactly. I believe this can be done without morphing because the actual item generation code is in while (PremiumItemLevel < lvl) {
PremiumItemLevel++;
if (gbIsHellfire) {
// Discard first 3 items and shift next 10
std::move(&PremiumItems[3], &PremiumItems[12] + 1, &PremiumItems[0]);
SpawnOnePremium(PremiumItems[10], PremiumItemLevel + itemLevelAddHf[10], player);
PremiumItems[11] = PremiumItems[13];
SpawnOnePremium(PremiumItems[12], PremiumItemLevel + itemLevelAddHf[12], player);
PremiumItems[13] = PremiumItems[14];
SpawnOnePremium(PremiumItems[14], PremiumItemLevel + itemLevelAddHf[14], player);
} else {
// Discard first 2 items and shift next 3
std::move(&PremiumItems[2], &PremiumItems[4] + 1, &PremiumItems[0]);
SpawnOnePremium(PremiumItems[3], PremiumItemLevel + itemLevelAdd[3], player);
PremiumItems[4] = PremiumItems[5];
SpawnOnePremium(PremiumItems[5], PremiumItemLevel + itemLevelAdd[5], player);
}
}Iterates in the I can forego that idea, and I can change the test to only test for a specific outcome. In that case, if I did make the change, the test would fail because less items are generated and they wouldn't be the same (though the item generation logic would be). That's not a difficult thing to fix, simply change the outcome tested for, but it makes it harder to prove that the change behaves correctly. |
|
Wouldn't that change mean that items in the store morph in save games between the two versions? |
Could you let me know where it crashes, it's curious since we have item generation tests that generate hellfire items without crashes. Maybe there is some code we just need to not invoke in headless. |
I don't believe so, because the call chain looks as follows when loading a game: When SetRndSeed(iseed);
_item_indexes itype = RndPremiumItem(player, plvl / 4, plvl);
GetItemAttrs(item, itype, plvl);
GetItemBonus(player, item, plvl / 2, plvl, true, !gbIsHellfire);Since the seed is saved for the item, it should create the same item when loading the game. Of course I will make sure things do not morph when I get around to implementing it, and wouldn't open a PR if I find that they do.
Never mind. |
Rename functions Comments
This commit adds tests for the SpawnWitch() function: - Tests that the correct pinned items are generated. - Tests that only allowed items for the vendor are generated. - Tests that the correct number of items are generated. - Tests that, at minimum, the number of books is equal to the pinned number of books. Rename ITEMS_PINNED Remove Hellfire check from WitchGen test
This commit implements tests for Griswold's basic item generation: - Tests that the correct items are generated. - Tests that the correct number of items are generated.
This commit implements tests for Pepin: - Tests that the correct pinned items are generated. - Tests that the correct type of items are generated. - Tests that the correct number of items are generated. Set Hellfire flag for Pepin
Cleanup
Do not assert and fail on HaveHellfire() == false Add missing EXPECT_THAT() Fix premium item test bugs Fix MSVC link failure Correct premium item type matches
Failure message changes More failure reporting improvements
This reverts commit ec5db72.
Add missing setCharacterLevel()
ecc945d to
012d930
Compare
|
Hi, So I've done some changes to this now that I've found the time. All the premium item generation now uses static test cases, and the function test_premium_qlvl is gone. The array for expected qlvls is initialised as constexpr in the scope where it's relevant. Additionally, some things have been moved into the fixture class' SetUp() function. Besides that, I've also split up PremiumQlvl and PremiumQlvlHf into more test cases, since I think their scope justifies it. I hope this test suite is better now. I know it's a lot of code to review, but hopefully it won't be a big pain. Regards, |
|
Nice work, was to bad to review it either. ... oh but feel free to amend commits 27 of them doesn't seem to benefit the logic :) |
Hello,
First off I would like to apologise for the low quality of my previous PR, and the overall mess it was to review it. I promise that my PRs will be of higher quality in the future, hopefully starting with this one.
As part of my effort to use StaticVector for vendors, I have implemented a range of tests for the vendors to ensure that the item generation is identical in the relevant ways (item types, amount of items. premium item qlvl etc.). That effort is now mostly complete and do pass these tests, but I figure that separating these into two different PRs makes sense. This will also ensure that any modification to vendors in the future need to pass these tests, and that one can determine correctness at a glance.
Regards,
yggdrasill