excel_writer_18.0.0_ae0dcf49/test/ew_test.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
with Excel_Out;

with Ada.Strings.Fixed;

procedure EW_Test is

  use Excel_Out;

  procedure Test_def_col_width (ef : Excel_type) is
    xl : Excel_Out_File;
  begin
    xl.Create ("With def col width [" & Excel_type'Image (ef) & "].xls", ef);
    xl.Write_default_column_width (20);
    xl.Write_column_width (1, 5);
    xl.Write_column_width (5, 10, 4);
    xl.Put ("A");
    xl.Put ("B");
    xl.Close;
    --
    xl.Create ("Without def col width [" & Excel_type'Image (ef) & "].xls", ef);
    xl.Write_column_width (1, 5);
    xl.Write_column_width (5, 10, 4);
    xl.Put ("A");
    xl.Put ("B");
    xl.Close;
  end Test_def_col_width;

  --  Test automatic choice for integer output
  --
  procedure Test_General (ef : Excel_type) is
    use Ada.Strings, Ada.Strings.Fixed;
    xl : Excel_Out_File;
  begin
    xl.Create ("Integer [" & Excel_type'Image (ef) & "].xls", ef);
    xl.Freeze_Top_Row;
    xl.Put ("x");
    xl.Next;
    xl.Put  ("2.0**x");
    xl.Put ("-2.0**x");
    xl.Put  ("2.0**x - 1");
    xl.Next;
    xl.Put  ("2**x");
    xl.Put ("-2**x");
    xl.Put  ("2**x - 1");
    xl.Next;
    xl.Put_Line
      ("Formulas for checking (all results should be 0). " &
       " NB: the formulas are written as text." &
       " Edit cells to convert them into real formulas.");
    for power in 0 .. 66 loop
      xl.Put (power);
      xl.Next;
      xl.Put   (2.0 ** power);
      xl.Put (-(2.0 ** power));
      xl.Put  ((2.0 ** power) - 1.0);
      xl.Next;
      if power <= 30 then
        xl.Put   (2 ** power);
        xl.Put (-(2 ** power));
        xl.Put  ((2 ** power) - 1);
      else
        xl.Next (3);
      end if;
      xl.Next;
      declare
        row : constant String := Trim (Integer'Image (power + 2), Both);
      begin
        xl.Put ("= (2^A" & row & ")     - C" & row);
        xl.Put ("=-(2^A" & row & ")     - D" & row);
        xl.Put ("= (2^A" & row & ") - 1 - E" & row);
        xl.Next;
        if power <= 30 then
          xl.Put ("= (2^A" & row & ")     - G" & row);
          xl.Put ("=-(2^A" & row & ")     - H" & row);
          xl.Put ("= (2^A" & row & ") - 1 - I" & row);
        end if;
      end;
      xl.New_Line;
    end loop;
    xl.Close;
  end Test_General;

begin
  for ef in Excel_type loop
    Test_def_col_width (ef);
    Test_General (ef);
  end loop;
end EW_Test;