summaryrefslogtreecommitdiff
path: root/Test/dafny0/Trait/TraitOverride1.dfy
blob: d0d164015928da873f92016f6f5a9d483741482c (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

//everything should work OK in this test file
trait T1
{
  function method Plus (x:int, y:int) : int
    requires x>y;
  {
     x + y
  }
  
  function method bb(x:int):int
    requires x>10;
  
  function method BodyLess1(a:int) : int
    requires a > 0;
   
  function method dd(a:int) : int  
   
  method Testing()  
}

class C1 extends T1
{
  function method dd(x:int):int
  {
    2  
  }
  
  method Testing()
  {
    var x:int := 11;
    x := bb(x);
  }
  
  function method bb(x:int):int
    requires x >10;
  {
    x
  }
  function method BodyLess1(bda:int) : int
    requires bda > (-10); 
  {
    2
  }
  
  method CallBodyLess(x:int)
    requires x > (-10);
  {
    var k:int := BodyLess1(x);
    assert (k==2);
  }
}

trait T2 
{
  function method F(x: int): int
    requires x < 100;
    ensures F(x) < 100;
  
  method M(x: int) returns (y: int)
    requires 0 <= x;
    ensures x < y;
}

class C2 extends T2 
{
  function method F(x: int): int
    requires x < 100;
    ensures F(x) < 100;
  {
    x
  }
  
  method M(x: int) returns (y: int)
    requires -2000 <= x; // a more permissive precondition than in the interface
    ensures 2*x < y; // a more detailed postcondition than in the interface
  {
    y := (2 * x) + 1;
  }
}


trait T3 
{
  function method F(y: int): int
  function method G(y: int): int { 12 }
  method M(y: int)
  method N(y: int) {  
    var a:int := 100;
    assert a==100;
  }
}
class C3 extends T3
{
  function method NewFunc (a:int, b:int) : int
  {
    a + b
  }
  function method F(y: int): int { 20 }
  method M(y: int) { 
    var a:int := 100;
    assert a==100;
  }
}

trait t
{
  function f(s2:int):int
    ensures f(s2) > 0;
    //requires s != null && s.Length > 1;
    //reads s, s2;
}

class c extends t
{
  function f(s3:int):int
    ensures f(s3) > 1;
    //requires s0 != null && s0.Length > (0);
    //reads s0;
  { 
    2
  }
}

trait TT
{
  static function method M(a:int, b:int) : int
    ensures M(a,b) == a + b;
  {
    a + b
  }
}

class CC extends TT 
{
  method Testing(a:int,b:int)
  {
    assert (TT.M(a,b) == a + b);
  }
}


trait T4 
{
  function method F(y: int): int
  
  function method G(y: int): int 
  { 
    100 
  }
  
  method M(y: int) returns (kobra:int)
    requires y > 0;
    ensures kobra > 0;
     
  method N(y: int) 
  { 
    var x: int;
    var y : int;
    y := 10;
    x := 1000;
    y := y + x;
  }
}

class C4 extends T4 
{
  function method F(y: int): int 
  { 
    200 
  }

  method M(kk:int) returns (ksos:int)
    requires kk > (-1);
    ensures ksos > 0;
  {
    ksos:=10;  
  }   
}