Assignment03RulesSpec.rsc 2.58 KB
Newer Older
1
2
3
module Assignment03RulesSpec

import IO;
4
import lang::java::m3::Core;
5
6
7
8
9

import List;
import Set;
import SpecUtil;
import Message;
Markus Klinik's avatar
Markus Klinik committed
10
import Util;
11
12
13
14
15

import Assignment03Rules;

test bool projectWithGeometricInterface()
{
Markus Klinik's avatar
retab    
Markus Klinik committed
16
  return isEmpty(a03_geometric_is_comparable(loadTestProject("assignment03-good")));
17
18
19
20
}

test bool projectWithoutGeometricInterface()
{
Markus Klinik's avatar
retab    
Markus Klinik committed
21
  errors = a03_geometric_is_comparable(loadTestProject("assignment01-good"));
Markus Klinik's avatar
Markus Klinik committed
22
  return "There should be one interface called Geometric" in messages(errors);
23
24
25
26
}

test bool geometricShouldExtendComparable()
{
Markus Klinik's avatar
retab    
Markus Klinik committed
27
  errors = a03_geometric_is_comparable(loadTestProject("assignment03-geometric-doesnt-extend-comparable"));
Markus Klinik's avatar
Markus Klinik committed
28
  return "Geometric should extend Comparable" in messages(errors);
29
30
31
32
}

test bool rectangleAndCircleImplementGeometric()
{
Markus Klinik's avatar
retab    
Markus Klinik committed
33
34
  errors = a03_shapes_implement_comparable(loadTestProject("assignment03-good"));
  return isEmpty(errors);
35
36
37
38
}

test bool rectangleIsMissing()
{
Markus Klinik's avatar
retab    
Markus Klinik committed
39
40
41
  errors = a03_shapes_implement_comparable(loadTestProject("assignment03-rectangle-missing"));
  return
    { "There should be two implementations of Geometric: Rectangle and Circle" }
Markus Klinik's avatar
Markus Klinik committed
42
    <= messages(errors);
43
44
45
46
}

test bool shapesImplementComparableDirectly()
{
Markus Klinik's avatar
retab    
Markus Klinik committed
47
48
49
50
51
  errors = a03_shapes_implement_comparable(loadTestProject("assignment03-shapes-implement-too-much"));
  return
    { "Circle should implement Geometric and nothing else"
    , "Rectangle should implement Geometric and nothing else"
    }
Markus Klinik's avatar
Markus Klinik committed
52
    <= messages(errors);
Markus Klinik's avatar
Markus Klinik committed
53
54
55
56
}

test bool geometricDoesntOverrideCompareTo()
{
Markus Klinik's avatar
retab    
Markus Klinik committed
57
58
59
60
61
  errors = a03_shapes_implement_comparable(loadTestProject("assignment03-no-override-compareTo"));
  return
    { "Circle should override Comparable.compareTo"
    , "Rectangle should override Comparable.compareTo"
    }
Markus Klinik's avatar
Markus Klinik committed
62
    <= messages(errors);
63
64
65
66
67
68
}

// Geometric declares compareTo, and the shapes implement it.
// This test should pass.
test bool geometricDeclaresShapeImplements()
{
Markus Klinik's avatar
retab    
Markus Klinik committed
69
70
  errors = a03_shapes_implement_comparable(loadTestProject("assignment03-declared-and-implemented"));
  return isEmpty(errors);
71
72
73
74
75
76
77
}


// Geometric declares compareTo, but Circle does not implement it.
// This should generate an error. It seems impossible to distinguish this
// case from a default implementation in Geometric with the current M3.
// For now we don't generate an error.
Markus Klinik's avatar
comment    
Markus Klinik committed
78
// This is okay, also according to Pieter, because students get a compile error anyway.
79
80
test bool geometricDeclaresButShapeDoesntImplement()
{
81
  return true;
Markus Klinik's avatar
retab    
Markus Klinik committed
82
83
84
85
  M3 model = loadTestProject("assignment03-declared-not-implemented");
  errors = a03_shapes_implement_comparable(model);
  return
    { "Circle should override Comparable.compareTo"
Markus Klinik's avatar
Markus Klinik committed
86
    } <= messages(errors);
Markus Klinik's avatar
retab    
Markus Klinik committed
87
}