mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
Repository Structure:
- Move files from cluttered root directory into organized structure
- Create archive/ for archived data and scraper results
- Create bugulma/ for the complete application (frontend + backend)
- Create data/ for sample datasets and reference materials
- Create docs/ for comprehensive documentation structure
- Create scripts/ for utility scripts and API tools
Backend Implementation:
- Implement 3 missing backend endpoints identified in gap analysis:
* GET /api/v1/organizations/{id}/matching/direct - Direct symbiosis matches
* GET /api/v1/users/me/organizations - User organizations
* POST /api/v1/proposals/{id}/status - Update proposal status
- Add complete proposal domain model, repository, and service layers
- Create database migration for proposals table
- Fix CLI server command registration issue
API Documentation:
- Add comprehensive proposals.md API documentation
- Update README.md with Users and Proposals API sections
- Document all request/response formats, error codes, and business rules
Code Quality:
- Follow existing Go backend architecture patterns
- Add proper error handling and validation
- Match frontend expected response schemas
- Maintain clean separation of concerns (handler -> service -> repository)
154 lines
4.0 KiB
Go
154 lines
4.0 KiB
Go
package financial
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSensitivityAnalyzer_AnalyzeSensitivity(t *testing.T) {
|
|
config := DefaultConfig()
|
|
npvCalc := NewNPVCalculator()
|
|
sa := NewSensitivityAnalyzer(config, npvCalc)
|
|
|
|
basic := &EconomicAnalysis{
|
|
NPV: 100000.0,
|
|
AnnualSavings: 15000.0,
|
|
CapexRequired: 50000.0,
|
|
OpexPerYear: 2000.0,
|
|
}
|
|
|
|
assumptions := &EconomicAssumptions{
|
|
DiscountRate: 0.08,
|
|
ProjectLifeYears: 10,
|
|
}
|
|
|
|
scenarios := sa.AnalyzeSensitivity(basic, assumptions)
|
|
|
|
// Should have scenarios for: discount_rate (-20%, -10%, +10%, +20%),
|
|
// capex (-20%, -10%, +10%, +20%), annual_savings (-20%, -10%, +10%, +20%),
|
|
// opex (-20%, -10%, +10%, +20%), project_life (-20%, +20%),
|
|
// co2_price (-50%, +50%, +100%)
|
|
expectedCount := 4 + 4 + 4 + 4 + 2 + 3 // 21 scenarios
|
|
if len(scenarios) != expectedCount {
|
|
t.Errorf("AnalyzeSensitivity() returned %d scenarios, want %d", len(scenarios), expectedCount)
|
|
}
|
|
|
|
// Check that scenarios have proper structure
|
|
for i, scenario := range scenarios {
|
|
if scenario.VariableName == "" {
|
|
t.Errorf("Scenario %d: VariableName is empty", i)
|
|
}
|
|
if scenario.BaseValue <= 0 {
|
|
t.Errorf("Scenario %d: BaseValue is not positive: %v", i, scenario.BaseValue)
|
|
}
|
|
if scenario.RiskLevel == "" {
|
|
t.Errorf("Scenario %d: RiskLevel is empty", i)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSensitivityAnalyzer_CalculateRiskLevel(t *testing.T) {
|
|
config := DefaultConfig()
|
|
npvCalc := NewNPVCalculator()
|
|
sa := NewSensitivityAnalyzer(config, npvCalc)
|
|
|
|
tests := []struct {
|
|
name string
|
|
impact float64
|
|
expected string
|
|
}{
|
|
{"Low impact", 0.05, "low"}, // < 0.3
|
|
{"Medium impact", 0.45, "medium"}, // 0.3-0.6
|
|
{"High impact", 0.7, "high"}, // 0.6-0.8
|
|
{"Critical impact", 0.9, "critical"}, // > 0.8
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
impl := sa.(*SensitivityAnalyzerImpl)
|
|
result := impl.calculateRiskLevel(tt.impact)
|
|
|
|
if result != tt.expected {
|
|
t.Errorf("calculateRiskLevel(%v) = %v, want %v", tt.impact, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSensitivityAnalyzer_DiscountRateSensitivity(t *testing.T) {
|
|
config := DefaultConfig()
|
|
npvCalc := NewNPVCalculator()
|
|
sa := NewSensitivityAnalyzer(config, npvCalc)
|
|
|
|
basic := &EconomicAnalysis{
|
|
NPV: 100000.0,
|
|
AnnualSavings: 15000.0,
|
|
CapexRequired: 50000.0,
|
|
OpexPerYear: 2000.0,
|
|
}
|
|
|
|
assumptions := &EconomicAssumptions{
|
|
DiscountRate: 0.08,
|
|
ProjectLifeYears: 10,
|
|
}
|
|
|
|
scenarios := sa.AnalyzeSensitivity(basic, assumptions)
|
|
|
|
// Find discount rate scenarios
|
|
var discountScenarios []SensitivityScenario
|
|
for _, scenario := range scenarios {
|
|
if scenario.VariableName == "discount_rate" {
|
|
discountScenarios = append(discountScenarios, scenario)
|
|
}
|
|
}
|
|
|
|
if len(discountScenarios) != 4 {
|
|
t.Errorf("Expected 4 discount rate scenarios, got %d", len(discountScenarios))
|
|
}
|
|
|
|
// Check that base value matches assumptions
|
|
for _, scenario := range discountScenarios {
|
|
if scenario.BaseValue != 0.08 {
|
|
t.Errorf("Discount rate scenario base value = %v, want 0.08", scenario.BaseValue)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSensitivityAnalyzer_CO2PriceSensitivity(t *testing.T) {
|
|
config := DefaultConfig()
|
|
npvCalc := NewNPVCalculator()
|
|
sa := NewSensitivityAnalyzer(config, npvCalc)
|
|
|
|
basic := &EconomicAnalysis{
|
|
NPV: 100000.0,
|
|
AnnualSavings: 15000.0,
|
|
CapexRequired: 50000.0,
|
|
OpexPerYear: 2000.0,
|
|
}
|
|
|
|
assumptions := &EconomicAssumptions{
|
|
DiscountRate: 0.08,
|
|
ProjectLifeYears: 10,
|
|
}
|
|
|
|
scenarios := sa.AnalyzeSensitivity(basic, assumptions)
|
|
|
|
// Find CO2 price scenarios
|
|
var co2Scenarios []SensitivityScenario
|
|
for _, scenario := range scenarios {
|
|
if scenario.VariableName == "co2_price" {
|
|
co2Scenarios = append(co2Scenarios, scenario)
|
|
}
|
|
}
|
|
|
|
if len(co2Scenarios) != 3 {
|
|
t.Errorf("Expected 3 CO2 price scenarios, got %d", len(co2Scenarios))
|
|
}
|
|
|
|
// Check that base value is €25/tonne
|
|
for _, scenario := range co2Scenarios {
|
|
if scenario.BaseValue != 25.0 {
|
|
t.Errorf("CO2 price scenario base value = %v, want 25.0", scenario.BaseValue)
|
|
}
|
|
}
|
|
}
|