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

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

Removing coopr.opt-depricated, and
renaming coopr.core to coopr.opt.

Unfortunately, plugins are still not being properly loaded, so
some of the tests are failing.

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 pyutilib_th
17import coopr.opt
18#import coopr
19import xml
20from coopr.opt import ResultsFormat, ProblemFormat
21import pyutilib
22
23
24class TestProblem1(coopr.opt.colin.MixedIntOptProblem):
25
26    def __init__(self):
27        coopr.opt.colin.MixedIntOptProblem.__init__(self)
28        self.real_lower=[0.0, -1.0, 1.0, None]
29        self.real_upper=[None, 0.0, 2.0, -1.0]
30        self.nreal=4
31
32    def function_value(self, point):
33        self.validate(point)
34        return point.reals[0] - point.reals[1] + (point.reals[2]-1.5)**2 + (point.reals[3]+2)**4
35
36
37
38
39class TestColinProblem(pyutilib_th.TestCase):
40
41    def setUp(self):
42        self.do_setup(False)
43        pyutilib.TempfileManager.tempdir = currdir
44
45    def do_setup(self,flag):
46        pyutilib.TempfileManager.tempdir = currdir
47        self.ps = coopr.opt.colin.PatternSearch()
48        self.problem=TestProblem1()
49
50    def tearDown(self):
51        pyutilib.TempfileManager.clear_tempfiles()
52
53    def test_error1(self):
54        point = coopr.opt.colin.MixedIntVars()
55        point.reals = [1.0]
56        try:
57            self.problem.validate(point)
58            self.fail("Expected ValueError")
59        except ValueError:
60            pass
61        point.reals = [1.0] * 4
62        point.integers = [1.0] * 4
63       
64
65if __name__ == "__main__":
66    unittest.main()
67
Note: See TracBrowser for help on using the repository browser.