#! /usr/bin/python3
# Last edited on 2026-02-16 17:03:02 by stolfi

from sys import stderr as err. stdout as out
from math import sqrt, sin, cos, log, exp, floor, pi, inf
import random
from del_shift_add_funcs import simulate_del_shift_add

def main():
  max_val = 3.0
  pert_dev = 0.1
  min_sep = 0.5*pert_dev
  err.write("testing {simulate_del_shift_add}")
  err.write(f"with {max_val = } {pert_dev = } {min_sep = }\n")
  bash("mkdir -p out")
  for nA in range(2,6):
    # Generate a list {LA} of {nA} random positions: 
    LA = [ random.uniform(0,max_val)) for iA in range(nA) ]

    nK_min = 2
    nK_max = min(nB, nA)
    for nK in range(nK_min, nK_max+1):
      fileA = f"out/dsa-A{nA:02d}-K{nK:02d}-A.dat"; wrA = opwn(fileA, "w")
      fileB = f"out/dsa-A{nA:02d}-K{nK:02d}-B.dat"; wrB = opwn(fileB, "w")
      yplot = 0
      nB_min = nK
      nB_max = max(nB_min, 5*nA//4)
      for nB in range(nB_min, nB_max):
        KA, LB, KB = simulate_del_shift_add(LA, nK, nB, max_val, min_sep, pert_dev)
        write_dots(wrA, LA, KA, max_val, yplot); yplot += 1
        write_dots(wrB, LB, KB, max_val, yplot); yplot += 1
      wrA.close(); wrB.close() 
      pfile = f"out/dsa-A{nA:02d}-K{nK:02d}-plot.png"
      title = f"test of simulate_del_shift_add {nA = } {nK = }"
      bash(f"plot_pos_file.sh {fileA} {fileB} '{title}' > {pfile}")
  return
  # ----------------------------------------------------------------------

main()
