コード例 #1
0
ファイル: state.py プロジェクト: nayabur/pyshgp
    def __init__(self, type_library: PushTypeLibrary, push_config: PushConfig):
        super().__init__()
        self.stdout = ""
        self.inputs = []
        self.untyped = deque([])
        self.type_library = type_library
        self.push_config = push_config

        for name, push_type in type_library.items():
            self[name] = PushStack(push_type, push_config)
コード例 #2
0
def str_stack(atoms, push_config):
    return PushStack(PushStr, push_config)
コード例 #3
0
ファイル: test_stack.py プロジェクト: bmetevier/pyshgp
def str_stack(atoms):
    return PushStack(PushStr)
コード例 #4
0
 def test_large_str(self, str_stack: PushStack):
     s = "largestr" * 1000
     str_stack.push(s)
     assert len(str_stack.pop()) != len(s)
コード例 #5
0
 def test_set_nth_oob(self, str_stack: PushStack):
     with pytest.raises(IndexError):
         str_stack.push("a").push("b").push("c").set_nth(10, "z")
コード例 #6
0
 def test_insert_oob(self, str_stack: PushStack):
     str_stack.push("a").push("b").push("c").insert(10, "z")
     assert len(str_stack) == 4
     assert str_stack.nth(1) == "b"
     assert str_stack.nth(3) == "z"
コード例 #7
0
 def test_top(self, int_stack: PushStack):
     int_stack.push(5).push(-10)
     assert int_stack.top() == -10
コード例 #8
0
 def test_nth(self, int_stack: PushStack):
     int_stack.push(5).push(4).push(3)
     assert int_stack.nth(1) == 4
コード例 #9
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_top(self, int_stack: PushStack):
     int_stack.push(5).push(-10)
     assert int_stack.top() == -10
コード例 #10
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_nth_oob(self, int_stack: PushStack):
     int_stack.push(5)
     assert int_stack.nth(1) == Token.no_stack_item
コード例 #11
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_nth(self, int_stack: PushStack):
     int_stack.push(5).push(4).push(3)
     assert int_stack.nth(1) == 4
コード例 #12
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_push_wrong_type(self, int_stack: PushStack):
     with pytest.raises(PushError):
         int_stack.push("zz")
コード例 #13
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_push(self, int_stack: PushStack):
     int_stack.push(5)
     assert len(int_stack) == 1
コード例 #14
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_init_values(self):
     stack = PushStack(PushStr, ["bottom", "middle", "top"])
     assert stack.top() == "top"
     assert list(stack) == ["bottom", "middle", "top"]
コード例 #15
0
ファイル: test_stack.py プロジェクト: bmetevier/pyshgp
def int_stack(atoms):
    return PushStack(PushInt)
コード例 #16
0
 def test_push(self, int_stack: PushStack):
     int_stack.push(5)
     assert len(int_stack) == 1
コード例 #17
0
 def test_push_wrong_type(self, int_stack: PushStack):
     with pytest.raises(PushError):
         int_stack.push("zz")
コード例 #18
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_top_of_empty(self, int_stack: PushStack):
     assert int_stack.top() == Token.no_stack_item
コード例 #19
0
 def test_nth_oob(self, int_stack: PushStack):
     int_stack.push(5)
     assert int_stack.nth(1) == Token.no_stack_item
コード例 #20
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_insert_oob(self, str_stack: PushStack):
     str_stack.push("a").push("b").push("c").insert(10, "z")
     assert len(str_stack) == 4
     assert str_stack.nth(1) == "b"
     assert str_stack.nth(3) == "z"
コード例 #21
0
 def test_top_of_empty(self, int_stack: PushStack):
     assert int_stack.top() == Token.no_stack_item
コード例 #22
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_set_nth(self, str_stack: PushStack):
     str_stack.push("a").push("b").push("c").push("d").set_nth(1, "z")
     assert len(str_stack) == 4
     assert str_stack.nth(1) == "z"
コード例 #23
0
 def test_set_nth(self, str_stack: PushStack):
     str_stack.push("a").push("b").push("c").push("d").set_nth(1, "z")
     assert len(str_stack) == 4
     assert str_stack.nth(1) == "z"
コード例 #24
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_set_nth_oob(self, str_stack: PushStack):
     with pytest.raises(IndexError):
         str_stack.push("a").push("b").push("c").set_nth(10, "z")
コード例 #25
0
 def test_flush(self, int_stack: PushStack):
     int_stack.push(1).push(-1).flush()
     assert len(int_stack) == 0
コード例 #26
0
ファイル: test_stack.py プロジェクト: erp12/Pysh
 def test_flush(self, int_stack: PushStack):
     int_stack.push(1).push(-1).flush()
     assert len(int_stack) == 0
コード例 #27
0
def int_stack(atoms, push_config):
    return PushStack(PushInt, push_config)
コード例 #28
0
ファイル: state.py プロジェクト: bmetevier/pyshgp
 def _register_stack_of_type(self, push_type: PushType):
     """Add a new stack."""
     self[push_type.name] = PushStack(push_type)