summaryrefslogtreecommitdiff
path: root/tests/test/tandorandnot1.pp
blob: 2890f9d202182dde57ab29fc1bbfeabbfcf21b16 (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{ test (a and b) or (c and not(b)) into c xor ((c xor a) and b) optimization with random values }
procedure test_word;
  var
    i,a,b,c,_a,_b,_c : word;
  begin
    for i:=1 to 1000 do
      begin
        a:=random(65536);
        _a:=a;
        b:=random(65536);
        _b:=b;
        c:=random(65536);
        _c:=c;
        if (a and b) or (c and not(b))<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a,'b=',b,'c=',c);
            halt(1);
          end;
        if (a and b) or (not(b) and c)<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a,'b=',b,'c=',c);
            halt(1);
          end;
        if (not(b) and c) or (a and b)<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a,'b=',b,'c=',c);
            halt(1);
          end;
        if (not(b) and c) or (b and a)<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a,'b=',b,'c=',c);
            halt(1);
          end;
      end;
  end;

procedure test_boolean;
  var
    i : word;
    a,b,c,_a,_b,_c : boolean;
  begin
    for i:=1 to 100 do
      begin
        a:=boolean(random(2));
        _a:=a;
        b:=boolean(random(2));
        _b:=b;
        c:=boolean(random(2));
        _c:=c;
        if (a and b) or (c and not(b))<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a,'b=',b,'c=',c);
            halt(11);
          end;
        if (a and b) or (not(b) and c)<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a,'b=',b,'c=',c);
            halt(11);
          end;
        if (not(b) and c) or (a and b)<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a,'b=',b,'c=',c);
            halt(11);
          end;
        if (not(b) and c) or (b and a)<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a,'b=',b,'c=',c);
            halt(11);
          end;
      end;
  end;


procedure test_pboolean;
  var
    i : word;
    a,b,c : pboolean;
    _a,_b,_c : boolean;
  begin
    new(a);
    new(b);
    for i:=1 to 100 do
      begin
        a^:=true;
        _a:=a^;
        b^:=true;
        _b:=b^;
        c:=nil;  
        { c should not matter in this case }      
        _c:=boolean(random(2));
        if (a^ and b^) or (c^ and not(b^))<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a^,'b=',b^,'c=',c^);
            halt(21);
          end;
        if (a^ and b^) or (not(b^) and c^)<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a^,'b=',b^,'c=',c^);
            halt(21);
          end;
        if (not(b^) and c^) or (a^ and b^)<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a^,'b=',b^,'c=',c^);
            halt(21);
          end;
        if (not(b^) and c^) or (b^ and a^)<>_c xor ((_c xor _a) and _b) then
          begin
            writeln('Error: ','a=',a^,'b=',b^,'c=',c^);
            halt(21);
          end;
      end;
    dispose(a);
    dispose(b);
  end;


begin
  test_word;
  test_boolean;
  test_pboolean;
end.