Skip to content

Commit

Permalink
[lohner] added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Jan 31, 2022
1 parent 76e0f8c commit f1b3c68
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
63 changes: 56 additions & 7 deletions tests/core/tests_ctc_lohner.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <cstdio>
#include "catch_interval.hpp"
#include "codac_VIBesFigTube.h"
#include "codac_VIBesFigTubeVector.h"
#include "codac_ContractorNetwork.h"
#include "vibes.h"

// Using #define so that we can access protected methods
Expand All @@ -17,38 +19,43 @@ using namespace codac;

#define VIBES_DRAWING 0

TEST_CASE("CtcLohner") {
SECTION("Test CtcLohner, eval base") {
TEST_CASE("CtcLohner")
{
SECTION("Test CtcLohner, eval base")
{
float delta = 1.1;

Interval t(0.5, 1.0);
TubeVector tube(t, 1);
tube.set(IntervalVector(1, 1.5), t.lb());
TubeVector tube_raw = tube;
Slice *slice;

tube = tube_raw;
Function f5("x", "x");
CtcLohner ctc_lohner_f5(f5);
ctc_lohner_f5.contract(tube, TimePropag::FORWARD);
CHECK(tube(0).is_superset(1.5 + Interval(0., 0.5) * Interval(1., 2.)));
// todo: these tests are not useful (supersets)

tube = tube_raw;
tube.set(IntervalVector(1, 2. * atan(exp(-t.lb()) * tan(0.5))), t.lb());
Function f7("x", "-sin(x)");
CtcLohner ctc_lohner_f7(f7);
ctc_lohner_f7.contract(tube, TimePropag::FORWARD);
CHECK(tube(0).is_superset(Interval(2. * atan(exp(-t.lb()) * tan(0.5))) | 2. * atan(exp(-t.ub()) * tan(0.5))));
// todo: these tests are not useful (supersets)

tube = tube_raw;
tube.set(IntervalVector(1, exp(-t.lb())), t.lb());
Function f8("x", "-x");
CtcLohner ctc_lohner_f8(f8);
ctc_lohner_f8.contract(tube, TimePropag::FORWARD);
CHECK(tube(0).is_superset(IntervalVector(Interval(exp(-t.lb()))) | IntervalVector(Interval(exp(-t.ub())))));
// todo: these tests are not useful (supersets)
}

SECTION("Test CtcLohner / Slice - dim 1") {
SECTION("Test CtcLohner / Slice - dim 1")
{
Interval domain(0., 0.1);
TubeVector tube(domain, 1);
tube.set(IntervalVector(1, exp(domain.lb())), domain.lb());
Expand All @@ -63,9 +70,11 @@ TEST_CASE("CtcLohner") {
ctc_lohner.contract(tube, TimePropag::FORWARD);
x = tube[0].first_slice();
CHECK(x->output_gate().is_superset(Interval(exp(domain.ub()))));
// todo: these tests are not useful (supersets)
}

SECTION("Test CtcLohner / TubeVector - dim 2") {
SECTION("Test CtcLohner / TubeVector - dim 2")
{
Interval domain(0., 1.);
double dt = 0.1;
TubeVector x(domain, dt, 2);
Expand All @@ -83,6 +92,7 @@ TEST_CASE("CtcLohner") {
// TODO : CHECK(x.codomain()[1].is_superset(exp(domain)));
CHECK(x(0.)[1].is_superset(Interval(exp(0.))));
CHECK(x(1.)[1].is_superset(Interval(exp(1.))));
// todo: these tests are not useful (supersets)

//if(false & VIBES_DRAWING) // drawing results
//{
Expand All @@ -94,7 +104,8 @@ TEST_CASE("CtcLohner") {
//}
}

SECTION("Test CtcLohner / TubeVector - dim 1 - forward") {
SECTION("Test CtcLohner / TubeVector - dim 1 - forward")
{
Interval domain(0., 1.);
double dt = 0.1;
Tube x(domain, dt);
Expand All @@ -109,6 +120,7 @@ TEST_CASE("CtcLohner") {
CHECK(x.codomain().is_superset(Interval(exp(-domain.lb())) | exp(-domain.ub())));
CHECK(x(0.).is_superset(Interval(exp(-0.))));
CHECK(x(1.).is_superset(Interval(exp(-1))));
// todo: these tests are not useful (supersets)

if (false & VIBES_DRAWING) // drawing results
{
Expand All @@ -120,7 +132,8 @@ TEST_CASE("CtcLohner") {
}
}

SECTION("Test CtcLohner / TubeVector - dim 1 - backward") {
SECTION("Test CtcLohner / TubeVector - dim 1 - backward")
{
double dt = 0.1;
Interval domain(0., 1.);
Tube x(domain, dt);
Expand All @@ -134,6 +147,7 @@ TEST_CASE("CtcLohner") {
CHECK(x.codomain().is_superset(Interval(exp(-domain.lb())) | exp(-domain.ub())));
CHECK(x(0.).is_superset(Interval(exp(-0.))));
CHECK(x(1.).is_superset(Interval(exp(-1))));
// todo: these tests are not useful (supersets)

if (false & VIBES_DRAWING) // drawing results
{
Expand All @@ -144,4 +158,39 @@ TEST_CASE("CtcLohner") {
//vibes::endDrawing();
}
}

SECTION("Test CtcLohner in CN")
{
Interval domain(0., 1.);
double dt = 0.1;
TubeVector x(domain, dt, 2);
IntervalVector condition(2, Interval(1.));
x.set(condition, 0.);

Function f("x", "y", "(-x ; y)");
CtcLohner ctc_lohner(f);

//ctc_lohner.contract(x);

ContractorNetwork cn;
cn.add(ctc_lohner, {x});
cn.contract();

CHECK_FALSE(x.codomain().is_unbounded());
// TODO : CHECK(x.codomain()[0].is_superset(exp(-domain)));
CHECK(x(0.)[0].is_superset(Interval(exp(-0.))));
CHECK(x(1.)[0].is_superset(Interval(exp(-1.))));
// TODO : CHECK(x.codomain()[1].is_superset(exp(domain)));
CHECK(x(0.)[1].is_superset(Interval(exp(0.))));
CHECK(x(1.)[1].is_superset(Interval(exp(1.))));

if (false & VIBES_DRAWING) // drawing results
{
vibes::beginDrawing();
VIBesFigTubeVector fig_tube("fig", &x);
fig_tube.set_properties(100, 100, 500, 500);
fig_tube.show(true);
vibes::endDrawing();
}
}
}
14 changes: 14 additions & 0 deletions tests/core/tests_ctc_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ TEST_CASE("CtcStatic")
CHECK(x[0] == expected);
CHECK(x[1] == expected);
}
}

TEST_CASE("CtcFunction")
{
SECTION("Test max tubes")
{
CtcFunction ctc_max(Function("x1", "x2","x3", "max(x1,x2)-x3"));
TubeVector tube(Interval(0,10), 1., 3);
tube[0].set(Interval(2,3));
tube[1].set(Interval(4,5));
tube[2].set(Interval::ALL_REALS);
ctc_max.contract(tube);
CHECK(tube[2].codomain() == Interval(4,5));
}
}

0 comments on commit f1b3c68

Please sign in to comment.