generator: verified

This commit is contained in:
Ilia Denisov
2025-09-13 02:13:44 +03:00
parent 05999687aa
commit 84578dc61c
6 changed files with 114 additions and 54 deletions
+3 -4
View File
@@ -39,9 +39,6 @@ func NewBitmapPlotter(bm bitmap.Bitmap, factor float32) (Plotter, error) {
}
func (p Plotter) RandomFreePoint(deadZoneRaduis float32) (float32, float32, error) {
if deadZoneRaduis <= 0. {
return 0, 0, fmt.Errorf("radius must be positive value: %f", deadZoneRaduis)
}
fsCount := p.freeCountFn()
if fsCount == 0 {
return 0, 0, errors.New("RandomFreePoint: no free space left")
@@ -51,7 +48,9 @@ func (p Plotter) RandomFreePoint(deadZoneRaduis float32) (float32, float32, erro
if err != nil {
return 0, 0, fmt.Errorf("RandomFreePoint: freeNumberToCoordFn: %s", err)
}
p.plotDeadZone(x, y, deadZoneRaduis)
if deadZoneRaduis > 0 {
p.plotDeadZone(x, y, deadZoneRaduis)
}
planetX := float32(x)*p.factor + rand.Float32()*p.factor
planetY := float32(y)*p.factor + rand.Float32()*p.factor
return planetX, planetY, nil
+2 -2
View File
@@ -63,8 +63,8 @@ func TestRandomFreePoint(t *testing.T) {
}
_, _, err = p.RandomFreePoint(0)
if err == nil {
t.Error("expect: error when radius not positive, got: none")
if err != nil {
t.Errorf("expect: no error when radius is zero, got: %s", err)
}
_, _, err = p.RandomFreePoint(float32(w + h)) // guaranteed to mark whole area dead zone