summaryrefslogtreecommitdiff
path: root/Test/dafny4/Bug49.dfy
blob: 887938d63c625c1bd75764787aceedc2f4c37398 (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
// RUN: %dafny /compile:3 "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

method Main()
{
  print apply(i => i + 1, 5), "\n";
  print mapply(map[5 := 6], 5), "\n";
  var f;
  print five(f), "\n";
}

// -----
// test that the definition axiom for function "apply" is available

function method apply(f:int->int, a:int): int
  reads f.reads
  requires f.requires(a)
{
  f(a)
}

lemma TestPost()
  ensures apply(i => i + 1, 5) == 6
{
}

lemma M() {
  assert apply(i => i + 1, 5) == 6;
}

lemma TestPre()
  requires apply(i => i + 1, 5) == 6
{
}

lemma TestPreCaller()
{
  TestPre();
}

// -----
// test that the above thing for arrows also works for maps

function method mapply(m: map<int,int>, a:int): int
  requires a in m
{
  m[a]
}

lemma TestMPost()
  ensures mapply(map[5 := 6], 5) == 6
{
}

lemma N() {
  assert mapply(map[5 := 6], 5) == 6;
}

// -----
// test that g's result is known to be $Is'ed and $IsAlloc'ed

function method five(f:int->int): int { 5 }

lemma P() {
  var f := i => i + 1;
  assert five(f) == 5;
}

lemma Q(g: real->int->int)
  requires g.requires(0.0)
{
  var f := g(0.0);
  assert five(f) == 5;
}