spreadlab/internal/engine/forwardchance_test.go
Justin Visser c1201caf11 engine: tune the default world to a soft program
DefaultConfig now describes a more realistic world: a moderately novel fake
(novelty 0.3), some ambient harm awareness (0.2), and a strong but imperfect
education program (programEffect 0.8) so educated students mostly, not always,
refuse. The headline shifts from 99/70/7 (a perfect program) to 100/83/21 out
of 120 (83/69/18 percent): no program >> random >> most-connected still holds,
targeting still wins by ~4x, but the program is no longer a perfect wall.
Golden values re-pinned in the engine and API tests; the preset base matches.
The forward-chance formula test now neutralises its baseline so it pins the
formula, not the tuned defaults.
2026-06-18 22:19:44 +02:00

73 lines
2.4 KiB
Go

package engine
import "testing"
// ForwardChance is the additive composite the whole model rests on. These
// pin the formula's shape (which lever pushes which way, the clamp, and how
// the program scales an educated student) in terms of the weight constants,
// so tuning the weights later does not silently break the relationships.
func TestForwardChance(t *testing.T) {
// A neutral baseline (the tuned DefaultConfig now carries novelty, harm
// awareness and a soft program); these assertions pin the formula's
// shape, not the default values.
base := DefaultConfig()
base.Novelty = 0
base.HarmAwareness = 0
base.ProgramEffect = 1
t.Run("default not educated is the baseline", func(t *testing.T) {
if got := base.ForwardChance(false); got != base.ForwardProb {
t.Errorf("ForwardChance(false) = %v, want baseline %v", got, base.ForwardProb)
}
})
t.Run("default educated never forwards under a full program", func(t *testing.T) {
if got := base.ForwardChance(true); got != 0 {
t.Errorf("ForwardChance(true) = %v, want 0 (programEffect 1)", got)
}
})
t.Run("novelty raises forwarding", func(t *testing.T) {
config := base
config.Novelty = 1
want := base.ForwardProb + noveltyWeight
if got := config.ForwardChance(false); got != want {
t.Errorf("ForwardChance = %v, want %v", got, want)
}
})
t.Run("harm awareness lowers forwarding", func(t *testing.T) {
config := base
config.HarmAwareness = 0.5
want := base.ForwardProb - harmAwarenessWeight*0.5
if got := config.ForwardChance(false); got != want {
t.Errorf("ForwardChance = %v, want %v", got, want)
}
})
t.Run("clamps to zero", func(t *testing.T) {
config := base
config.HarmAwareness = 1 // 0.38 - 0.40 < 0
if got := config.ForwardChance(false); got != 0 {
t.Errorf("ForwardChance = %v, want clamped 0", got)
}
})
t.Run("clamps to the ceiling", func(t *testing.T) {
config := base
config.ForwardProb = 0.9
config.Novelty = 1 // 0.9 + 0.30 > 0.95
if got := config.ForwardChance(false); got != maxForwardChance {
t.Errorf("ForwardChance = %v, want clamped %v", got, maxForwardChance)
}
})
t.Run("a softer program leaves some forwarding", func(t *testing.T) {
config := base
config.ProgramEffect = 0.5
want := base.ForwardProb * 0.5
if got := config.ForwardChance(true); got != want {
t.Errorf("ForwardChance(true) = %v, want %v", got, want)
}
})
}