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)
95 lines
2.2 KiB
Go
95 lines
2.2 KiB
Go
package financial
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestCO2Calculator_CalculateCO2Reduction(t *testing.T) {
|
|
config := DefaultConfig()
|
|
cc := NewCO2Calculator(config)
|
|
|
|
tests := []struct {
|
|
name string
|
|
resourceType string
|
|
annualVolume float64
|
|
expectedMin float64
|
|
expectedMax float64
|
|
}{
|
|
{
|
|
name: "Heat energy",
|
|
resourceType: "heat",
|
|
annualVolume: 1000.0,
|
|
expectedMin: 189.0, // 1000 MWh * 0.3 t/MWh * 0.9 efficiency * 0.7 utilization
|
|
expectedMax: 191.0,
|
|
},
|
|
{
|
|
name: "Steam energy",
|
|
resourceType: "steam",
|
|
annualVolume: 1000.0,
|
|
expectedMin: 189.0,
|
|
expectedMax: 191.0,
|
|
},
|
|
{
|
|
name: "Water treatment",
|
|
resourceType: "water",
|
|
annualVolume: 1000000.0, // 1 million liters
|
|
expectedMin: 300.0, // 1M liters * 1 kWh/m³ * 0.3 t/MWh / 1000
|
|
expectedMax: 310.0,
|
|
},
|
|
{
|
|
name: "Biowaste",
|
|
resourceType: "biowaste",
|
|
annualVolume: 1000.0, // 1000 tonnes
|
|
expectedMin: 500.0, // 1000 tonnes * 0.5 t CO2/tonne
|
|
expectedMax: 510.0,
|
|
},
|
|
{
|
|
name: "Cooling",
|
|
resourceType: "cooling",
|
|
annualVolume: 1000.0,
|
|
expectedMin: 189.0,
|
|
expectedMax: 191.0,
|
|
},
|
|
{
|
|
name: "Unknown resource",
|
|
resourceType: "unknown",
|
|
annualVolume: 1000.0,
|
|
expectedMin: 0.0,
|
|
expectedMax: 0.1,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := cc.CalculateCO2Reduction(tt.resourceType, tt.annualVolume)
|
|
|
|
if result < tt.expectedMin || result > tt.expectedMax {
|
|
t.Errorf("CalculateCO2Reduction(%s, %v) = %v, expected between %v and %v",
|
|
tt.resourceType, tt.annualVolume, result, tt.expectedMin, tt.expectedMax)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCO2Calculator_ZeroVolume(t *testing.T) {
|
|
config := DefaultConfig()
|
|
cc := NewCO2Calculator(config)
|
|
|
|
result := cc.CalculateCO2Reduction("heat", 0.0)
|
|
|
|
if result != 0.0 {
|
|
t.Errorf("CalculateCO2Reduction with zero volume = %v, want 0.0", result)
|
|
}
|
|
}
|
|
|
|
func TestCO2Calculator_NegativeVolume(t *testing.T) {
|
|
config := DefaultConfig()
|
|
cc := NewCO2Calculator(config)
|
|
|
|
result := cc.CalculateCO2Reduction("heat", -1000.0)
|
|
|
|
if result != 0.0 {
|
|
t.Errorf("CalculateCO2Reduction with negative volume = %v, want 0.0", result)
|
|
}
|
|
}
|