geneura-papers / 2020-evostar-variable-attack-surface

Paper on evolving the "attack surface" of services to maximize security.
GNU General Public License v3.0
1 stars 0 forks source link

Test errors: in test_genetic.py #16

Closed JJ closed 4 years ago

JJ commented 4 years ago

In test_genetic.py:

➜  code git:(master) pytest test/test_genetic.py 
==================================================== test session starts =====================================================
platform linux -- Python 3.6.4, pytest-4.3.0, py-1.8.0, pluggy-0.9.0
rootdir: /home/jmerelo/txt/investigacion/papers/2019/2020-evostar-variable-attack-surface/code, inifile:
plugins: celery-4.2.1
collected 8 items                                                                                                            

test/test_genetic.py ...F...F                                                                                          [100%]

========================================================== FAILURES ==========================================================
_______________________________________________________ test_mutation ________________________________________________________

function1 = <MagicMock name='generate_random_config' id='139624031941240'>
function2 = <MagicMock name='random' id='139624121741608'>

    @mock.patch('random.random', return_value=0.1)
    @mock.patch('fitness.generate_random_config', return_value=[200, 39, 0, 1, 0, 1033, 1933, 1, 0, 2, 3, 0, 1])
    def test_mutation(function1, function2):
        """Test mutation function"""
        population = [
            [1523, 42, 0, 1, 1, 2045, 537, 1, 1, 2, 2, 0, 0],
            [1971, 117, 0, 1, 0, 1140, 1737, 1, 1, 2, 2, 0, 0],
            [882, 101, 1, 0, 0, 986, 644, 0, 1, 1, 5, 0, 0],
            [1529, 70, 1, 1, 1, 1462, 1834, 0, 0, 1, 1, 1, 0],
        ]
        expected_result = [
            [1523, 42, 0, 1, 1, 2045, 537, 1, 1, 2, 2, 0, 0],
            [1971, 117, 0, 1, 0, 1140, 1737, 1, 1, 2, 2, 0, 0],
            [882, 101, 1, 0, 0, 986, 644, 0, 1, 1, 5, 0, 0],
            [1529, 70, 1, 1, 1, 1462, 1834, 0, 0, 1, 1, 1, 0]
        ]
>       result = genetic.mutation(population)
E       AttributeError: module 'genetic' has no attribute 'mutation'

test/test_genetic.py:62: AttributeError
________________________________________________ test_crossover_two_points_7 _________________________________________________

    def test_crossover_two_points_7():
        """Test crossover function"""

        # We initialize the seed to get always the same random numbers
        random.seed(0)

        individual1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        individual2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        expected_result = [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1]
        result = genetic.crossover_two_points(individual1, individual2)
>       assert(result == expected_result)
E       assert [1, 1, 1, 1, 1, 1, ...] == [1, 1, 1, 1, 1, 1, ...]
E         At index 10 diff: 0 != 1
E         Use -v to get the full diff

test/test_genetic.py:110: AssertionError
============================================= 2 failed, 6 passed in 0.15 seconds =============================================
JJ commented 4 years ago

The second error is:

    def test_crossover_two_points_7():
        """Test crossover function"""

        # We initialize the seed to get always the same random numbers
        random.seed(0)

        individual1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        individual2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

        expected_result = [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1]
        result = genetic.crossover_two_points(individual1, individual2)
>       assert(result == expected_result)
E       assert [1, 1, 1, 1, 1, 1, ...] == [1, 1, 1, 1, 1, 1, ...]
E         At index 10 diff: 0 != 1
E         Full diff:
E         - [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]
E         ?                                ^  ^  ^
E         + [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1]
E         ?                                ^  ^  ^

It might not be actually working as a 2-point crossover.