Commit 5765d89b authored by Alexis Lebis's avatar Alexis Lebis

Course class ok + test. Defining default construc for comp & mag

parent 7e43b059
correction/
build/
howto.pdf
.vscode/
\ No newline at end of file
......@@ -2,6 +2,8 @@
#include <iostream>
#include <string>
#include <cassert>
#include <utility>
#include <vector>
#include "model/course.h"
#include "model/competency.h"
......@@ -34,8 +36,6 @@ int main(int argc, char* argv[])
assert(c.ects() == 7 && (c.name().compare("Testdel'oeuf") == 0) );
std::cout << "Comp constructor ok" << std::endl;
try
{
c = Course::build(-1, "lol");
......@@ -94,17 +94,47 @@ int main(int argc, char* argv[])
std::cout << "Excepetion handling ok" << std::endl;
}
// int * ptr_time = c.rmTemporalFrameValue(2);
// assert(ptr_time != NULL && c.timeFrame().size()==1);
// std::cout << "Temporal rm by value 1/2 ok" << std::endl;;
// ptr_time = c.rmTemporalFrameValue(2);
// assert(ptr_time == NULL && c.timeFrame().size() == 1);
// std::cout << "Temp rm by val 2/2 ok" << std::endl;
// c.addTemporalFrame(7);
// ptr_time = c.rmTemporalFrameIndex(1);
// assert(ptr_time != NULL && c.timeFrame().size()==2 && c.timeFrame().at(0) == 0);
// std::cout << "Temporal rm by index ok" << std::endl;
int * ptr_time = c.rmTemporalFrameValue(2);
assert(ptr_time != NULL && c.timeFrame().size()==1);
std::cout << "Temporal rm by value 1/2 ok" << std::endl;;
ptr_time = c.rmTemporalFrameValue(2);
assert(ptr_time == NULL && c.timeFrame().size() == 1);
std::cout << "Temp rm by val 2/2 ok" << std::endl;
c.addTemporalFrame(7);
ptr_time = c.rmTemporalFrameIndex(1);
assert(ptr_time != NULL && *ptr_time == 7);
assert(c.timeFrame().size()==1 && c.timeFrame().at(0) == 0);
std::cout << "Temporal rm by index ok" << std::endl;
c.addTemporalFrame(7);
try{
ptr_time = c.rmTemporalFrameIndex(2);
assert(false);
}
catch(std::out_of_range & e)
{
assert(true);
}
std::pair<Competency,double> p1, p2, p3;
p1.first = comp1; p1.second = 0.5;
p2.first = comp2; p2.second = 0.3;
p3.first = comp3; p3.second = 0.7;
c.addTeachedComp(p1);
assert(c.teachedCompetenciesWeighted().size() == 1);
assert(c.teachedCompetenciesWeighted().at(0).first == comp1 );
std::cout << "Add new comp to teached ok" << std::endl;
c.addTeachedComp(p2); c.addTeachedComp(p3);
assert(c.teachedCompetenciesWeighted().size() == 3);
std::pair<Competency, double> * ptr_p;
ptr_p = c.rmTeachedComp(comp3);
assert(ptr_p != NULL);
assert(ptr_p->first == comp3);
assert(c.teachedCompetenciesWeighted().size() == 2);
std::cout << "RM teached comp ok" << std::endl;
return EXIT_SUCCESS;
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ class Competency
static Competency build(Magnitude &, std::string s = "");
static Competency build(double, std::string = "");
Competency() = default;
// === FUNCTION
/** evolveTowards allows the competency to increase or decrease according to the value passed in parameter (either in Magnitude._value or double). It represents the competency evolving towards a specfic state, here represented by this->_m.value() + m.value().
* Use it instead of manipuling directly a Magnitude, since it'll handle MagnitudeException
......
......@@ -2,6 +2,7 @@
#include <utility>
#include <algorithm>
#include <iterator>
#include <stdexcept>
#include "course.h"
#include "competency.h"
......@@ -102,14 +103,53 @@ Course::Course(int id, int ects, std::string name)
}
std::pair<Competency,double> * Course::rmTeachedComp(Competency teached)
{return NULL;}
int * Course::rmTemporalFrameIndex(int index)
{
if(this->_weightedTeached.size()==0)
return NULL;
std::vector<std::pair<Competency, double>>::iterator it = this->_weightedTeached.begin();
int index = 0;
Competency current = this->_weightedTeached.at(index).first;
while(it != this->_weightedTeached.end() && !( this->_weightedTeached.at(index).first == teached) )
{
index=std::distance(this->_weightedTeached.begin(), it);
current = this->_weightedTeached.at(index).first;
it++;
}
if(it == this->_weightedTeached.end() && !( this->_weightedTeached.at(index).first == teached))
return NULL;
std::pair<Competency, double> * ptr_pair = &(this->_weightedTeached.at(index));
this->_weightedTeached.erase(this->_weightedTeached.begin()+index);
return ptr_pair;
}
int * Course::rmTemporalFrameIndex(int index)
{
int *ptr_time = & (this->_temporalAvailability.at(index)) ;
this->_temporalAvailability.erase(this->_temporalAvailability.begin()+index);
return ptr_time;
}
int * Course::rmTemporalFrameValue(int value)
{
std::vector<int>::iterator it =
std::find(
this->_temporalAvailability.begin(),
this->_temporalAvailability.end(),
value
);
if(it == this->_temporalAvailability.end())
return NULL;
int index = std::distance(this->_temporalAvailability.begin(), it);
int * ptr_time = &(this->_temporalAvailability.at(index));
this->_temporalAvailability.erase(this->_temporalAvailability.begin()+index);
return ptr_time;
}
// === END MUTATOR
......@@ -130,20 +170,44 @@ bool Course::_duplicataProtection(std::vector<Competency> * prereq, Competency c
bool Course::_duplicataProtection(std::vector<std::pair<Competency,double>> *teached, Competency c)
{
if(teached->size() == 0)
return false;
std::vector<std::pair<Competency, double>>::iterator it = teached->begin();
int index = std::distance(teached->begin(), teached->begin());
int index = 0;
Competency current = teached->at(index).first;
while(it != teached->end() && !( teached->at(index).first == c) )
{
it++;
index=std::distance(teached->begin(), teached->begin());
index=std::distance(teached->begin(), it);
current = teached->at(index).first;
it++;
}
return it!=teached->end();
return ( it != teached->end() && !( teached->at(index).first == c) );
}
// template<typename T>
// std::pair<int, T> Course::findInVector(const std::vector<T> & vec, const T & findMe)
// {
// std::pair<int, T> res;
// typename std::vector<T>::iterator it = std::find( vec.begin(), vec.end(), findMe);
// if(it == vec.end())
// {
// res.first = -1;
// res.second; //NTD, -1 SHOULD BE USED TO DETECT THAT NOTHING HAS BEEN FOUND
// }
// else
// {
// res.first = std::distance(vec.begin(), it);
// res.second = vec.at(res.first);
// }
// return res;
// }
// === OPERATOR
std::ostream& operator<<(std::ostream& Stream, const Course & c)
{
......
......@@ -61,6 +61,7 @@ class Course
const int ects() const{return this->_ects;}
const std::vector<Competency> prerequisites() const {return this->_prerequisites;}
const std::vector<int> timeFrame() const {return this->_temporalAvailability;}
const std::vector<std::pair<Competency, double>> teachedCompetenciesWeighted() const{return this->_weightedTeached;}
// === MUTATOR
// SETTER
......@@ -87,6 +88,10 @@ class Course
// === FUNC
void fixECTS();
/// _findInVector search the 2nd param inside a vector (1st param). It returns the a pair representing the index of the element, and the ptr of the element, or (-1;NULL) otherwise
// template<typename T>
// static std::pair<int, T> findInVector(const std::vector<T> &, const T &);
};
// === OPERATOR
......
......@@ -18,10 +18,10 @@ Magnitude Magnitude::build(double value = 0)
}
// === CONSTRUCTOR
Magnitude::Magnitude()
{
// Magnitude::Magnitude()
// {
}
// }
Magnitude::Magnitude(double d)
{
......
......@@ -11,7 +11,6 @@ class Magnitude
double _value = 0;
//Constructor
Magnitude();
Magnitude(double);
// function
......@@ -20,6 +19,7 @@ class Magnitude
public:
static Magnitude build(double); //factory
Magnitude() = default;
/* Magnitude(const Magnitude & m); */
double rebase(); /// if value is out of range, assign it the nearest value. Usefull when a MagnitudeException is caught
......
#ifndef SRC_MODEL_PARCOURS_H_
#define SRC_MODEL_PARCOURS_H_
/**
* Represents a cursus of a student. It is equivalent to an individu in a EA.
*/
#endif // SRC_MODEL_PARCOURS_H_
\ No newline at end of file
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