コード例 #1
0
class StoppingTaskBaseTestCase(TestCase):
    def setUp(self):
        self.D = 6
        self.Lower, self.Upper = [2, 1, 1], [10, 10, 2]
        self.task = StoppingTask(Lower=self.Lower, Upper=self.Upper, D=self.D)

    def test_dim_ok(self):
        self.assertEqual(self.D, self.task.D)
        self.assertEqual(self.D, self.task.dim())

    def test_lower(self):
        self.assertTrue(
            array_equal(fullArray(self.Lower, self.D), self.task.Lower))
        self.assertTrue(
            array_equal(fullArray(self.Lower, self.D), self.task.bcLower()))

    def test_upper(self):
        self.assertTrue(
            array_equal(fullArray(self.Upper, self.D), self.task.Upper))
        self.assertTrue(
            array_equal(fullArray(self.Upper, self.D), self.task.bcUpper()))

    def test_range(self):
        self.assertTrue(
            array_equal(
                fullArray(self.Upper, self.D) - fullArray(self.Lower, self.D),
                self.task.bRange))
        self.assertTrue(
            array_equal(
                fullArray(self.Upper, self.D) - fullArray(self.Lower, self.D),
                self.task.bcRange()))

    def test_ngens(self):
        self.assertEqual(inf, self.task.nGEN)

    def test_nfess(self):
        self.assertEqual(inf, self.task.nFES)

    def test_stop_cond(self):
        self.assertFalse(self.task.stopCond())

    def test_stop_condi(self):
        self.assertFalse(self.task.stopCondI())

    def test_eval(self):
        self.assertRaises(AttributeError, lambda: self.task.eval([]))

    def test_evals(self):
        self.assertEqual(0, self.task.evals())

    def test_iters(self):
        self.assertEqual(0, self.task.iters())

    def test_next_iter(self):
        self.assertEqual(None, self.task.nextIter())

    def test_is_feasible(self):
        self.assertFalse(self.task.isFeasible(fullArray([1, 2, 3], self.D)))
コード例 #2
0
ファイル: test_task.py プロジェクト: parkkk123/finan_jupyter
class StoppingTaskBaseTestCase(TestCase):
    r"""Test case for testing `Task`, `StoppingTask` and `CountingTask` classes.

	Date:
		April 2019

	Author:
		Klemen Berkovič

	See Also:
		* :class:`NiaPy.util.Task`
		* :class:`NiaPy.util.CountingTask`
		* :class:`NiaPy.util.StoppingTask`
	"""
    def setUp(self):
        self.D = 6
        self.Lower, self.Upper = [2, 1, 1], [10, 10, 2]
        self.task = StoppingTask(Lower=self.Lower, Upper=self.Upper, D=self.D)

    def test_dim_ok(self):
        self.assertEqual(self.D, self.task.D)
        self.assertEqual(self.D, self.task.dim())

    def test_lower(self):
        self.assertTrue(
            array_equal(fullArray(self.Lower, self.D), self.task.Lower))
        self.assertTrue(
            array_equal(fullArray(self.Lower, self.D), self.task.bcLower()))

    def test_upper(self):
        self.assertTrue(
            array_equal(fullArray(self.Upper, self.D), self.task.Upper))
        self.assertTrue(
            array_equal(fullArray(self.Upper, self.D), self.task.bcUpper()))

    def test_range(self):
        self.assertTrue(
            array_equal(
                fullArray(self.Upper, self.D) - fullArray(self.Lower, self.D),
                self.task.bRange))
        self.assertTrue(
            array_equal(
                fullArray(self.Upper, self.D) - fullArray(self.Lower, self.D),
                self.task.bcRange()))

    def test_ngens(self):
        self.assertEqual(inf, self.task.nGEN)

    def test_nfess(self):
        self.assertEqual(inf, self.task.nFES)

    def test_stop_cond(self):
        self.assertFalse(self.task.stopCond())

    def test_stop_condi(self):
        self.assertFalse(self.task.stopCondI())

    def test_eval(self):
        self.assertRaises(AttributeError, lambda: self.task.eval([]))

    def test_evals(self):
        self.assertEqual(0, self.task.evals())

    def test_iters(self):
        self.assertEqual(0, self.task.iters())

    def test_next_iter(self):
        self.assertEqual(None, self.task.nextIter())

    def test_is_feasible(self):
        self.assertFalse(self.task.isFeasible(fullArray([1, 2, 3], self.D)))