Carlos Gershenson

196 papers A* 1A 1B 1C 11Journal 171Unranked 8
YearRankTypeTitle / Venue / Authors
2026 J jnl
CoRR
Marco A. Rosas Pulido, Roberto Murcio, Omar R. Vázquez, Carlos Gershenson
2026 J jnl
CoRR
Mário Franco, Carlos Gershenson
2025 J jnl
CoRR
Sean P. Maley, Carlos Gershenson, Stuart A. Kauffman
2025 J jnl
CoRR
Mário Franco, Gerardo L. Febres, Nelson Fernández, Carlos Gershenson
2024 J jnl
Entropy
Fernanda Sánchez-Puig, Rogelio Lozano-Aranda, Dante Pérez-Méndez, Ewan Colman, Alfredo J. Morales-Guzmán, Pedro Juan Rivera Torres, Carlos Pineda, Carlos Gershenson
2024 J jnl
CoRR
Gerardo Altamirano-Gómez, Carlos Gershenson
2024 J jnl
CoRR
Alberto García-Rodríguez, Matias Núñez, Miguel Robles Pérez, Tzipe Govezensky, Rafael A. Barrio, Carlos Gershenson, Kimmo K. Kaski, Julia Tagüeña
2024 J jnl
CoRR
Amahury Jafet López-Díaz, Hiroki Sayama, Carlos Gershenson
2023 J jnl
Artif. Life
Carlos Gershenson
2023 J jnl
CoRR
Gerardo Altamirano-Gómez, Carlos Gershenson
2023 J jnl
CoRR
Josué Ely Molina, Jorge Flores, Carlos Gershenson, Carlos Pineda
2023 J jnl
Entropy
Amahury Jafet López-Díaz, Fernanda Sánchez-Puig, Carlos Gershenson
2023 J jnl
Nat. Comput. Sci.
Guido Caldarelli, Elsa Arcaute, Marc Barthelemy, Michael Batty, Carlos Gershenson, Dirk Helbing, Stefano Mancuso, Yamir Moreno, José J. Ramasco, Céline Rozenblat, Ángel Sánchez, José Luis Fernández-Villacañas
2022 J jnl
Syst.
Gerardo L. Febres, Carlos Gershenson
2022 J jnl
CoRR
Fernanda Sánchez-Puig, Rogelio Lozano-Aranda, Dante Pérez-Méndez, Ewan Colman, Alfredo J. Morales-Guzmán, Carlos Pineda, Pedro Juan Rivera Torres, Carlos Gershenson
2022 J jnl
CoRR
Yoshio Martinez, Katya Rodriguez, Carlos Gershenson
2022 J jnl
CoRR
Amahury Jafet López-Díaz, Fernanda Sánchez-Puig, Carlos Gershenson
2021 J jnl
CoRR
Carlos Gershenson, Jitka Cejková
2021 J jnl
Frontiers Robotics AI
Carlos Gershenson, Daniel Polani, Georg Martius
2021 J jnl
CoRR
Carlos Gershenson
2021 J jnl
Adv. Complex Syst.
Alberto García-Rodríguez, Tzipe Govezensky, Carlos Gershenson, Gerardo G. Naumis, Rafael A. Barrio
2021 J jnl
CoRR
Alberto García-Rodríguez, Tzipe Govezensky, Carlos Gershenson, Gerardo G. Naumis, Rafael A. Barrio
2021 J jnl
CoRR
Martín Zumaya, Rita Guerrero, Eduardo Islas, Omar K. Pineda, Carlos Gershenson, Gerardo Iñiguez, Carlos Pineda
2021 J jnl
CoRR
Carlos Gershenson
2021 C conf
ALIFE
Carlos Gershenson
2021 C conf
ALIFE
Mário Franco, Octavio Zapata, David A. Rosenblueth, Carlos Gershenson
2021 J jnl
CoRR
José Antonio Morales, Jorge Flores, Carlos Gershenson, Carlos Pineda
2021 J jnl
Adv. Complex Syst.
José Antonio Morales, Jorge Flores, Carlos Gershenson, Carlos Pineda
2021 J jnl
Entropy
Daniel Guerrero, Pedro J. Rivera Torres, Gerardo L. Febres, Carlos Gershenson
2020 J jnl
J. Ambient Intell. Humaniz. Comput.
Cesar L. Gonzalez, Jorge L. Zapotecatl, Carlos Gershenson, Juan M. Alberola, Vicente Julián
2020 J jnl
Entropy
Hyobin Kim, Stalin Muñoz, Pamela Osuna, Carlos Gershenson
2020 J jnl
CoRR
Hyobin Kim, Stalin Muñoz, Pamela Osuna, Carlos Gershenson
2020 J jnl
Complex.
José C. Valverde, Henning S. Mortveit, Carlos Gershenson, Yongtang Shi
2020 J jnl
Complex.
Sergey A. Mityagin, Carlos Gershenson, Alexander Boukhanovsky
2020 J jnl
Frontiers Robotics AI
Carlos Gershenson
2020 C conf
ALIFE
Octavio Zapata, Hyobin Kim, Carlos Gershenson
2020 J jnl
Artif. Life
Carlos Gershenson, Vito Trianni, Justin Werfel, Hiroki Sayama
2019 J jnl
Complex.
Hyobin Kim, Omar K. Pineda, Carlos Gershenson
2019 J jnl
CoRR
Hyobin Kim, Omar K. Pineda, Carlos Gershenson
2019 J jnl
Complex.
Omar K. Pineda, Hyobin Kim, Carlos Gershenson
2019 J jnl
Complex.
Luis A. Escobar, Hyobin Kim, Carlos Gershenson
2019 J jnl
PLoS Comput. Biol.
Ewan Colman, Petter Holme, Hiroki Sayama, Carlos Gershenson
2019 J jnl
CoRR
Carlos Gershenson
2019 J jnl
CoRR
Carlos Gershenson, Vito Trianni, Justin Werfel, Hiroki Sayama
2019 J jnl
EPJ Data Sci.
Mário Franco, Gerardo L. Febres, Nelson Fernández, Carlos Gershenson
2018 J jnl
Artif. Life
Jesús Mario Siqueiros-García, Tom Froese, Carlos Gershenson, Wendy Aguilar, Hiroki Sayama, Eduardo Izquierdo
2018 J jnl
CoRR
Omar K. Pineda, Hyobin Kim, Carlos Gershenson
2018 conf
ISAmI
Cesar L. Gonzalez, Jorge L. Zapotecatl, Juan M. Alberola, Vicente Julián, Carlos Gershenson
2018 J jnl
J. Comput. Soc. Sci.
Carlos Adolfo Piña-García, Jesús Mario Siqueiros-García, Eduardo Robles-Belmont, Gustavo Carreón, Carlos Gershenson, Julio Amador Díaz López
2018 J jnl
Future Gener. Comput. Syst.
Vladislav A. Karbovskii, Daniil V. Voloshin, Andrey Karsakov, Alexey Bezgodov, Carlos Gershenson
2018 C conf
ALIFE
Carlos Gershenson, Vito Trianni, Justin Werfel, Hiroki Sayama
2018 J jnl
CoRR
Carlos Gershenson, Vito Trianni, Justin Werfel, Hiroki Sayama
2018 J jnl
Complex.
Sergio Sánchez, Germinal Cocho, Jorge Flores, Carlos Gershenson, Gerardo Iñiguez, Carlos Pineda
2017 J jnl
Frontiers Robotics AI
Guillermo Santamaría Bonfil, Carlos Gershenson, Nelson Fernández
2017 J jnl
Complex.
Jorge Zapotecatl, David A. Rosenblueth, Carlos Gershenson
2017 J jnl
CoRR
Sanjay Goel, Stephen F. Bush, Carlos Gershenson
2016 J jnl
CoRR
Carlos Gershenson, Paolo Santi, Carlo Ratti
2016 C conf
ALIFE
Nelson Fernández, Carlos Gershenson, Yesid Madrid
2016 J jnl
Complex.
Carlos Gershenson
2016 J jnl
Complex.
Carlos Gershenson
2016 J jnl
Complex.
Carlos Gershenson
2016 J jnl
CoRR
Carlos Adolfo Piña-García, Dongbing Gu, Jesús Mario Siqueiros-García, Gustavo Carreón, Carlos Gershenson
2016 J jnl
Res. Comput. Sci.
Carlos Adolfo Piña-García, Dongbing Gu, Carlos Gershenson, Jesús Mario Siqueiros-García, Eduardo Robles-Belmont
2016 C ed.
ALIFE
Tom Froese, Jesús Mario Siqueiros-García, Wendy Aguilar, Eduardo J. Izquierdo, Hiroki Sayama, Carlos Gershenson
2016 J jnl
EPJ Data Sci.
José A. Morales, Sergio Sánchez, Jorge Flores, Carlos Pineda, Carlos Gershenson, Germinal Cocho, Jerónimo Zizumbo, Rosalío F. Rodríguez, Gerardo Iñiguez
2016 J jnl
Entropy
Guillermo Santamaría Bonfil, Nelson Fernández, Carlos Gershenson
2016 J jnl
Peer-to-Peer Netw. Appl.
Michele Amoretti, Carlos Gershenson
2016 C conf
ALIFE
Carlos Gershenson, Anglica Muoz-Melndez, Jorge L. Zapotecatl
2016 A conf
IROS
Csaba Virágh, Máté Nagy, Carlos Gershenson, Gábor Vásárhelyi
2016 J jnl
Appl. Netw. Sci.
Carlos Adolfo Piña-García, Carlos Gershenson, Jesús Mario Siqueiros-García
2015 J jnl
Complex.
Carlos Gershenson
2015 J jnl
Complex.
Carlos Gershenson
2015 J jnl
Complex.
Carlos Gershenson
2015 J jnl
Complex.
Carlos Gershenson
2015 J jnl
Complex.
Gerardo L. Febres, Klaus Jaffe, Carlos Gershenson
2015 J jnl
Complex.
Carlos Gershenson
2015 J jnl
CoRR
Guillermo Santamaría Bonfil, Nelson Fernández, Carlos Gershenson
2015 J jnl
CoRR
Germinal Cocho, Jorge Flores, Carlos Gershenson, Carlos Pineda, Sergio Sánchez
2015 J jnl
Kybernetes
Carlos Gershenson
2015 J jnl
Complex.
Carlos Gershenson, Dirk Helbing
2015 J jnl
CoRR
Carlos Gershenson, Dirk Helbing
2014 J jnl
Complex.
Carlos Gershenson
2014 J jnl
Complex.
Carlos Gershenson
2014 J jnl
Complex.
Carlos Gershenson
2014 J jnl
Complex.
Carlos Gershenson
2014 J jnl
Entropy
Mikhail Prokopenko, Carlos Gershenson
2014 J jnl
CoRR
Carlos Gershenson
2014 J jnl
Entropy
Dario Zubillaga, Geovany Cruz, Luis Daniel Aguilar, Jorge Zapotecatl, Nelson Fernández, José Aguilar, David A. Rosenblueth, Carlos Gershenson
2014 J jnl
CoRR
Dario Zubillaga, Geovany Cruz, Luis Daniel Aguilar, Jorge Zapotecatl, Nelson Fernández, José Aguilar, David A. Rosenblueth, Carlos Gershenson
2014 C conf
CLEI
Nelson Fernández, José Aguilar, Gustavo Marcano, Oswaldo Terán, Carlos Gershenson
2014 C conf
ALIFE
Octavio Zapata, Carlos Gershenson
2014 J jnl
CoRR
Carlos Gershenson
2014 J jnl
Frontiers Robotics AI
Wendy Aguilar, Guillermo Santamaría Bonfil, Tom Froese, Carlos Gershenson
2013 J jnl
Complex.
Carlos Gershenson
2013 J jnl
Complex.
Carlos Gershenson
2013 J jnl
Complex.
Carlos Gershenson
2013 J jnl
Complex.
Carlos Gershenson
2013 J jnl
CoRR
Gerardo L. Febres, Klaus Jaffe, Carlos Gershenson
2013 J jnl
CoRR
Nelson Fernández, Carlos Maldonado, Carlos Gershenson
2013 J jnl
CoRR
Carlos Gershenson
2013 ch.
Handbook of Human Computation
Carlos Gershenson
2013 J jnl
CoRR
Bruce Edmonds, Carlos Gershenson
2013 J jnl
Complex Adapt. Syst. Model.
Carlos Gershenson, Muaz A. Niazi
2013 J jnl
Complex.
Carlos Gershenson
2013 J jnl
Complex.
Carlos Gershenson
2013 J jnl
CoRR
Luis Enrique Cortes-Berrueco, Carlos Gershenson, Christopher R. Stephens
2013 conf
IWSOS
Luis Enrique Cortes-Berrueco, Carlos Gershenson, Christopher R. Stephens
2013 J jnl
CoRR
Tom Froese, Carlos Gershenson, David A. Rosenblueth
2013 B conf
IEEE Congress on Evolutionary Computation
Tom Froese, Carlos Gershenson, David A. Rosenblueth
2012 J jnl
Kybernetes
Carlos Gershenson, David A. Rosenblueth
2012 J jnl
CoRR
Carlos Gershenson, Nelson Fernández
2012 J jnl
Complex.
Carlos Gershenson, Nelson Fernández
2012 J jnl
Complex.
Carlos Gershenson
2012 J jnl
Complex.
Carlos Gershenson
2012 J jnl
Complex.
Carlos Gershenson
2012 conf
Complex
Igor Lugo, Carlos Gershenson
2012 J jnl
Theory Biosci.
Carlos Gershenson
2012 C conf
CiE
Bruce Edmonds, Carlos Gershenson
2012 J jnl
CoRR
Bruce Edmonds, Carlos Gershenson
2012 J jnl
Entropy
Héctor Zenil, Carlos Gershenson, James A. R. Marshall, David A. Rosenblueth
2012 J jnl
CoRR
Keith Douglas Farnsworth, John Nelson, Carlos Gershenson
2012 J jnl
CoRR
Michele Amoretti, Carlos Gershenson
2012 J jnl
Complex.
Carlos Gershenson
2012 J jnl
Complex.
Carlos Gershenson, David A. Rosenblueth
2011 J jnl
Complex Syst.
David A. Rosenblueth, Carlos Gershenson
2011 J jnl
CoRR
Carlos Gershenson
2011 J jnl
CoRR
Carlos Gershenson, Mikhail Prokopenko
2011 J jnl
Artif. Life
Carlos Gershenson, Mikhail Prokopenko
2011 J jnl
CoRR
Carlos Gershenson
2011 J jnl
Complex.
Carlos Gershenson
2011 J jnl
Complex.
Carlos Gershenson
2011 J jnl
Complex.
Carlos Gershenson
2011 J jnl
Complex.
Carlos Gershenson
2011 J jnl
Res. Comput. Sci.
Caleb Rascón, Carlos Gershenson, Héctor H. Avilés, Iván V. Meza, Lisset Salinas, Luis A. Pineda, Montserrat Alvarado-González
2011 J jnl
CoRR
Carlos Gershenson
2011 J jnl
Artif. Life
Rodrigo Poblanno-Balp, Carlos Gershenson
2011 J jnl
Complex.
Carlos Gershenson
2011 J jnl
CoRR
Chris Marriott, Carlos Gershenson
2011 conf
ECAL
Chris Marriott, Carlos Gershenson
2011 ed.
IWSOS
Christian Bettstetter, Carlos Gershenson
2011 J jnl
CoRR
Carlos Gershenson, David A. Rosenblueth
2011 J jnl
Complex.
Carlos Gershenson
2011 J jnl
Int. J. Artif. Life Res.
Carlos Gershenson
2010 J jnl
Complex.
Carlos Gershenson
2010 J jnl
Complex.
Carlos Gershenson
2010 J jnl
Complex.
Carlos Gershenson
2010 J jnl
CoRR
Carlos Gershenson
2010 J jnl
Paladyn J. Behav. Robotics
Carlos Gershenson
2010 C conf
ALIFE
Rodrigo Poblanno-Balp, Carlos Gershenson
2010 J jnl
Complex.
Carlos Gershenson
2010 J jnl
Complex.
Carlos Gershenson
2010 J jnl
Complex.
Carlos Gershenson
2009 J jnl
CoRR
Carlos Gershenson, David A. Rosenblueth
2009 J jnl
CoRR
Carlos Gershenson
2009 J jnl
CoRR
Carlos Gershenson
2008 J jnl
Artif. Life
Carlos Gershenson, Tom Lenaerts
2008 ch.
Advances in Applied Self-organizing Systems
Seung-Bae Cools, Carlos Gershenson, Bart D'Hooghe
2007 conf
HICSS
Marko A. Rodriguez, Daniel J. Steinbock, Jennifer H. Watkins, Carlos Gershenson, Johan Bollen, Victor Grey, Brad deGraf
2007 J jnl
CoRR
Carlos Gershenson
2007 J jnl
CoRR
Marko A. Rodriguez, Jennifer H. Watkins, Johan Bollen, Carlos Gershenson
2006 J jnl
CoRR
Francis Heylighen, Paul Cilliers, Carlos Gershenson
2006 J jnl
CoRR
Seung-Bae Cools, Carlos Gershenson, Bart D'Hooghe
2005 J jnl
CoRR
Carlos Gershenson
2005 J jnl
Complex Syst.
Carlos Gershenson
2005 J jnl
CoRR
Carlos Gershenson, Stuart A. Kauffman, Ilya Shmulevich
2004 J jnl
Cogn. Syst. Res.
Carlos Gershenson
2004 J jnl
CoRR
Carlos Gershenson
2004 J jnl
CoRR
Carlos Gershenson, Francis Heylighen
2004 conf
IBERAMIA
Carlos Rubén de la Mora-Basáñez, Carlos Gershenson, Angelica Garcia-Vega
2004 J jnl
CoRR
Carlos Rubén de la Mora-Basáñez, Carlos Gershenson, Angelica Garcia-Vega
2004 J jnl
CoRR
Carlos Gershenson
2003 J jnl
CoRR
Carlos Gershenson
2003 A* conf
IJCAI
Carlos Gershenson
2003 J jnl
CoRR
Atin Das, Gottfried Mayer-Kress, Carlos Gershenson, Pritha Das
2003 J jnl
CoRR
Carlos Gershenson, Jan Broekaert, Diederik Aerts
2003 conf
ECAL
Carlos Gershenson, Jan Broekaert, Diederik Aerts
2003 J jnl
IEEE Intell. Syst.
Steffen Staab, Francis Heylighen, Carlos Gershenson, Gary William Flake, David M. Pennock, Daniel C. Fain, David De Roure, Karl Aberer, Wei-Min Shen, Olivier Dousse, Patrick Thiran
2003 J jnl
CoRR
Carlos Gershenson
2003 J jnl
CoRR
Carlos Gershenson
2003 J jnl
CoRR
Carlos Gershenson
2003 J jnl
CoRR
Carlos Gershenson, Gottfried Mayer-Kress, Atin Das, Pritha Das, Matus Marko
2003 conf
ECAL
Carlos Gershenson, Francis Heylighen
2003 J jnl
CoRR
Carlos Gershenson, Francis Heylighen
2002 J jnl
CoRR
Carlos Gershenson
2002 J jnl
CoRR
Carlos Gershenson, Pedro Pablo González Pérez, José Negrete Martínez
2002 J jnl
CoRR
Carlos Gershenson
2002 J jnl
CoRR
Carlos Gershenson
2002 J jnl
CoRR
Carlos Gershenson
2002 J jnl
CoRR
Carlos Gershenson, Pedro Pablo González Pérez
2002 J jnl
CoRR
Pedro Pablo González Pérez, Maura Cárdenas-García, Carlos Gershenson, Jaime Lagunez-Otero
2002 J jnl
CoRR
Pedro Pablo González Pérez, Carlos Gershenson, Maura Cárdenas-García, Jaime Lagunez-Otero
2002 J jnl
CoRR
Atin Das, Matus Marko, Andrej Probst, Mason A. Porter, Carlos Gershenson
2002 J jnl
J. Artif. Soc. Soc. Simul.
Carlos Gershenson
2002 J jnl
CoRR
Carlos Gershenson, Pedro Pablo González Pérez, José Negrete Martínez
2002 J jnl
CoRR
Matus Marko, Mason A. Porter, Andrej Probst, Carlos Gershenson, Atin Das
2001 J jnl
CoRR
Carlos Gershenson
tests/integration/test_base_extractor.py
← Index tests/integration/test_base_extractor.py python
"""
Integration tests for the base Extractor class.
"""
import pytest
import hashlib
import math
from unittest.mock import Mock, patch, MagicMock
from collections import Counter

pytestmark = [pytest.mark.integration]


class TestExtractorStaticMethods:
    """Tests for static methods in Extractor class."""

    def test_process_binary_string_printable(self):
        """Test processing a printable binary string."""
        from redb.extractors.extractor import Extractor

        # Test with printable ASCII characters
        input_bytes = b"Hello World\x00\x00\x00"
        result = Extractor.process_binary_string(input_bytes)
        assert result == "Hello World"

    def test_process_binary_string_non_printable(self):
        """Test processing a string with non-printable characters."""
        from redb.extractors.extractor import Extractor

        # Test with non-printable characters
        input_bytes = b"\x01\x02Hello\x00"
        result = Extractor.process_binary_string(input_bytes)
        assert "\\x01" in result
        assert "\\x02" in result
        assert "Hello" in result

    def test_process_binary_string_empty(self):
        """Test processing an empty binary string."""
        from redb.extractors.extractor import Extractor

        input_bytes = b"\x00\x00\x00"
        result = Extractor.process_binary_string(input_bytes)
        assert result == ""

    def test_process_binary_string_all_printable(self):
        """Test processing a fully printable string."""
        from redb.extractors.extractor import Extractor

        input_bytes = b"TestString123"
        result = Extractor.process_binary_string(input_bytes)
        assert result == "TestString123"

    def test_remove_non_utf8_valid(self):
        """Test removing non-UTF8 characters from valid UTF8 string."""
        from redb.extractors.extractor import Extractor

        input_bytes = b"Hello World"
        result = Extractor.remove_non_utf8(input_bytes)
        assert result == b"Hello World"

    def test_remove_non_utf8_with_invalid(self):
        """Test removing non-UTF8 characters from mixed string."""
        from redb.extractors.extractor import Extractor

        # Mix of valid UTF8 and invalid bytes
        input_bytes = b"Hello\xff\xfeWorld"
        result = Extractor.remove_non_utf8(input_bytes)
        # Should remove the invalid bytes
        assert b"\xff" not in result
        assert b"\xfe" not in result
        assert b"Hello" in result
        assert b"World" in result

    def test_remove_non_utf8_empty(self):
        """Test removing non-UTF8 from empty string."""
        from redb.extractors.extractor import Extractor

        result = Extractor.remove_non_utf8(b"")
        assert result == b""


class TestExtractorEntropyCalculation:
    """Tests for entropy calculation in Extractor class."""

    def test_calculate_entropy_empty_data(self, elf_binary_path, mock_logger):
        """Test entropy calculation with empty data."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(elf_binary_path, mock_logger)
            result = extractor.calculate_entropy(b"")
            assert result == 0.0

    def test_calculate_entropy_uniform_data(self, elf_binary_path, mock_logger):
        """Test entropy calculation with uniform (low entropy) data."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(elf_binary_path, mock_logger)
            # All same bytes = 0 entropy
            uniform_data = b"\x00" * 256
            result = extractor.calculate_entropy(uniform_data)
            assert result == 0.0

    def test_calculate_entropy_random_data(self, elf_binary_path, mock_logger, high_entropy_data):
        """Test entropy calculation with random (high entropy) data."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(elf_binary_path, mock_logger)
            result = extractor.calculate_entropy(high_entropy_data)
            # Random data should have entropy close to 8 (max for bytes)
            assert result > 7.0

    def test_calculate_entropy_binary_data(self, elf_binary_path, mock_logger):
        """Test entropy calculation with binary data."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(elf_binary_path, mock_logger)
            # Two equally distributed values = 1 bit entropy
            binary_data = b"\x00\x01" * 128
            result = extractor.calculate_entropy(binary_data)
            assert abs(result - 1.0) < 0.01

    def test_calculate_entropy_string_data(self, elf_binary_path, mock_logger):
        """Test entropy calculation with string data."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(elf_binary_path, mock_logger)
            # String with two equally distributed characters
            string_data = "ab" * 100
            result = extractor.calculate_entropy(string_data)
            assert abs(result - 1.0) < 0.01


class TestExtractorInitialization:
    """Tests for Extractor initialization."""

    def test_extractor_hashes_computed_on_init(self, elf_binary_path, mock_logger, known_hashes):
        """Test that hashes are computed during initialization."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(elf_binary_path, mock_logger)

            assert extractor.md5 == known_hashes['md5']
            assert extractor.sha1 == known_hashes['sha1']
            assert extractor.sha256 == known_hashes['sha256']

    def test_extractor_hash_dataclass_created(self, elf_binary_path, mock_logger, known_hashes):
        """Test that Hash dataclass is created during initialization."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(elf_binary_path, mock_logger)

            assert extractor.hash.md5 == known_hashes['md5']
            assert extractor.hash.sha1 == known_hashes['sha1']
            assert extractor.hash.sha256 == known_hashes['sha256']

    def test_extractor_binary_cached_property(self, elf_binary_path, mock_logger, elf_binary_content):
        """Test that binary content is loaded as cached property."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(elf_binary_path, mock_logger)

            # Access binary property
            binary = extractor.binary
            assert binary == elf_binary_content

            # Second access should return cached value (same id)
            assert extractor.binary is binary

    def test_extractor_with_exporters(self, elf_binary_path, mock_logger, mock_print_exporter):
        """Test extractor initialization with exporters."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(
                elf_binary_path,
                mock_logger,
                exporters=[mock_print_exporter]
            )

            assert len(extractor.exporters) == 1
            assert extractor.exporters[0] is mock_print_exporter

    def test_extractor_with_index_prefix(self, elf_binary_path, mock_logger):
        """Test extractor initialization with custom index prefix."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(
                elf_binary_path,
                mock_logger,
                index_prefix="custom_prefix"
            )

            assert "custom_prefix" in extractor.elastic_index

    def test_extractor_known_benign_flag(self, elf_binary_path, mock_logger):
        """Test extractor with known_benign flag."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(
                elf_binary_path,
                mock_logger,
                known_benign=True
            )

            assert extractor.known_benign is True
            assert extractor.known_malicious is False

    def test_extractor_known_malicious_flag(self, elf_binary_path, mock_logger):
        """Test extractor with known_malicious flag."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(
                elf_binary_path,
                mock_logger,
                known_malicious=True
            )

            assert extractor.known_benign is False
            assert extractor.known_malicious is True


class TestExtractorExportData:
    """Tests for export_data method."""

    def test_export_data_with_print_exporter(self, elf_binary_path, mock_logger, mock_print_exporter, capsys):
        """Test export_data with PrintExporter."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(
                elf_binary_path,
                mock_logger,
                exporters=[mock_print_exporter]
            )

            result = extractor.export_data()
            # Should succeed with PrintExporter
            assert result is True

    def test_export_data_no_exporters(self, elf_binary_path, mock_logger):
        """Test export_data with no exporters configured."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(
                elf_binary_path,
                mock_logger,
                exporters=[]
            )

            result = extractor.export_data()
            # Should succeed with no exporters (nothing to export)
            assert result is True


class TestExtractorEdgeCases:
    """Tests for edge cases in Extractor class."""

    def test_extractor_with_nonexistent_file(self, mock_logger):
        """Test extractor with non-existent file."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            with pytest.raises(FileNotFoundError):
                BasicPropertiesExtractor("/nonexistent/file.bin", mock_logger)

    def test_entropy_none_data(self, elf_binary_path, mock_logger):
        """Test entropy calculation with None returns 0."""
        from redb.extractors.basicproperties import BasicPropertiesExtractor

        with patch('redb.settings.ELASTIC_BINARIES_COLLECTION', 'test'):
            extractor = BasicPropertiesExtractor(elf_binary_path, mock_logger)
            result = extractor.calculate_entropy(None)
            assert result == 0.0

    def test_process_binary_string_high_bytes(self):
        """Test processing binary string with high byte values."""
        from redb.extractors.extractor import Extractor

        # Characters above 126 are non-printable
        input_bytes = b"\x7f\x80\x81\xff"
        result = Extractor.process_binary_string(input_bytes)
        assert "\\x7f" in result
        assert "\\x80" in result
        assert "\\xff" in result