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
156 lines
4.5 KiB
Go
156 lines
4.5 KiB
Go
package market
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/damirmukimov/city_resource_graph/models/params"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGetMarketSize(t *testing.T) {
|
|
p := ¶ms.Params{
|
|
Market: params.MarketParams{
|
|
TAM: 500000000000.0,
|
|
AddressableDigital: 3000000000.0,
|
|
PilotCityEconomicBenefit: 4000000.0,
|
|
ScalabilityPotential: 400000000.0,
|
|
EUIndustrialFacilities: 2100000,
|
|
EnergyWastePotential: 0.45,
|
|
ResourceCostReduction: 0.25,
|
|
},
|
|
}
|
|
|
|
result, err := GetMarketSize(p)
|
|
assert.NoError(t, err, "Should not return error for valid params")
|
|
|
|
assert.Equal(t, 500000000000.0, result.TAM, "TAM should match")
|
|
assert.Equal(t, 3000000000.0, result.AddressableDigital, "Addressable digital should match")
|
|
assert.Equal(t, 4000000.0, result.PilotCityEconomicBenefit, "Pilot benefit should match")
|
|
assert.Equal(t, 400000000.0, result.ScalabilityPotential, "Scalability potential should match")
|
|
assert.Equal(t, 2100000, result.EUIndustrialFacilities, "EU facilities should match")
|
|
assert.Equal(t, 0.45, result.EnergyWastePotential, "Energy waste potential should match")
|
|
assert.Equal(t, 0.25, result.ResourceCostReduction, "Resource cost reduction should match")
|
|
}
|
|
|
|
func TestGetMarketSize_MissingTAM(t *testing.T) {
|
|
p := ¶ms.Params{
|
|
Market: params.MarketParams{
|
|
// TAM is 0 (missing)
|
|
},
|
|
}
|
|
|
|
_, err := GetMarketSize(p)
|
|
assert.Error(t, err, "Should return error for missing TAM")
|
|
assert.Contains(t, err.Error(), "missing market data", "Error should mention missing data")
|
|
assert.Contains(t, err.Error(), "market.tam", "Error should specify missing field")
|
|
}
|
|
|
|
func TestCalculateSAM(t *testing.T) {
|
|
p := ¶ms.Params{
|
|
Market: params.MarketParams{
|
|
TAM: 500000000000.0,
|
|
ViableExchangeRate: 0.15,
|
|
PlatformCaptureRate: 0.50,
|
|
},
|
|
}
|
|
|
|
result, err := CalculateSAM(p)
|
|
assert.NoError(t, err, "Should not return error for valid params")
|
|
|
|
expected := 500000000000.0 * 0.15 * 0.50 * 2.0 // TAM * viable_rate * capture_rate * 2
|
|
assert.InDelta(t, expected, result, 0.01, "SAM calculation should match expected formula")
|
|
}
|
|
|
|
func TestCalculateSAM_MissingParams(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
market params.MarketParams
|
|
field string
|
|
}{
|
|
{
|
|
name: "missing TAM",
|
|
market: params.MarketParams{ViableExchangeRate: 0.15, PlatformCaptureRate: 0.50},
|
|
field: "market.tam",
|
|
},
|
|
{
|
|
name: "missing viable exchange rate",
|
|
market: params.MarketParams{TAM: 500000000000.0, PlatformCaptureRate: 0.50},
|
|
field: "market.viable_exchange_rate",
|
|
},
|
|
{
|
|
name: "missing platform capture rate",
|
|
market: params.MarketParams{TAM: 500000000000.0, ViableExchangeRate: 0.15},
|
|
field: "market.platform_capture_rate",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
p := ¶ms.Params{Market: tt.market}
|
|
|
|
_, err := CalculateSAM(p)
|
|
assert.Error(t, err, "Should return error for missing params")
|
|
assert.Contains(t, err.Error(), "missing market data", "Error should mention missing data")
|
|
assert.Contains(t, err.Error(), tt.field, "Error should specify missing field")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetSOM(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
year int
|
|
somValue float64
|
|
}{
|
|
{
|
|
name: "Year 1 SOM",
|
|
year: 1,
|
|
somValue: 50000000.0,
|
|
},
|
|
{
|
|
name: "Year 2 SOM",
|
|
year: 2,
|
|
somValue: 300000000.0,
|
|
},
|
|
{
|
|
name: "Year 3 SOM",
|
|
year: 3,
|
|
somValue: 1500000000.0,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
p := ¶ms.Params{
|
|
Market: params.MarketParams{
|
|
SOM: params.YearlyFloat{params.YearKey(tt.year): tt.somValue},
|
|
},
|
|
}
|
|
|
|
result, err := GetSOM(tt.year, p)
|
|
assert.NoError(t, err, "Should not return error for valid SOM")
|
|
assert.InDelta(t, tt.somValue, result, 0.01, "SOM should match expected value")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGetSOM_MissingValue(t *testing.T) {
|
|
p := ¶ms.Params{
|
|
Market: params.MarketParams{
|
|
SOM: params.YearlyFloat{}, // Empty
|
|
},
|
|
}
|
|
|
|
_, err := GetSOM(1, p)
|
|
assert.Error(t, err, "Should return error for missing SOM value")
|
|
assert.Contains(t, err.Error(), "missing market data", "Error should mention missing data")
|
|
assert.Contains(t, err.Error(), "market.som.1", "Error should specify missing field")
|
|
}
|
|
|
|
func TestErrMissingMarketData_Error(t *testing.T) {
|
|
err := ErrMissingMarketData{Field: "test.field"}
|
|
errorMsg := err.Error()
|
|
assert.Contains(t, errorMsg, "missing market data", "Error should mention missing data")
|
|
assert.Contains(t, errorMsg, "test.field", "Error should specify field")
|
|
}
|