package calc_test

import (
	"math"
	"testing"

	"galaxy/calc"
)

func TestShipBuildCost(t *testing.T) {
	cases := []struct {
		name      string
		shipMass  float64
		material  float64
		resources float64
		want      float64
	}{
		{
			name:      "material exceeds mass: no farming needed",
			shipMass:  5,
			material:  10,
			resources: 0.5,
			want:      50, // ShipProductionCost(5) = 50; matFarm = 0.
		},
		{
			name:      "material equal to mass: no farming needed",
			shipMass:  5,
			material:  5,
			resources: 0.5,
			want:      50,
		},
		{
			name:      "material short of mass: farming term added",
			shipMass:  10,
			material:  3,
			resources: 0.5,
			want:      114, // 100 + (7 / 0.5).
		},
		{
			name:      "no material at all: full mass farmed",
			shipMass:  4,
			material:  0,
			resources: 0.5,
			want:      48, // 40 + (4 / 0.5).
		},
		{
			name:      "zero resources collapses farming term to zero",
			shipMass:  10,
			material:  3,
			resources: 0,
			want:      100, // 100 + 0; resources == 0 is a pathological guard.
		},
	}
	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			got := calc.ShipBuildCost(tc.shipMass, tc.material, tc.resources)
			if math.Abs(got-tc.want) > 1e-9 {
				t.Errorf("ShipBuildCost(%v, %v, %v) = %v, want %v",
					tc.shipMass, tc.material, tc.resources, got, tc.want)
			}
		})
	}
}
