コード例 #1
0
 @Test
 public void testDiv() throws StackRuntimeException {
   List<Instruction> instructions = new ArrayList<Instruction>();
   instructions.add(new Instruction("const", new IntStackValue(5)));
   instructions.add(new Instruction("const", new IntStackValue(2)));
   instructions.add(new Instruction("div"));
   StackMachine machine = new StackMachine(instructions);
   machine.step();
   machine.step();
   machine.step();
   assertEquals(new Integer(2), machine.getStack().pop().getValue());
   assertEquals(0, machine.getStack().size());
 }
コード例 #2
0
 @Test
 public void testJezFail() throws StackRuntimeException {
   List<Instruction> instructions = new ArrayList<Instruction>();
   instructions.add(new Instruction("const", new IntStackValue(1)));
   instructions.add(new Instruction("jez", new StringStackValue("fail")));
   instructions.add(new Instruction("const", new IntStackValue(2)));
   instructions.add(new Instruction("label", new StringStackValue("fail")));
   instructions.add(new Instruction("const", new IntStackValue(3)));
   StackMachine machine = new StackMachine(instructions);
   machine.step();
   machine.step();
   machine.step();
   assertEquals(new Integer(2), machine.getStack().pop().getValue());
 }
コード例 #3
0
 @Test
 public void testLoad() throws StackRuntimeException {
   List<Instruction> instructions = new ArrayList<Instruction>();
   instructions.add(new Instruction("load", new IntStackValue(0)));
   StackMachine machine = new StackMachine(instructions);
   machine.setStore(0, new IntStackValue(2));
   machine.step();
   assertEquals(new Integer(2), machine.getStack().pop().getValue());
 }
コード例 #4
0
 @Test
 public void testInput() throws StackRuntimeException {
   List<Instruction> instructions = new ArrayList<Instruction>();
   instructions.add(new Instruction("input"));
   List<StackValue<?>> input = new ArrayList<StackValue<?>>();
   input.add(new IntStackValue(2));
   StackMachine machine = new StackMachine(instructions, input);
   machine.step();
   assertEquals(new Integer(2), machine.getStack().pop().getValue());
 }