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
85 lines
2.7 KiB
Go
85 lines
2.7 KiB
Go
package cost
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/damirmukimov/city_resource_graph/models/params"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCalculateCosts(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
year int
|
|
expectedEngineering float64
|
|
expectedInfrastructure float64
|
|
expectedMarketing float64
|
|
expectedOperations float64
|
|
expectedTotal float64
|
|
}{
|
|
{
|
|
name: "Year 1 cost calculation",
|
|
year: 1,
|
|
expectedEngineering: 800000.0, // 8 * 100000
|
|
expectedInfrastructure: 200000.0, // 200000
|
|
expectedMarketing: 300000.0, // 300000
|
|
expectedOperations: 100000.0, // 100000
|
|
expectedTotal: 1400000.0,
|
|
},
|
|
{
|
|
name: "Year 2 cost calculation",
|
|
year: 2,
|
|
expectedEngineering: 1200000.0, // 12 * 100000
|
|
expectedInfrastructure: 250000.0, // 250000
|
|
expectedMarketing: 600000.0, // 600000
|
|
expectedOperations: 150000.0, // 150000
|
|
expectedTotal: 2200000.0,
|
|
},
|
|
{
|
|
name: "Year 3 cost calculation",
|
|
year: 3,
|
|
expectedEngineering: 1500000.0, // 15 * 100000
|
|
expectedInfrastructure: 400000.0, // 400000
|
|
expectedMarketing: 900000.0, // 900000
|
|
expectedOperations: 200000.0, // 200000
|
|
expectedTotal: 3000000.0,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
p := createTestParams(tt.year)
|
|
|
|
result := CalculateCosts(tt.year, p)
|
|
|
|
assert.InDelta(t, tt.expectedEngineering, result.Engineering, 0.01, "Engineering costs should match")
|
|
assert.InDelta(t, tt.expectedInfrastructure, result.Infrastructure, 0.01, "Infrastructure costs should match")
|
|
assert.InDelta(t, tt.expectedMarketing, result.MarketingSales, 0.01, "Marketing costs should match")
|
|
assert.InDelta(t, tt.expectedOperations, result.Operations, 0.01, "Operations costs should match")
|
|
assert.InDelta(t, tt.expectedTotal, result.Total, 0.01, "Total costs should match")
|
|
})
|
|
}
|
|
}
|
|
|
|
func createTestParams(year int) *params.Params {
|
|
yearKey := params.YearKey(year)
|
|
|
|
// Use actual values from params.yaml
|
|
engineers := []int{8, 12, 15}
|
|
infrastructure := []float64{200000, 250000, 400000}
|
|
marketing := []float64{300000, 600000, 900000}
|
|
operations := []float64{100000, 150000, 200000}
|
|
|
|
idx := year - 1
|
|
|
|
return ¶ms.Params{
|
|
Costs: params.CostParams{
|
|
Engineers: params.YearlyInt{yearKey: engineers[idx]},
|
|
EngineerSalary: 100000.0,
|
|
Infrastructure: params.YearlyFloat{yearKey: infrastructure[idx]},
|
|
MarketingSales: params.YearlyFloat{yearKey: marketing[idx]},
|
|
Operations: params.YearlyFloat{yearKey: operations[idx]},
|
|
},
|
|
}
|
|
}
|