• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samsmithnz / SatisfactoryTree / 17901166475

22 Sep 2025 12:34AM UTC coverage: 68.109% (+0.3%) from 67.811%
17901166475

Pull #310

github

web-flow
Merge b81997b41 into 0525e91df
Pull Request #310: Added new imported item type

426 of 734 branches covered (58.04%)

Branch coverage included in aggregate %.

94 of 187 new or added lines in 10 files covered. (50.27%)

7 existing lines in 3 files now uncovered.

1148 of 1577 relevant lines covered (72.8%)

1173.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.05
/src/SatisfactoryTree.Logic/Models/Plan.cs
1
using System.Security.Cryptography.X509Certificates;
2

3
namespace SatisfactoryTree.Logic.Models
4
{
5
    public class Plan
6
    {
7
        public List<Part> Parts { get; set; } = new();
2✔
8
        public List<Recipe> Recipes { get; set; } = new();
2✔
9
        public List<Building> Buildings { get; set; } = new();
2✔
10
        public List<Factory> Factories { get; set; } = new();
22✔
11

12
        public void UpdatePlanCalculations(FactoryCatalog factoryCatalog)
13
        {
2✔
14
            Calculator calculator = new();
2✔
15

16
            // Complete initial calculations
17
            foreach (Factory factory in Factories)
14✔
18
            {
4✔
19
                factory.ComponentParts = calculator.CalculateFactoryProduction(factoryCatalog, factory);
4✔
20
            }
4✔
21

22
            // Balance imports and exports across factories
23
            BalanceImportsAndExports();
2✔
24
        }
2✔
25

26
        private void BalanceImportsAndExports()
27
        {
2✔
28
            // Initialize exported quantities based on each factory's target production
29
            foreach (Factory factory in Factories)
14✔
30
            {
4✔
31
                foreach (ExportedItem exportedItem in factory.ExportedParts)
20✔
32
                {
4✔
33
                    // Initialize the exported quantity to the target production amount
34
                    exportedItem.PartQuantityExported = exportedItem.Item.Quantity;
4✔
35
                }
4✔
36
            }
4✔
37

38
            // Process each factory's import requests
39
            foreach (Factory factory in Factories)
14✔
40
            {
4✔
41
                foreach (KeyValuePair<int, ImportedItem> import in factory.ImportedParts)
16✔
42
                {
2✔
43
                    int sourceFactoryId = import.Key;
2✔
44
                    ImportedItem importedItem = import.Value;
2✔
45
                    
46
                    // Find the source factory
47
                    Factory? sourceFactory = Factories.FirstOrDefault(f => f.Id == sourceFactoryId);
4✔
48
                    if (sourceFactory == null)
2!
NEW
49
                    {
×
50
                        // Source factory not found
UNCOV
51
                        importedItem.PartQuantityImported = 0;
×
UNCOV
52
                        continue;
×
53
                    }
54

55
                    // Find the matching exported item
56
                    ExportedItem? exportedItem = sourceFactory.ExportedParts
2✔
57
                        .FirstOrDefault(e => e.Item.Name == importedItem.Item.Name);
4✔
58
                    
59
                    if (exportedItem == null)
2!
NEW
60
                    {
×
61
                        // Source factory doesn't export this item
NEW
62
                        importedItem.PartQuantityImported = 0;
×
UNCOV
63
                        continue;
×
64
                    }
65

66
                    double requestedQuantity = importedItem.Item.Quantity;
2✔
67
                    double availableQuantity = exportedItem.PartQuantityExported;
2✔
68

69
                    if (availableQuantity >= requestedQuantity)
2✔
70
                    {
1✔
71
                        // Full allocation possible
72
                        exportedItem.PartQuantityExported -= requestedQuantity;
1✔
73
                        importedItem.PartQuantityImported = requestedQuantity;
1✔
74
                    }
1✔
75
                    else if (availableQuantity > 0)
1!
76
                    {
1✔
77
                        // Partial allocation possible
78
                        importedItem.PartQuantityImported = availableQuantity;
1✔
79
                        exportedItem.PartQuantityExported = 0;
1✔
80
                    }
1✔
81
                    else
NEW
82
                    {
×
83
                        // No quantity available
UNCOV
84
                        importedItem.PartQuantityImported = 0;
×
UNCOV
85
                    }
×
86
                }
2✔
87
            }
4✔
88

89
            // Update the final PartQuantityExported to reflect what was actually used
90
            foreach (Factory factory in Factories)
14✔
91
            {
4✔
92
                foreach (ExportedItem exportedItem in factory.ExportedParts)
20✔
93
                {
4✔
94
                    // PartQuantityExported now represents what was actually exported (allocated)
95
                    double originalProduction = exportedItem.Item.Quantity;
4✔
96
                    double remainingQuantity = exportedItem.PartQuantityExported;
4✔
97
                    exportedItem.PartQuantityExported = originalProduction - remainingQuantity;
4✔
98
                }
4✔
99
            }
4✔
100
        }
2✔
101

102
    }
103
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc