Skip to content

Commit

Permalink
improving unit tests for constants 2
Browse files Browse the repository at this point in the history
  • Loading branch information
hhijazi committed Dec 28, 2018
1 parent 77a92be commit 544faec
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 166 deletions.
1 change: 1 addition & 0 deletions .codecov.yml
Expand Up @@ -27,3 +27,4 @@ comment:

ignore:
- "examples/*"
- "include/gravity/doctest.h"
9 changes: 8 additions & 1 deletion examples/Gravity_test.cpp
Expand Up @@ -45,14 +45,21 @@ TEST_CASE("Testing constants") {
auto mag0 = sqrmag(cx2);
CHECK(abs(mag0.eval()-5)<1e-8);
auto ang0 = angle(cx2);
ang0.print();
ang0.println();
CHECK(abs(ang0.eval()-(-2.677945045))<1e-8);
auto cx3 = conj(cx1);
CHECK(cx3.eval().real()==cx1.eval().real());
CHECK(cx3.eval().imag()==-1*cx1.eval().imag());
CHECK(real(cx3) == cx3.eval().real());
CHECK(imag(cx3) == cx3.eval().imag());
CHECK(cx3.get_dim() == 1);
try{
cx3.get_dim(2);
}
catch(invalid_argument& arg){
cout << "Error successfully caught: "<< endl;
cout << arg.what() << endl;
}
CHECK(cx3.is_number());
}

Expand Down
116 changes: 58 additions & 58 deletions examples/Optimization/NonLinear/Power/Gen.cpp
@@ -1,60 +1,60 @@
////
//// Gen.cpp
//// Gravity++
////
//// Created by Hassan Hijazi on 30/01/2015.
//
// Gen.cpp
// Gravity++
//
// Created by Hassan Hijazi on 30/01/2015.

//

#include "Gen.h"

using namespace std;

/** @brief Initialiser with linked Bus and generator properties
@note Designated initialiser
*/
Gen::Gen(Bus* bus, string name, double p_min, double p_max, double q_min, double q_max):_bus(bus), _cost(new GenCost()), _ps(0), _qs(0){
_active = true;
_name = name;
_pbound.min = p_min;
_pbound.max = p_max;
_qbound.min = q_min;
_qbound.max = q_max;
_id = -1;
};

Gen::Gen(const string& name):_cost(new GenCost()){
_name = name;
_active = true;
}

Gen::~Gen(){
delete _cost;
}

//void Gen::init_complex(){
// _S_ = Complex("S", &pg, &qg);
// _S_._name.append(_name);
////
//
//#include "Gen.h"
//
//using namespace std;
//
///** @brief Initialiser with linked Bus and generator properties
// @note Designated initialiser
// */
//Gen::Gen(Bus* bus, string name, double p_min, double p_max, double q_min, double q_max):_bus(bus), _cost(new GenCost()), _ps(0), _qs(0){
// _active = true;
// _name = name;
// _pbound.min = p_min;
// _pbound.max = p_max;
// _qbound.min = q_min;
// _qbound.max = q_max;
// _id = -1;
//};
//
//Gen::Gen(const string& name):_cost(new GenCost()){
// _name = name;
// _active = true;
//}
//
//Gen::~Gen(){
// delete _cost;
//}

/** @brief Prints generator infos */
void Gen::print(){

// cout << "Gen Id: "<< std::atoi(_name.c_str());
cout << _name;
if(!_active)
cout << " | WARNING: Inactive generator";
printf(" | Cost coefficients: (c0=%.02f,c1=%.02f,c2=%.02f)", _cost->c0, _cost->c1, _cost->c2);
printf(" | Active Power Bounds: (%.02f,%.02f)", _pbound.min, _pbound.max);
printf(" | Reactive Power Bounds: (%.02f,%.02f)", _qbound.min, _qbound.max);
printf(" | Participation Factor: %.02f%%\n", _part_factor);

};

/** @brief Set cost coefficients fot the current generator */
void Gen::set_costs(double c0, double c1, double c2){
_cost->c0 = c0;
_cost->c1 = c1;
_cost->c2 = c2;
};

//
////void Gen::init_complex(){
//// _S_ = Complex("S", &pg, &qg);
//// _S_._name.append(_name);
////}
//
///** @brief Prints generator infos */
//void Gen::print(){
//
//// cout << "Gen Id: "<< std::atoi(_name.c_str());
// cout << _name;
// if(!_active)
// cout << " | WARNING: Inactive generator";
// printf(" | Cost coefficients: (c0=%.02f,c1=%.02f,c2=%.02f)", _cost->c0, _cost->c1, _cost->c2);
// printf(" | Active Power Bounds: (%.02f,%.02f)", _pbound.min, _pbound.max);
// printf(" | Reactive Power Bounds: (%.02f,%.02f)", _qbound.min, _qbound.max);
// printf(" | Participation Factor: %.02f%%\n", _part_factor);
//
//};
//
///** @brief Set cost coefficients fot the current generator */
//void Gen::set_costs(double c0, double c1, double c2){
// _cost->c0 = c0;
// _cost->c1 = c1;
// _cost->c2 = c2;
//};
//
172 changes: 86 additions & 86 deletions examples/Optimization/NonLinear/Power/Gen.h
@@ -1,86 +1,86 @@
//
// Gen.h
// PowerTools++
//
// Created by Hassan Hijazi on 30/01/2015.
// Copyright (c) 2015 NICTA. All rights reserved.
//

#ifndef Gen_h
#define Gen_h

#include <stdio.h>
#include <gravity/var.h>
#include "Bound.h"
#include "GenCost.h"
#include <iostream>
#include <stdio.h>
#include <gravity/Auxiliary.h>

class Bus;

class Gen: public gravity::aux{
public:
/** @brief Unit name
@note One bus may have multiple generators
*/
string _unit_name;

string _type_name="Gen";



int _gen_type = -1;

/** Position of a generator in a container. **/
int _id;

/** @brief Corresponding Bus */
Bus* _bus;

/** @brief Active Power Generation Bounds */
Bound _pbound;

/** @brief Reactive Power Generation Bounds */
Bound _qbound;

/** @brief Participation Factor */
double _part_factor = 0;

/** @brief generation cost function/coefficients */
GenCost* _cost;

/** @brief snapshot value of active power generation */
double _ps;
/** @brief snapshot value of reactive power generation */
double _qs;

/** @brief Complex power generation variable */
//Complex<double> _S_;
/** @brief Active power generation variable */
//var<> pg;
/** @brief Reactive power generation variable */
//var<> qg;
Bus* _src = nullptr;
Bus* _dest = nullptr;

/** @brief Initialiser with linked Bus and generator properties
*/
Gen(Bus* b, std::string name, double p_min, double p_max, double q_min, double q_max);

Gen(const string& name);

/** @brief Destructor
*/
~Gen();

//void init_complex();

/** @brief Prints generator infos */
void print();

/** @brief Set cost coefficients fot the current generator */
void set_costs(double c0, double c1, double c2);

};
#endif /* defined(__PowerTools____Gen__) */
// //
// // Gen.h
// // PowerTools++
// //
// // Created by Hassan Hijazi on 30/01/2015.
// // Copyright (c) 2015 NICTA. All rights reserved.
// //
//
//#ifndef Gen_h
//#define Gen_h
//
//#include <stdio.h>
//#include <gravity/var.h>
//#include "Bound.h"
//#include "GenCost.h"
//#include <iostream>
//#include <stdio.h>
//#include <gravity/Auxiliary.h>
//
//class Bus;
//
//class Gen: public gravity::aux{
//public:
// /** @brief Unit name
// @note One bus may have multiple generators
// */
// string _unit_name;
//
// string _type_name="Gen";
//
//
//
// int _gen_type = -1;
//
// /** Position of a generator in a container. **/
// int _id;
//
// /** @brief Corresponding Bus */
// Bus* _bus;
//
// /** @brief Active Power Generation Bounds */
// Bound _pbound;
//
// /** @brief Reactive Power Generation Bounds */
// Bound _qbound;
//
// /** @brief Participation Factor */
// double _part_factor = 0;
//
// /** @brief generation cost function/coefficients */
// GenCost* _cost;
//
// /** @brief snapshot value of active power generation */
// double _ps;
// /** @brief snapshot value of reactive power generation */
// double _qs;
//
// /** @brief Complex power generation variable */
// //Complex<double> _S_;
// /** @brief Active power generation variable */
// //var<> pg;
// /** @brief Reactive power generation variable */
// //var<> qg;
// Bus* _src = nullptr;
// Bus* _dest = nullptr;
//
// /** @brief Initialiser with linked Bus and generator properties
// */
// Gen(Bus* b, std::string name, double p_min, double p_max, double q_min, double q_max);
//
// Gen(const string& name);
//
// /** @brief Destructor
// */
// ~Gen();
//
// //void init_complex();
//
// /** @brief Prints generator infos */
// void print();
//
// /** @brief Set cost coefficients fot the current generator */
// void set_costs(double c0, double c1, double c2);
//
//};
//#endif /* defined(__PowerTools____Gen__) */
42 changes: 21 additions & 21 deletions include/gravity/Auxiliary.h
@@ -1,24 +1,24 @@
////
//// Auxiliary.h
//// Gravity
////
//// Created by Hassan Hijazi on 1/3/18.
////
////
//
// Auxiliary.h
// Gravity
//#ifndef Auxiliary_h
//#define Auxiliary_h
//
// Created by Hassan Hijazi on 1/3/18.
//using namespace std;
//
//

#ifndef Auxiliary_h
#define Auxiliary_h

using namespace std;

namespace gravity {

/** Backbone class for auxiliary objects that can be attached to nodes, e.g., generators. */
class aux{
public:
bool _active;
string _name;
virtual ~aux(){};
};
};
#endif /* Auxiliary_h */
//namespace gravity {
//
// /** Backbone class for auxiliary objects that can be attached to nodes, e.g., generators. */
// class aux{
// public:
// bool _active;
// string _name;
// virtual ~aux(){};
// };
//};
//#endif /* Auxiliary_h */

0 comments on commit 544faec

Please sign in to comment.