import unittest
from modelverse_state.main import ModelverseState

class TestReadValue(unittest.TestCase):
    def setUp(self):
        self.mvs = ModelverseState()

    def test_read_value_different_id_simple(self):
        id1 = self.mvs.create_nodevalue(1)
        id2 = self.mvs.create_nodevalue(2)
        assert id1 != None
        assert id2 != None
        
        v1 = self.mvs.read_value(id1)
        v2 = self.mvs.read_value(id2)
        assert v1 == 1
        assert v2 == 2

    def test_read_value_integer_ib_negative(self):
        # Just within range
        for i in range(-2**63, -2**63 + 10):
            id1 = self.mvs.create_nodevalue(i)
            assert id1 != None

            v = self.mvs.read_value(id1)
            assert v == i

    def test_read_value_integer_ib_zero(self):
        # Nicely within range
        for i in range(-10, 10):
            id1 = self.mvs.create_nodevalue(i)
            assert id1 != None

            v = self.mvs.read_value(id1)
            assert v == i

    def test_read_value_integer_ib_positive(self):
        # Just within range
        for i in range(2**63-10, 2**63):
            id1 = self.mvs.create_nodevalue(i)
            assert id1 != None

            v = self.mvs.read_value(id1)
            assert v == i

    def test_read_value_boolean(self):
        id1 = self.mvs.create_nodevalue(True)
        id2 = self.mvs.create_nodevalue(False)
        assert id1 != None
        assert id2 != None

        v1 = self.mvs.read_value(id1)
        v2 = self.mvs.read_value(id2)
        assert v1 == True
        assert v2 == False

    def test_read_nodevalue_boolean_same(self):
        id1 = self.mvs.create_nodevalue(True)
        id2 = self.mvs.create_nodevalue(True)
        assert id1 != None
        assert id2 != None

        v1 = self.mvs.read_value(id1)
        v2 = self.mvs.read_value(id2)
        assert v1 == True
        assert v2 == True

    def test_read_value_no_exist(self):
        v1 = self.mvs.read_value(100000)
        assert v1 == None

    def test_read_value_no_value(self):
        id1 = self.mvs.create_node()
        assert id1 != None

        v1 = self.mvs.read_value(id1)
        assert v1 == None
