Generated on for Gecode by doxygen 1.15.0
basic.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
6 *
7 * Copyright:
8 * Christian Schulte, 2005
9 * Vincent Barichard, 2012
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.dev
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#include "test/float.hh"
37
38#include <cmath>
39
40namespace Test { namespace Float {
41
43 namespace Basic {
44
50
52 class Basic : public Test {
53 public:
56 : Test("Basic",3,-n,n,s,CPLT_ASSIGNMENT,false) {}
57
59 : Test("Basic",3,v,s,CPLT_ASSIGNMENT,false) {}
60
61 virtual MaybeType solution(const Assignment&) const {
62 return MT_TRUE;
63 }
64
66 }
67
69 // Reification for no constraint is not interesting
71 }
72 };
73
74 namespace {
75 Basic b1(3,1.5);
76 Basic b2(Gecode::FloatVal(-2,10),1.5);
77 }
78
80 class Median : public Base {
81 private:
83 static bool valid(const Gecode::FloatVal& x) {
84 const Gecode::FloatNum m = x.med();
85 return (m >= x.min()) && (m <= x.max()) &&
86 (x.tight() || ((m > x.min()) && (m < x.max())));
87 }
88 public:
90 Median(void) : Base("Float::Basic::Median") {}
92 virtual bool run(void) {
93 using namespace Gecode;
95 const FloatNum i = std::numeric_limits<FloatNum>::infinity();
96 const FloatNum d = std::numeric_limits<FloatNum>::denorm_min();
97 const FloatVal negative(-m, -m / 2.0);
98 const FloatVal positive(m / 2.0, m);
99 const FloatVal mixed(-m, m);
100 // The subtraction-based formula rounds this median one ULP upward.
101 const FloatVal closest(3.07187504409887e-53,
102 7.805365587017815e-45);
103 return valid(negative) && valid(positive) && valid(mixed) &&
104 (closest.med() == 3.902682808868283e-45) &&
105 (FloatVal(-i,-1.0).med() == -i) &&
106 (FloatVal(1.0,i).med() == i) &&
107 (FloatVal(-i,i).med() == 0.0) &&
108 (FloatVal(-i,-i).med() == -i) &&
109 (FloatVal(i,i).med() == i) &&
110 !std::signbit(FloatVal(-0.0,0.0).med()) &&
111 (FloatVal(0.0,2.0*d).med() == d) &&
112 (FloatVal(-2.0*d,0.0).med() == -d);
113 }
114 };
115
116 namespace {
117 Median median;
118 }
120
121 }
122}}
123
124// STATISTICS: test-float
Float value type.
Definition float.hh:334
FloatNum med(void) const
Return median of float value.
Definition val.hpp:82
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition val.hpp:403
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition val.hpp:415
bool tight(void) const
Test whether float is tight.
Definition val.hpp:104
Float variable array.
Definition float.hh:1035
Reification specification.
Definition int.hh:910
Computation spaces.
Definition core.hpp:1775
Base(std::string s)
Create and register test with name s.
Definition test.cpp:60
Base class for assignments
Definition float.hh:80
Test whether testing infrastructure for float variables works
Definition basic.cpp:52
virtual void post(Gecode::Space &, Gecode::FloatVarArray &, Gecode::Reify)
Post reified constraint on x for r.
Definition basic.cpp:68
virtual void post(Gecode::Space &, Gecode::FloatVarArray &)
Post constraint on x.
Definition basic.cpp:65
Basic(Gecode::FloatNum n, Gecode::FloatNum s)
Initialize test.
Definition basic.cpp:55
Basic(Gecode::FloatVal v, Gecode::FloatNum s)
Initialize test.
Definition basic.cpp:58
virtual MaybeType solution(const Assignment &) const
Check whether x is a solution.
Definition basic.cpp:61
virtual bool run(void)
Perform test.
Definition basic.cpp:92
Median(void)
Create and register test.
Definition basic.cpp:90
double FloatNum
Floating point number base type.
Definition float.hh:106
const FloatNum max
Largest allowed float value.
Definition float.hh:844
Gecode toplevel namespace
Tests for basic setup
Definition basic.cpp:43
Testing domain floats.
Definition float.cpp:43
@ CPLT_ASSIGNMENT
Definition float.hh:62
MaybeType
Type for comparisons and solutions.
Definition float.hh:51
General test support.
Definition afc.cpp:39
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56