source: trunk/test/core/colin/test_problem.py @ 1768

Last change on this file since 1768 was 1768, checked in by wehart, 11 years ago

Rework of Coopr to use the new PyUtilib? package decomposition.

NOTE: to use Coopr with this update, we need to work with a new version of coopr_install.

File size: 1.6 KB
Line 
1#
2# Unit Tests for coopr.opt.colin.problem
3#
4#
5
6import os
7import sys
8from os.path import abspath, dirname
9cooprdir = dirname(dirname(dirname(dirname(abspath(__file__)))))
10sys.path.insert(0, cooprdir)
11cooprdir += os.sep
12currdir = dirname(abspath(__file__))+os.sep
13
14import unittest
15from nose.tools import nottest
16import coopr.opt
17import xml
18from coopr.opt import ResultsFormat, ProblemFormat
19import pyutilib.services
20import pyutilib.th
21
22
23class TestProblem1(coopr.opt.colin.MixedIntOptProblem):
24
25    def __init__(self):
26        coopr.opt.colin.MixedIntOptProblem.__init__(self)
27        self.real_lower=[0.0, -1.0, 1.0, None]
28        self.real_upper=[None, 0.0, 2.0, -1.0]
29        self.nreal=4
30
31    def function_value(self, point):
32        self.validate(point)
33        return point.reals[0] - point.reals[1] + (point.reals[2]-1.5)**2 + (point.reals[3]+2)**4
34
35
36
37
38class TestColinProblem(pyutilib.th.TestCase):
39
40    def setUp(self):
41        self.do_setup(False)
42        pyutilib.services.TempfileManager.tempdir = currdir
43
44    def do_setup(self,flag):
45        pyutilib.services.TempfileManager.tempdir = currdir
46        self.ps = coopr.opt.colin.PatternSearch()
47        self.problem=TestProblem1()
48
49    def tearDown(self):
50        pyutilib.services.TempfileManager.clear_tempfiles()
51
52    def test_error1(self):
53        point = coopr.opt.colin.MixedIntVars()
54        point.reals = [1.0]
55        try:
56            self.problem.validate(point)
57            self.fail("Expected ValueError")
58        except ValueError:
59            pass
60        point.reals = [1.0] * 4
61        point.integers = [1.0] * 4
62       
63
64if __name__ == "__main__":
65    unittest.main()
66
Note: See TracBrowser for help on using the repository browser.