Commit 3230cb9e authored by Markus Klinik's avatar Markus Klinik
Browse files

refactor test cases

parent 99fa0c6d
......@@ -22,4 +22,5 @@ set[loc] getMainMethods(M3 model)
loc getMainClass(M3 model) =
getOneFrom(range(domainR(invert(model.containment), getMainMethods(model))));
// extract only the messages of a set of errors, discarding the locations
set[str] messages(set[Message] errors) = { message | error(message, _) <- errors };
\ No newline at end of file
......@@ -4,6 +4,7 @@ import Set;
import SpecUtil;
import Assignment01Rules;
import Util;
test bool allIsWell()
{
......@@ -14,5 +15,5 @@ test bool allIsWell()
test bool ioOnlyInMainClass()
{
errors = a01_io(loadTestProject("assignment01-io-in-group"));
return "Only the main or view class should contain I/O" in { message | error(message,_) <- errors };
return "Only the main or view class should contain I/O" in messages(errors);
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import List;
import Set;
import SpecUtil;
import Message;
import Util;
import Assignment03Rules;
......@@ -18,13 +19,13 @@ test bool projectWithGeometricInterface()
test bool projectWithoutGeometricInterface()
{
errors = a03_geometric_is_comparable(loadTestProject("assignment01-good"));
return "There should be an interface called Geometric" in { message | error(message, _) <- errors };
return "There should be an interface called Geometric" in messages(errors);
}
test bool geometricShouldExtendComparable()
{
errors = a03_geometric_is_comparable(loadTestProject("assignment03-geometric-doesnt-extend-comparable"));
return "Geometric should extend Comparable" in { message | error(message, _) <- errors };
return "Geometric should extend Comparable" in messages(errors);
}
test bool rectangleAndCircleImplementGeometric()
......@@ -38,7 +39,7 @@ test bool rectangleIsMissing()
errors = a03_shapes_implement_comparable(loadTestProject("assignment03-rectangle-missing"));
return
{ "There should be two implementations of Geometric: Rectangle and Circle" }
<= { message | error(message, _) <- errors };
<= messages(errors);
}
test bool shapesImplementComparableDirectly()
......@@ -48,7 +49,7 @@ test bool shapesImplementComparableDirectly()
{ "Circle should implement Geometric and nothing else"
, "Rectangle should implement Geometric and nothing else"
}
<= { message | error(message, _) <- errors };
<= messages(errors);
}
test bool geometricDoesntOverrideCompareTo()
......@@ -58,7 +59,7 @@ test bool geometricDoesntOverrideCompareTo()
{ "Circle should override Comparable.compareTo"
, "Rectangle should override Comparable.compareTo"
}
<= { message | error(message, _) <- errors };
<= messages(errors);
}
// Geometric declares compareTo, and the shapes implement it.
......@@ -82,5 +83,5 @@ test bool geometricDeclaresButShapeDoesntImplement()
errors = a03_shapes_implement_comparable(model);
return
{ "Circle should override Comparable.compareTo"
} <= { message | error(message, _) <- errors};
} <= messages(errors);
}
......@@ -6,6 +6,7 @@ import lang::java::m3::Core;
import SpecUtil;
import Assignment04Rules;
import Util;
test bool abstractClassQuestionExists()
{
......@@ -16,27 +17,27 @@ test bool abstractClassQuestionExists()
test bool questionIsNotAbstract()
{
M3 model = loadTestProject("assignment04-question-is-not-abstract");
messages = a04_question_exists(model);
return { "Class Question should be abstract." } <= { m | error(m, _) <- messages };
errors = a04_question_exists(model);
return { "Class Question should be abstract." } <= messages(errors);
}
test bool classHierarchyIncorrect()
{
M3 model = loadTestProject("assignment04-class-hierarchy-incorrect");
messages = a04_question_types(model);
return {"ThisThatQuestion should extend MultipleChoiceQuestion"} <= { e | error(e,_) <- messages };
errors = a04_question_types(model);
return {"ThisThatQuestion should extend MultipleChoiceQuestion"} <= messages(errors);
}
test bool allSubclassesExist()
{
M3 model = loadTestProject("assignment04-good");
messages = a04_question_types(model);
return isEmpty(messages);
errors = a04_question_types(model);
return isEmpty(errors);
}
test bool oneSubclassMissing()
{
M3 model = loadTestProject("assignment04-subclass-missing");
messages = a04_question_types(model);
return { "There should be one class called MultipleChoiceQuestion" } <= { m | error(m, _) <- messages };
errors = a04_question_types(model);
return { "There should be one class called MultipleChoiceQuestion" } <= messages(errors);
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment