File: tcase1.pp

package info (click to toggle)
fpc 2.6.4%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 178,760 kB
  • ctags: 83,946
  • sloc: pascal: 2,000,374; xml: 138,807; ansic: 9,617; asm: 7,843; yacc: 3,747; php: 3,271; sh: 2,626; makefile: 2,610; lex: 2,537; sql: 267; cpp: 145; sed: 132; perl: 126; csh: 34; tcl: 7
file content (56 lines) | stat: -rw-r--r-- 1,150 bytes parent folder | download | duplicates (13)
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
program test_case;
function case1(Val : byte) : char;
begin
  case Val of
    0..25 : case1:=chr(Val + ord('A'));
    26..51: case1:=chr(Val + ord('a') - 26);
    52..61: case1:=chr(Val + ord('0') - 52);
    62    : case1:='+';
    63    : case1:='/';
  else
    case1:='$';
  end;
end;

function case2(Val : integer) : integer;
begin
  case Val of
    -1      : case2:=1;
    32765..
    32767   : case2:=2;
  else
    case2:=-1;
  end;
end;

function case3(Val : integer) : integer;
begin
  case Val of
    -32768..
    -32766 : case3:=1;
    0..10  : case3:=2;
  else
    case3:=-1;
  end;
end;

var
  error: boolean;

begin
  { The correct outputs should be:
    F $
    2 2
    1 2 2
  }
  error := false;
  writeln(case1(5), ' ', case1(255),' (should be: F $)');
  error := (case1(5) <> 'F') or (case1(255) <> '$');
  writeln(case2(32765), ' ', case2(32767),' (should be: 2 2)');
  error := error or (case2(32765) <> 2) or (case2(32767) <> 2);
  writeln(case3(-32768),' ',case3(0), ' ',case3(5),' (should be: 1 2 2)');
  error := error or (case3(-32768) <> 1) or (case3(0) <> 2) or
           (case3(5) <> 2);
  if error then
    halt(1);
end.