uses
  dpolynomialf;

function R(B: Boolean): AnsiString;
begin
  if B then begin
    Result := 'PASSED';
  end else
    Result := 'FAILED';
end;

function E(A, B: Single): Boolean;
begin
  Result := Abs(A - B) <= 1e-6;
end;

function Test3(A, X1, X2, X3: Single): Boolean;
var
  B, C, D: Single;
  X: array[0 .. 3] of Single;
  N: LongInt;
begin
  Result := True;
  Write(A:6:6, ' * (X - ', X1:6:6, ') * (X - ', X2:6:6, ') * (X - ', X3:6:6, ') = ');
  B := - A * (X1 + X2 + X3);
  C :=   A * (X1 * X2 + X1 * X3 + X2 * X3);
  D := - A * (X1 * X2 * X3);
  Writeln(A:6:6, '* X^3 + (', B:6:6, ') * X^2 + (', C:6:6, ') * X + (', D:6:6, ')');
  N := SolveCubicEquation(A, B, C, D, @X[0]);
  if N <> 3 then begin
    Writeln('WARNING: not enough roots: ', N, ', expected 3');
    Result := False;
  end;
  if not (E(X1, X[0]) or E(X1, X[1]) or E(X1, X[2])) then
    Result := False;
  if not (E(X2, X[0]) or E(X2, X[1]) or E(X2, X[2])) then
    Result := False;
  if not (E(X3, X[0]) or E(X3, X[1]) or E(X3, X[2])) then
    Result := False;
  Writeln('  Roots (', N, '): ', X[0]:6:6, ' ', X[1]:6:6, ' ', X[2]:6:6, ' ', R(Result), '');
end;

begin
  Test3(1, 1, 2, 3);
  Test3(2, 4, -3, 1);
end.
