mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- Initialize git repository - Add comprehensive .gitignore for Go projects - Install golangci-lint v2.6.0 (latest v2) globally - Configure .golangci.yml with appropriate linters and formatters - Fix all formatting issues (gofmt) - Fix all errcheck issues (unchecked errors) - Adjust complexity threshold for validation functions - All checks passing: build, test, vet, lint
81 lines
2.3 KiB
Go
81 lines
2.3 KiB
Go
package impact
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/damirmukimov/city_resource_graph/models/customer"
|
|
"github.com/damirmukimov/city_resource_graph/models/params"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCalculateImpact(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
year int
|
|
custMetrics customer.CustomerMetrics
|
|
expectedCO2 float64
|
|
expectedWater float64
|
|
expectedWaste float64
|
|
}{
|
|
{
|
|
name: "Year 1 impact calculation",
|
|
year: 1,
|
|
custMetrics: customer.CustomerMetrics{
|
|
TotalOrgs: 500,
|
|
},
|
|
expectedCO2: 94500.0, // 500000 * 0.3 * 0.9 * 0.7
|
|
expectedWater: 2500000.0, // 500 * 25000 * 0.20
|
|
expectedWaste: 7500.0, // 500 * 100 * 0.15
|
|
},
|
|
{
|
|
name: "Year 2 impact calculation",
|
|
year: 2,
|
|
custMetrics: customer.CustomerMetrics{
|
|
TotalOrgs: 2000,
|
|
},
|
|
expectedCO2: 283500.0, // 1500000 * 0.3 * 0.9 * 0.7
|
|
expectedWater: 12500000.0, // 2000 * 25000 * 0.25
|
|
expectedWaste: 50000.0, // 2000 * 100 * 0.25
|
|
},
|
|
{
|
|
name: "Year 3 impact calculation",
|
|
year: 3,
|
|
custMetrics: customer.CustomerMetrics{
|
|
TotalOrgs: 5000,
|
|
},
|
|
expectedCO2: 472500.0, // 2500000 * 0.3 * 0.9 * 0.7 = 472500
|
|
expectedWater: 37500000.0, // 5000 * 25000 * 0.30
|
|
expectedWaste: 175000.0, // 5000 * 100 * 0.35
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
p := createTestParams(tt.year)
|
|
|
|
result := CalculateImpact(tt.year, tt.custMetrics, p)
|
|
|
|
assert.InDelta(t, tt.expectedCO2, result.CO2Avoided, 0.01, "CO2 avoided should match")
|
|
assert.InDelta(t, tt.expectedWater, result.WaterReused, 0.01, "Water reused should match")
|
|
assert.InDelta(t, tt.expectedWaste, result.WasteDiverted, 0.01, "Waste diverted should match")
|
|
})
|
|
}
|
|
}
|
|
|
|
func createTestParams(year int) *params.Params {
|
|
yearKey := params.YearKey(year)
|
|
|
|
return ¶ms.Params{
|
|
Impact: params.ImpactParams{
|
|
HeatMWh: params.YearlyFloat{yearKey: float64(500000 + (year-1)*1000000)}, // 500k, 1.5M, 3M
|
|
GridFactor: 0.3,
|
|
HXEff: 0.9,
|
|
Utilization: 0.7,
|
|
WaterPerOrg: 25000.0,
|
|
WaterReuseRate: params.YearlyFloat{yearKey: 0.20 + float64(year-1)*0.05}, // 0.20, 0.25, 0.30
|
|
WastePerOrg: 100.0,
|
|
WasteDiversionRate: params.YearlyFloat{yearKey: 0.15 + float64(year-1)*0.10}, // 0.15, 0.25, 0.35
|
|
},
|
|
}
|
|
}
|