# Written by: kfont015
# Last updated: kfont015

import unittest
from pytlex_core import Signal


class SignalTestCase(unittest.TestCase):

    """
        Testing constructor
    """

    def test_null_signal_class(self):
        with self.assertRaises(Exception):
            Signal.Event(None, None)

    def test_invalid_signal_id(self):
        with self.assertRaises(Exception):
            Signal.Event(0, "Valid string")

    def test_invalid_signal_string(self):
        with self.assertRaises(Exception):
            Signal.Event(2, "")

    """
        Testing the getters and setters
    """

    def test_signal_id_getter(self):
        signal = Signal.Signal(1, "SignalValid")
        assert signal.signal_id == 1

    def test_signal_string_getter(self):
        signal = Signal.Signal(1, "SignalValid")
        assert signal.signal_string == "SignalValid"

    def test_signal_id_setter(self):
        signal = Signal.Signal(1, "SignalValid")
        signal.signal_id = 5
        assert signal.signal_id == 5

    def test_signal_string_setter(self):
        signal = Signal.Signal(1, "SignalValid")
        signal.signal_string = "HelloWorld"
        assert signal.signal_string == "HelloWorld"


    """
       Test custom methods
    """

    def test_get_id_str(self):
        signal = Signal.Signal(1, "testString")
        assert signal.get_id_str() == "sid 1"

    def test_to_json(self):
        test_value = "{\"Id\": \"sid 1\", \"signalString\": \"testString\"}"
        signal = Signal.Signal(1, "testString")
        assert signal.to_json() == test_value

    def test__str__(self):
        test_value = "Signal: {Id = 1, String = testString}"
        signal = Signal.Signal(1, "testString")
        assert str(signal) == test_value

    """
       Test object comparison
    """

    def test_signal_object_equal(self):
        signal1 = Signal.Signal(1, "TEST_1")
        signal2 = Signal.Signal(1, "TEST_1")
        assert signal1 == signal2

    def test_signal_id_object_not_equal(self):
        signal1 = Signal.Signal(1, "TEST_1")
        signal2 = Signal.Signal(2, "TEST_1")
        assert signal1 != signal2

    def test_signal_string_object_not_equal(self):
        signal1 = Signal.Signal(1, "TEST_1")
        signal2 = Signal.Signal(1, "TEST_2")
        assert signal1 != signal2


if __name__ == '__main__':
    unittest.main()
