MCPcopy Create free account
hub / github.com/QuipNetwork/xquad / test_range_loop

Method test_range_loop

xqvm_py/tests/test_executor.py:149–169  ·  view source on GitHub ↗

RANGE creates loop with values [start, start+count).

(self)

Source from the content-addressed store, hash-verified

147 assert ex.state.get_register(0) == 99
148
149 def test_range_loop(self):
150 """RANGE creates loop with values [start, start+count)."""
151 # Sum 0+1+2+3+4 = 10
152 ex = run_program(
153 [
154 Instruction(Opcode.PUSH1, (0,)), # Sum accumulator
155 Instruction(Opcode.STOW, (0,)),
156 Instruction(Opcode.PUSH1, (0,)), # Start
157 Instruction(Opcode.PUSH1, (5,)), # Count
158 Instruction(Opcode.RANGE),
159 Instruction(Opcode.TARGET, ()), # Loop body
160 Instruction(Opcode.LVAL, (1,)), # i -> r1
161 Instruction(Opcode.LOAD, (0,)), # Load sum
162 Instruction(Opcode.LOAD, (1,)), # Load i
163 Instruction(Opcode.ADD),
164 Instruction(Opcode.STOW, (0,)), # Store sum
165 Instruction(Opcode.NEXT),
166 Instruction(Opcode.HALT),
167 ]
168 )
169 assert ex.state.get_register(0) == 10
170
171 def test_range_count_zero_skips_body(self):
172 """RANGE with count=0 skips the loop body entirely."""

Callers

nothing calls this directly

Calls 3

run_programFunction · 0.90
InstructionClass · 0.90
get_registerMethod · 0.80

Tested by

no test coverage detected