Commit 2912241b authored by Ådne Karstad's avatar Ådne Karstad

[minor] finish test code and related documentation

parent 57b47f31
# Project 1
# Project 1: SPP - StudyProgramProject
- `tdt4250.spp.model` contains the model code and source code.
- `model` contains the `spp.ecore` model related genmodel and implementation.
- `src` containing the automatically generated and manual written code
- `tdt4250.spp` the interfaces and datatypes generated by Ecore
- `tdt4250.spp.examples` manually written example code - based on examples given in the lectures
- `tdt4250.spp.impl` implementation code mostly generated by Ecore and some details written manually
- `tdt4250.spp.util`
- `tdt4250.spp.model.tests` contain all tests for the source code.
The model created
The model created (subject to change)
![model](assets/model.png)
## Assumptions
-
## Rationale
- A University naturally owns all Study _Programs_ and institutes, meaning it's the root container in the domain.
......@@ -26,3 +28,20 @@ The model created
- Bachelor level courses is one of; Foundation, Intermediate, or ThirdYear.
- Masters is always Second Degree.
- A course can be taken either in the semester Fall or Spring, and may or may not be available for both.
## Testing
Tests for all current manual code implementation written.
Code coverage run with EclEmma v.3.1.3. [https://www.eclemma.org/index.html](https://www.eclemma.org/index.html).
![coverage](./assets/coverage.png)
The tests written are currently very trivial, and vulnerable to changes made to the code.
I've copied an xmi example into the test called _testFixture_ which is used in a couple of setUp methods.
When a more detailed fixture is created it should be replaced.
## Mistakes
- Typo for specialization -> is currently specialisation.
- Would like to do a refactor -> don't want to mess up current implementation.
......@@ -2,16 +2,22 @@
*/
package tdt4250.spp.tests;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import junit.framework.TestCase;
import junit.textui.TestRunner;
import tdt4250.spp.Course;
import tdt4250.spp.LevelType;
import tdt4250.spp.Program;
import tdt4250.spp.Semester;
import tdt4250.spp.SppFactory;
import tdt4250.spp.SppPackage;
import tdt4250.spp.University;
/**
* <!-- begin-user-doc -->
......@@ -40,6 +46,7 @@ public class ProgramTest extends TestCase {
* @generated
*/
protected Program fixture = null;
/**
* <!-- begin-user-doc -->
......@@ -88,7 +95,16 @@ public class ProgramTest extends TestCase {
*/
@Override
protected void setUp() throws Exception {
setFixture(SppFactory.eINSTANCE.createProgram());
ResourceSet resSet = new ResourceSetImpl();
resSet.getPackageRegistry().put(SppPackage.eNS_URI, SppPackage.eINSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Resource resource = resSet.getResource(URI.createURI(ProgramTest.class.getResource("testFixture.xmi").toString()), true);
University uni = (University) resource.getContents().get(0);
setFixture(uni.getPrograms().get(0));
}
/**
......@@ -141,12 +157,19 @@ public class ProgramTest extends TestCase {
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see tdt4250.spp.Program#getCredits()
* @generated
* @generated NOPE
*/
public void testGetCredits() {
// TODO: implement this operation test method
// Ensure that you remove @generated or mark it @generated NOT
fail();
Program program = getFixture();
float actualNumberOfCredits = program.getCredits();
float expectedNumberOfCredits = 0.0f;
for (Semester semester : program.getSemesters()) {
for (Course course : semester.getSelectedCourses()) {
expectedNumberOfCredits += course.getCredits();
}
}
assertEquals(expectedNumberOfCredits, actualNumberOfCredits);
}
} //ProgramTest
......@@ -2,12 +2,20 @@
*/
package tdt4250.spp.tests;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import junit.framework.TestCase;
import junit.textui.TestRunner;
import tdt4250.spp.Course;
import tdt4250.spp.Semester;
import tdt4250.spp.SppFactory;
import tdt4250.spp.SppPackage;
import tdt4250.spp.University;
/**
* <!-- begin-user-doc -->
......@@ -78,7 +86,16 @@ public class SemesterTest extends TestCase {
*/
@Override
protected void setUp() throws Exception {
setFixture(SppFactory.eINSTANCE.createSemester());
ResourceSet resSet = new ResourceSetImpl();
resSet.getPackageRegistry().put(SppPackage.eNS_URI, SppPackage.eINSTANCE);
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Resource resource = resSet.getResource(URI.createURI(ProgramTest.class.getResource("testFixture.xmi").toString()), true);
University uni = (University) resource.getContents().get(0);
setFixture(uni.getPrograms().get(0).getSemesters().get(0));
}
/**
......@@ -97,12 +114,15 @@ public class SemesterTest extends TestCase {
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see tdt4250.spp.Semester#getCredits()
* @generated
* @generated NOPE
*/
public void testGetCredits() {
// TODO: implement this operation test method
// Ensure that you remove @generated or mark it @generated NOT
fail();
float expectedNumberOfCredits = 0.0f;
for (Course course : getFixture().getSelectedCourses()) {
expectedNumberOfCredits += course.getCredits();
}
assertEquals(expectedNumberOfCredits, getFixture().getCredits());
}
} //SemesterTest
<?xml version="1.0" encoding="UTF-8"?>
<spp:University
xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spp="platform:/plugin/tdt4250.spp.model/model/spp.ecore"
xsi:schemaLocation="platform:/plugin/tdt4250.spp.model/model/spp.ecore spp.ecore"
name="NTNU">
<programs
name="Bachelor in IT">
<semesters
selectedCourses="//@institutes.0/@courses.0 //@institutes.0/@courses.7"/>
<semesters
season="Spring"
selectedCourses="//@institutes.0/@courses.4 //@institutes.1/@courses.5"/>
<semesters
year="2"
selectedCourses="//@institutes.0/@courses.5 //@institutes.1/@courses.2"/>
<mandatoryCourses
courses="//@institutes.0/@courses.0 //@institutes.0/@courses.3 //@institutes.0/@courses.4 //@institutes.0/@courses.5 //@institutes.0/@courses.7"/>
<electiveCourses
courses="//@institutes.0/@courses.1 //@institutes.0/@courses.2 //@institutes.0/@courses.6 //@institutes.1/@courses.3 //@institutes.1/@courses.4 //@institutes.1/@courses.5"/>
</programs>
<institutes
name="Institutt for datateknologi og informatikk">
<courses
code="TDT4110"
name="Informasjonsteknologi, grunnkurs"
credits="7.5"/>
<courses
code="TDT4250"
name="Avansert programvaredesign"
credits="7.5"
level="SecoundDegreeCourse"/>
<courses
code="TDT4175"
name="Informasjonssystemer"
credits="7.5"
level="ThirdYearCourse"/>
<courses
code="TDT4140"
name="Programvareutvikling"
credits="7.5"
level="IntermediateCourse"
season="Spring"/>
<courses
code="TDT4100"
name="Objektorientert programmering"
credits="7.5"
season="Spring"/>
<courses
code="TDT4120"
name="Algoritmer og datastrukturer"
credits="7.5"
level="IntermediateCourse"/>
<courses
code="IT2810"
name="Webutvikling"
credits="7.5"
level="IntermediateCourse"/>
<courses
code="IT2805"
name="Webteknologi"
credits="7.5"/>
</institutes>
<institutes
name="Institutt for matematiske fag">
<courses
code="MA1101"
name="Grunnkurs i analyse I"
credits="7.5"/>
<courses
code="MA1102"
name="Grunnkurs i analyse II"
credits="7.5"
season="Spring"/>
<courses
code="TMA4135"
name="Matematikk 4D"
credits="7.5"
level="ThirdYearCourse"/>
<courses
code="TMA4140"
name="Diskret matematikk"
credits="7.5"/>
<courses
code="MA1201"
name="Lineær algebra og geometri"
credits="7.5"/>
<courses
code="MA1103"
name="Flerdimensjonal analyse"
credits="7.5"
season="Spring"/>
</institutes>
<institutes
name="Institutt for lærerutdanning">
<courses
code="PPU4601 "
name="Pedagogikk 1"
credits="7.5"/>
<courses
code="PPU4611"
name="Praksis 1"/>
</institutes>
</spp:University>
......@@ -9,6 +9,7 @@ Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: tdt4250.spp,
tdt4250.spp.examples,
tdt4250.spp.impl,
tdt4250.spp.util
Require-Bundle: org.eclipse.core.runtime,
......
Markdown is supported
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