
list tests
# test1
 test2
# test3
end

macro test1
 $PASS = 1
 break -auto off

 create x -10 10 0.1
 set y = 5 * exp(-0.5*x^2/3^2)

 $C0 = 0.5
 $C1 = 2
 $C2 = 10
 $C3 = 1
 set dy = sqrt(y)

 vgauss -q x y dy yfit

 if (abs($C0 - 0.0) > 0.01)
   $PASS = 0
 end
 if (abs($C1 - 3.0) > 0.01)
   $PASS = 0
 end
 if (abs($C2 - 5.0) > 0.01)
   $PASS = 0
 end
 if (abs($C3 - 0.0) > 0.01)
   $PASS = 0
 end
end

# noise of 0.1
macro test2
 $PASS = 1
 break -auto off

 create x 0 1000 1
 set y = 1000 * (x-200)^2 * exp(-0.5*(x-300)^2/30^2)
 set dy = (rnd(y) - 0.5)/0.5
 set y = y + dy

 lim x y; clear; box; plot -x 1 -c black x y

 $C0 = 250
 $C1 = 25
 $C2 = 900
 $C3 = 1
 $C4 = 190

 vmaxwell x y dy yfit
 plot x yfit -c red

 if (abs($C0 - 0.0) > 0.01)
   $PASS = 0
 end
 if (abs($C1 - 3.0) > 0.01)
   $PASS = 0
 end
 if (abs($C2 - 1000.0) > 0.1)
   $PASS = 0
 end
 if (abs($C3 - 0.0) > 0.1)
   $PASS = 0
 end
end

# poisson-distributed noise
macro test3
 $PASS = 1
 break -auto off

 create x -10 10 0.1
 set y = 1000 * exp(-0.5*x^2/3^2)

 gaussdev dY y[] 0.0 1.0
 set dy = dY * sqrt(y)
 set y = y + dy

 $C0 = 0.5
 $C1 = 2
 $C2 = 900
 $C3 = 1

 vgauss -q x y dy yfit

 if (abs($C0 - 0.0) > 0.01)
   $PASS = 0
 end
 if (abs($C1 - 3.0) > 0.01)
   $PASS = 0
 end
 if (abs($C2 - 1000.0) > 1)
   $PASS = 0
 end
 if (abs($C3 - 0.0) > 0.2)
   $PASS = 0
 end
end
