Skip to content

Commit

Permalink
Lathe Arbitrage Integration Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Roudenn committed Jan 9, 2025
1 parent 75e69b7 commit 5a6fa5c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
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;
}
}
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Objects/Misc/space_cash.yml
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

0 comments on commit 5a6fa5c

Please sign in to comment.