source: doc/theses/jiada_liang_MMath/test.adb@ 28182444

Last change on this file since 28182444 was 7568e5c, checked in by JiadaL <j82liang@…>, 13 months ago

Minor update on the thesis (add auto initialization and update future work

  • Property mode set to 100644
File size: 2.9 KB
Line 
1with Ada.Text_IO; use Ada.Text_IO;
2-- with Ada.Standard; use Ada.Standard;
3procedure test is
4 type GBR is ( Green, Blue, Red );
5 type RGB is ( Red, Green, Blue );
6 for RGB use ( Red => 10, Green => 20, Blue => 21 );
7 Colour : RGB := Red;
8
9 type ABC is ('A', 'B', 'C');
10 Chars : ABC := 'C';
11
12 type Operator is ( '+', '-', '*', '/' );
13 for Operator use ( '+' => 10, '-' => 20, '*' => 30, '/' => 40 );
14 op : Operator := '+';
15 Ops : array( 0..3) of Operator;
16
17 type Week is ( Mon, Tue, Wed, Thu, Fri, Sat, Sun );
18 for Week use ( Mon => 0, Tue => 1, Wed => 2, Thu => 10, Fri => 11, Sat => 14, Sun => 15 );
19 subtype Weekday is Week range Mon .. Fri;
20 subtype Weekend is Week range Sat .. Sun;
21 Day : Week;
22 Lunch : array( Week ) of Integer;
23
24-- type Boolean is ( False, True );
25 B : Boolean := True;
26begin
27 Put_Line( Integer'Image( RGB'Pos( Colour ) ) & " " & RGB'Image( RGB'Val(0) ) );
28 Put_Line( Integer'Image( RGB'Enum_Rep( Colour ) ) & " " & RGB'Image( RGB'Enum_Val( 10 ) ) );
29 Put_Line( """" & RGB'Image( Colour ) & """ " & RGB'Image( RGB'Value( "Red" ) ) );
30
31
32 Put_Line( RGB'Image( Colour ) & Integer'Image( RGB'Pos( Colour ) ) & Integer'Image( RGB'Enum_Rep( Colour ) ) );
33 Put_Line( RGB'Image( Colour ) & Integer'Image( RGB'Pos( Colour ) ) & Integer'Image( RGB'Enum_Rep( Colour ) ) );
34
35 for op in RGB loop
36 Put( "(" & Integer'Image( RGB'Pos( op ) ) & Integer'Image( RGB'Enum_Rep( op ) ) & ' ' & RGB'Image( op ) & ") " );
37 end loop;
38 Put_Line( "" );
39
40 Put_Line( ABC'Image( Chars ) );
41 Put_Line( Integer'Image( ABC'Pos( Chars ) ) );
42
43 Op := '+';
44 if Op = '+' or else Op = '-' then null;
45 elsif Op = '*' or else Op = '/' then null; end if;
46
47 case Op is
48 when '+' => null;
49 when '-' => null;
50 when '*' => null;
51-- when '/' => null;
52 when others => null;
53 end case;
54 for op in Operator loop
55 Put( "(" & Integer'Image( Operator'Pos( op ) ) & Integer'Image( Operator'Enum_Rep( op ) ) & ' ' & Operator'Image( op ) & ") " );
56 end loop;
57 Put_Line( "" );
58
59 Ops := "+-*/";
60 Ops := "+-" & "*/";
61 for Op of Ops loop
62 Put_Line( Operator'Image( Op ) );
63 end loop;
64 Day := Wed;
65 case Day is
66 when Mon .. Fri => null;
67 when Sat .. Sun => null;
68 end case;
69 case Day is
70 when Weekday => null;
71 when Weekend => null;
72 end case;
73 for Day in Mon .. Sun loop
74 Put( Week'Image( Day ) & " " );
75 end loop;
76 Put_Line( "" );
77 for Day in Week loop
78 Put( Week'Image( Day ) & " " );
79 end loop;
80 Put_Line( "" );
81 for Day in Weekday loop
82 Put( Week'Image( Day ) & " " );
83 end loop;
84 Put_Line( "" );
85 for Day in Weekend loop
86 Put( Week'Image( Day ) & " " );
87 end loop;
88 Put_Line( "" );
89
90 for Day in Week loop
91 Lunch( Day ) := 3;
92 end loop;
93 for Day in Week loop
94 Put( Integer'Image( Lunch(Day ) ) & " " );
95 end loop;
96
97 if B then null; end if;
98
99 B := False;
100 Colour := Green;
101
102 Put_Line ( Boolean'Image( B ) & " " );
103 Put_Line ( RGB'Image( RGB'Enum_Val( 10 ) ) & " " );
104end test;
105
106-- Local Variables: --
107-- tab-width: 4 --
108-- compile-command: "gnatmake test.adb" --
109-- End: --
Note: See TracBrowser for help on using the repository browser.