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

[Feature] Lathe Arbitrage Integration Test #997

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using Content.Server.Cargo.Systems;
using Content.Shared.Research.Prototypes;

namespace Content.IntegrationTests.Tests.Backmen.Lathe;

[TestFixture]
public sealed class LatheRecipyCostTest
{
private const double Tolerance = 10;

[Test]
public async Task LatheRecipesNoArbitrageTest()
{
await using var pair = await PoolManager.GetServerClient();

var server = pair.Server;
var proto = server.ProtoMan;
var entMan = server.EntMan;
var priceSystem = entMan.System<PricingSystem>();

var fails = new List<string>();

await server.WaitAssertion(() =>
{
var recipes = proto.EnumeratePrototypes<LatheRecipePrototype>();
foreach (var recipe in recipes)
{
var resultPrice = Math.Round(priceSystem.GetLatheRecipePrice(recipe));
var matPrice = 0.0;
bool ignoreRecipe = false;
foreach (var (materialId, count) in recipe.Materials)
{
var material = proto.Index(materialId);

if (material.IgnoreArbitrage)
ignoreRecipe = true;

matPrice += material.Price * count;
}

if (ignoreRecipe)
continue;

matPrice = Math.Round(matPrice);

if (resultPrice > matPrice + Tolerance)
{
fails.Add($"ID: {recipe.ID} Materials: {matPrice} Result: {resultPrice} Dif: {resultPrice - matPrice}");
}
}
});

if (fails.Count > 0)
{
var msg = string.Join("\n", fails) + "\n" + "Following RecipePrototypes are giving Arbitrage when printed!";
Assert.Fail(msg);
}

await pair.CleanReturnAsync();
}
}
7 changes: 7 additions & 0 deletions Content.Shared/Materials/MaterialPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,12 @@ public sealed partial class MaterialPrototype : IPrototype, IInheritingPrototype
/// </summary>
[DataField(required: true)]
public double Price = 0;

/// <summary>
/// Backmen Change: Setting this to true will make
/// this material be ignored in Price Tests.
/// </summary>
[DataField]
public bool IgnoreArbitrage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
stackEntity: SpaceCash
icon: { sprite: /Textures/Objects/Economy/cash.rsi, state: cash }
price: 1
ignoreArbitrage: true # lathe-test change # uhhhh no

- type: stack
id: Credit
Expand Down
3 changes: 3 additions & 0 deletions Resources/Prototypes/Reagents/Materials/materials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
icon: { sprite: /Textures/Objects/Misc/monkeycube.rsi, state: cube }
color: "#8A9A5B"
price: 0.1
ignoreArbitrage: true # lathe-test change # We don't care about biomass too much...

- type: material
id: Cardboard
Expand All @@ -14,6 +15,7 @@
icon: { sprite: /Textures/Objects/Materials/materials.rsi, state: cardboard }
color: "#70736c"
price: 0.025
ignoreArbitrage: true # lathe-test change

- type: material
id: Cloth
Expand Down Expand Up @@ -41,6 +43,7 @@
icon: { sprite: Objects/Materials/Sheets/other.rsi, state: paper }
color: "#d9d9d9"
price: 0.01 # it's paper bro what do you expect?
ignoreArbitrage: true # lathe-test change

- type: material
id: Plasma
Expand Down
11 changes: 10 additions & 1 deletion Resources/Prototypes/Reagents/Materials/ores.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
unit: materials-unit-chunk
icon: { sprite: Objects/Materials/ore.rsi, state: iron }
price: 0.05
ignoreArbitrage: true # lathe-test change

- type: material
id: RawQuartz
Expand All @@ -14,6 +15,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: spacequartz }
color: "#a8ccd7"
price: 0.075
ignoreArbitrage: true # lathe-test change

- type: material
id: RawGold
Expand All @@ -23,6 +25,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: gold }
color: "#FFD700"
price: 0.2
ignoreArbitrage: true # lathe-test change

- type: material
id: RawDiamond
Expand All @@ -32,6 +35,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: diamond }
color: "#C9D8F2"
price: 0.5
ignoreArbitrage: true # lathe-test change

- type: material
id: RawSilver
Expand All @@ -41,6 +45,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: silver }
color: "#C0C0C0"
price: 0.15
ignoreArbitrage: true # lathe-test change

- type: material
id: RawPlasma
Expand All @@ -50,6 +55,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: plasma }
color: "#7e009e"
price: 0.2
ignoreArbitrage: true # lathe-test change

- type: material
id: RawUranium
Expand All @@ -59,6 +65,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: uranium }
color: "#32a852"
price: 0.2
ignoreArbitrage: true # lathe-test change

- type: material
id: RawBananium
Expand All @@ -68,6 +75,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: bananium }
color: "#32a852"
price: 0.2
ignoreArbitrage: true # lathe-test change

- type: material
id: RawSalt
Expand All @@ -76,4 +84,5 @@
unit: materials-unit-chunk
icon: { sprite: Objects/Materials/ore.rsi, state: salt }
color: "#f5e7d7"
price: 0.075
price: 0.075
ignoreArbitrage: true # lathe-test change
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
name: prize ticket
icon: { sprite: Backmen/Objects/Fun/prizeticket.rsi, state: ticket }
price: 0
ignoreArbitrage: true # lathe-test change
Loading