Skip to content

Commit

Permalink
partially updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alpavlenko committed Sep 20, 2023
1 parent 1fc8380 commit 2093c74
Show file tree
Hide file tree
Showing 25 changed files with 810 additions and 760 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with unittest
run: python -m unittest discover tests
run: ./run_tests.sh
37 changes: 0 additions & 37 deletions tests/test_a_utils.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest

from space.model import Backdoor
from instance.module.variables import Range
from pysatmc.variables import Range

from algorithm.module.crossover import OnePoint, TwoPoint, Uniform


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import unittest

from space.model import Backdoor
from instance.module.variables import Range
from pysatmc.variables import Range

from algorithm.module.mutation import OneBit, Uniform, Doer


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import unittest

from space.model import Backdoor
from pysatmc.variables import Range

from core.model.point import Point
from instance.module.variables import Range
from core.module.comparator import MinValueMaxSize

from algorithm.module.selection import BestPoint, Roulette


Expand Down Expand Up @@ -38,8 +40,9 @@ def test_best_point(self):
self.assertEqual(selection.select(vector, 2), [vector[4], vector[2]])

selection = BestPoint(best_count=2)
self.assertEqual(selection.select([vector[0]], 2), [vector[0], vector[0]])
# selection.select(vector, 3)
self.assertEqual(
selection.select([vector[0]], 2), [vector[0], vector[0]]
)

def test_roulette(self):
comparator = MinValueMaxSize()
Expand All @@ -54,8 +57,13 @@ def test_roulette(self):

selection = Roulette()
selection.random_state = RandomStateStub([0.05, 0.8])
self.assertEqual(selection.select(vector, 2), [vector[0], vector[4]])
self.assertEqual(
selection.select(vector, 2), [vector[0], vector[4]]
)

selection = Roulette()
selection.random_state = RandomStateStub([0.05, 0.05, 0.8, 0.65])
self.assertEqual(selection.select(vector, 4), [vector[0], vector[0], vector[4], vector[3]])
self.assertEqual(
selection.select(vector, 4),
[vector[0], vector[0], vector[4], vector[3]]
)
59 changes: 0 additions & 59 deletions tests/test_b_encoding.py

This file was deleted.

111 changes: 0 additions & 111 deletions tests/test_b_variables.py

This file was deleted.

48 changes: 0 additions & 48 deletions tests/test_c_instance.py

This file was deleted.

Empty file added tests/test_core/__init__.py
Empty file.
33 changes: 33 additions & 0 deletions tests/test_core/test_v_comparator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# import unittest
#
# from space.model import Backdoor
# from pysatmc.variables import Range
#
# from core.model.point import Point
# from core.module.comparator import MinValueMaxSize
#
#
# class TestComparator(unittest.TestCase):
# def test_min_value_max_size(self):
# comparator = MinValueMaxSize()
# backdoor = Backdoor(Range(start=1, length=8))
# self.assertGreater(
# Point(backdoor.make_copy([]), comparator).set(value=1000),
# Point(backdoor.make_copy([0, 0, 1]), comparator).set(value=900),
# )
# self.assertGreater(
# Point(backdoor.make_copy([0, 0, 1]), comparator).set(value=1000),
# Point(backdoor.make_copy([1, 1, 1]), comparator).set(value=1000),
# )
# self.assertEqual(
# Point(backdoor.make_copy([0, 1, 1]), comparator).set(value=1000),
# Point(backdoor.make_copy([1, 0, 1]), comparator).set(value=1000),
# )
# self.assertLess(
# Point(backdoor.make_copy([0, 1, 1]), comparator).set(value=1000),
# Point(backdoor.make_copy([0, 0, 1]), comparator).set(value=1000),
# )
# self.assertLess(
# Point(backdoor.make_copy([0, 1, 1]), comparator).set(value=1000),
# Point(backdoor.make_copy([1, 0, 1]), comparator).set(value=float('inf')),
# )
34 changes: 34 additions & 0 deletions tests/test_core/test_v_limitation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# import unittest
#
# from core.module.limitation import WallTime, Iteration
#
#
# class TestLimitation(unittest.TestCase):
# def test_iteration(self):
# limitation = Iteration(value=1000)
# self.assertEqual(limitation.exhausted(), False)
# self.assertEqual(limitation.left('time'), None)
# self.assertEqual(limitation.left('iteration'), 1000)
#
# limitation.increase('iteration', 990)
# self.assertEqual(limitation.left('iteration'), 10)
#
# limitation.set('iteration', 1234)
# self.assertEqual(limitation.left('iteration'), 0)
# self.assertEqual(limitation.get('iteration'), 1234)
# self.assertEqual(limitation.exhausted(), True)
#
# def test_wall_time(self):
# limitation = WallTime(from_string='02:13:45')
# self.assertEqual(limitation.exhausted(), False)
# self.assertEqual(limitation.left('time'), 8025)
# self.assertEqual(limitation.left('iteration'), None)
#
# limitation.increase('time', 654)
# self.assertEqual(limitation.get('time'), 654)
# self.assertEqual(limitation.left('time'), 7371)
#
# limitation.set('time', 10345)
# self.assertEqual(limitation.left('time'), 0)
# self.assertEqual(limitation.get('time'), 10345)
# self.assertEqual(limitation.exhausted(), True)
Loading

0 comments on commit 2093c74

Please sign in to comment.