RANGE creates loop with values [start, start+count).
(self)
| 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.""" |
nothing calls this directly
no test coverage detected