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

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

parent 7e43b059
correction/ correction/
build/ build/
howto.pdf howto.pdf
.vscode/
\ No newline at end of file
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <cassert> #include <cassert>
#include <utility>
#include <vector>
#include "model/course.h" #include "model/course.h"
#include "model/competency.h" #include "model/competency.h"
...@@ -34,8 +36,6 @@ int main(int argc, char* argv[]) ...@@ -34,8 +36,6 @@ int main(int argc, char* argv[])
assert(c.ects() == 7 && (c.name().compare("Testdel'oeuf") == 0) ); assert(c.ects() == 7 && (c.name().compare("Testdel'oeuf") == 0) );
std::cout << "Comp constructor ok" << std::endl; std::cout << "Comp constructor ok" << std::endl;
try try
{ {
c = Course::build(-1, "lol"); c = Course::build(-1, "lol");
...@@ -94,17 +94,47 @@ int main(int argc, char* argv[]) ...@@ -94,17 +94,47 @@ int main(int argc, char* argv[])
std::cout << "Excepetion handling ok" << std::endl; std::cout << "Excepetion handling ok" << std::endl;
} }
// int * ptr_time = c.rmTemporalFrameValue(2); int * ptr_time = c.rmTemporalFrameValue(2);
// assert(ptr_time != NULL && c.timeFrame().size()==1); assert(ptr_time != NULL && c.timeFrame().size()==1);
// std::cout << "Temporal rm by value 1/2 ok" << std::endl;; std::cout << "Temporal rm by value 1/2 ok" << std::endl;;
// ptr_time = c.rmTemporalFrameValue(2); ptr_time = c.rmTemporalFrameValue(2);
// assert(ptr_time == NULL && c.timeFrame().size() == 1); assert(ptr_time == NULL && c.timeFrame().size() == 1);
// std::cout << "Temp rm by val 2/2 ok" << std::endl; std::cout << "Temp rm by val 2/2 ok" << std::endl;
// c.addTemporalFrame(7); c.addTemporalFrame(7);
// ptr_time = c.rmTemporalFrameIndex(1); ptr_time = c.rmTemporalFrameIndex(1);
// assert(ptr_time != NULL && c.timeFrame().size()==2 && c.timeFrame().at(0) == 0); assert(ptr_time != NULL && *ptr_time == 7);
// std::cout << "Temporal rm by index ok" << std::endl; 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; return EXIT_SUCCESS;
} }
\ No newline at end of file
...@@ -29,6 +29,7 @@ class Competency ...@@ -29,6 +29,7 @@ class Competency
static Competency build(Magnitude &, std::string s = ""); static Competency build(Magnitude &, std::string s = "");
static Competency build(double, std::string = ""); static Competency build(double, std::string = "");
Competency() = default;
// === FUNCTION // === 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(). /** 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 * Use it instead of manipuling directly a Magnitude, since it'll handle MagnitudeException
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <utility> #include <utility>
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include <stdexcept>
#include "course.h" #include "course.h"
#include "competency.h" #include "competency.h"
...@@ -102,14 +103,53 @@ Course::Course(int id, int ects, std::string name) ...@@ -102,14 +103,53 @@ Course::Course(int id, int ects, std::string name)
} }
std::pair<Competency,double> * Course::rmTeachedComp(Competency teached) 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; 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) 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; 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 // === END MUTATOR
...@@ -130,20 +170,44 @@ bool Course::_duplicataProtection(std::vector<Competency> * prereq, Competency c ...@@ -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) 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(); 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; Competency current = teached->at(index).first;
while(it != teached->end() && !( teached->at(index).first == c) ) while(it != teached->end() && !( teached->at(index).first == c) )
{ {
it++; index=std::distance(teached->begin(), it);
index=std::distance(teached->begin(), teached->begin());
current = teached->at(index).first; 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 // === OPERATOR
std::ostream& operator<<(std::ostream& Stream, const Course & c) std::ostream& operator<<(std::ostream& Stream, const Course & c)
{ {
......
...@@ -61,6 +61,7 @@ class Course ...@@ -61,6 +61,7 @@ class Course
const int ects() const{return this->_ects;} const int ects() const{return this->_ects;}
const std::vector<Competency> prerequisites() const {return this->_prerequisites;} const std::vector<Competency> prerequisites() const {return this->_prerequisites;}
const std::vector<int> timeFrame() const {return this->_temporalAvailability;} const std::vector<int> timeFrame() const {return this->_temporalAvailability;}
const std::vector<std::pair<Competency, double>> teachedCompetenciesWeighted() const{return this->_weightedTeached;}
// === MUTATOR // === MUTATOR
// SETTER // SETTER
...@@ -87,6 +88,10 @@ class Course ...@@ -87,6 +88,10 @@ class Course
// === FUNC // === FUNC
void fixECTS(); 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 // === OPERATOR
......
...@@ -18,10 +18,10 @@ Magnitude Magnitude::build(double value = 0) ...@@ -18,10 +18,10 @@ Magnitude Magnitude::build(double value = 0)
} }
// === CONSTRUCTOR // === CONSTRUCTOR
Magnitude::Magnitude() // Magnitude::Magnitude()
{ // {
} // }
Magnitude::Magnitude(double d) Magnitude::Magnitude(double d)
{ {
......
...@@ -11,7 +11,6 @@ class Magnitude ...@@ -11,7 +11,6 @@ class Magnitude
double _value = 0; double _value = 0;
//Constructor //Constructor
Magnitude();
Magnitude(double); Magnitude(double);
// function // function
...@@ -20,6 +19,7 @@ class Magnitude ...@@ -20,6 +19,7 @@ class Magnitude
public: public:
static Magnitude build(double); //factory static Magnitude build(double); //factory
Magnitude() = default;
/* Magnitude(const Magnitude & m); */ /* Magnitude(const Magnitude & m); */
double rebase(); /// if value is out of range, assign it the nearest value. Usefull when a MagnitudeException is caught 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