import unittest
from modelverse_state.main import ModelverseState

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

    def test_create_nodevalue_different_id_simple(self):
        id1 = self.mvs.create_nodevalue(1)
        id2 = self.mvs.create_nodevalue(1)

        assert id1 != None
        assert id2 != None
        assert id1 != id2
        
    def test_create_nodevalue_read(self):
        id1 = self.mvs.create_nodevalue(1)
        assert id1 != None
        val = self.mvs.read_value(id1)
        assert val == 1

    def test_create_nodevalue_integer_ib_zero(self):
        # Nicely within range
        v = set()
        size = 0
        for i in range(-10, 10):
            id1 = self.mvs.create_nodevalue(i)
            assert id1 != None
            size += 1
            v.add(id1)
        assert len(v) == size

    def test_create_nodevalue_boolean(self):
        id1 = self.mvs.create_nodevalue(True)
        id2 = self.mvs.create_nodevalue(False)

        assert id1 != None
        assert id2 != None
        assert id1 != id2
        
    def test_create_nodevalue_boolean_same(self):
        id1 = self.mvs.create_nodevalue(True)
        id2 = self.mvs.create_nodevalue(True)
        
        assert id1 != None
        assert id2 != None
        assert id1 != id2
        
    def test_create_nodevalue_float_keeps_type(self):
        id1 = self.mvs.create_nodevalue(0.0)
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert type(v) == float
        assert v == 0.0

    def test_create_nodevalue_string_empty(self):
        id1 = self.mvs.create_nodevalue("")
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert type(v) == str
        assert v == ""

    def test_create_nodevalue_string_normal(self):
        id1 = self.mvs.create_nodevalue("ABC")
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert type(v) == str
        assert v == "ABC"

    def test_create_nodevalue_string_not_parsed(self):
        id1 = self.mvs.create_nodevalue("1")
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert type(v) == str
        assert v == "1"

        id1 = self.mvs.create_nodevalue("1.0")
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert type(v) == str
        assert v == "1.0"

        id1 = self.mvs.create_nodevalue("-1.0")
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert type(v) == str
        assert v == "-1.0"

        id1 = self.mvs.create_nodevalue("True")
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert type(v) == str
        assert v == "True"

    def test_create_nodevalue_junk(self):
        class Unknown(object):
            pass

        id1 = self.mvs.create_nodevalue(Unknown())
        assert id1 == None

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

    def test_create_nodevalue_action_if(self):
        id1 = self.mvs.create_nodevalue({"value": "if"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "if"}

    def test_create_nodevalue_action_while(self):
        id1 = self.mvs.create_nodevalue({"value": "while"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "while"}

    def test_create_nodevalue_action_assign(self):
        id1 = self.mvs.create_nodevalue({"value": "assign"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "assign"}

    def test_create_nodevalue_action_call(self):
        id1 = self.mvs.create_nodevalue({"value": "call"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "call"}

    def test_create_nodevalue_action_break(self):
        id1 = self.mvs.create_nodevalue({"value": "break"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "break"}

    def test_create_nodevalue_action_continue(self):
        id1 = self.mvs.create_nodevalue({"value": "continue"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "continue"}

    def test_create_nodevalue_action_return(self):
        id1 = self.mvs.create_nodevalue({"value": "return"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "return"}

    def test_create_nodevalue_action_resolve(self):
        id1 = self.mvs.create_nodevalue({"value": "resolve"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "resolve"}

    def test_create_nodevalue_action_access(self):
        id1 = self.mvs.create_nodevalue({"value": "access"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "access"}

    def test_create_nodevalue_action_unknown(self):
        id1 = self.mvs.create_nodevalue({"value": "unknown"})
        assert id1 == None

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

    def test_create_nodevalue_action_input(self):
        id1 = self.mvs.create_nodevalue({"value": "input"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "input"}

    def test_create_nodevalue_action_output(self):
        id1 = self.mvs.create_nodevalue({"value": "output"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "output"}

    def test_create_nodevalue_action_declare(self):
        id1 = self.mvs.create_nodevalue({"value": "declare"})
        assert id1 != None

        v = self.mvs.read_value(id1)
        assert v == {"value": "declare"}
