Package de.danielkullmann.hackvm.solutions

Source Code of de.danielkullmann.hackvm.solutions.AddTwoAndPrint

package de.danielkullmann.hackvm.solutions;

import java.util.Random;
import java.util.Stack;

import de.danielkullmann.hackvm.HackVM;
import de.danielkullmann.hackvm.SolutionCheck;
import de.danielkullmann.hackvm.VMState;

public class AddTwoAndPrint implements SolutionCheck {

  @Override
  public boolean check(String program) {
    Random r = new Random();
    HackVM vm = new HackVM();
    for (int i = 0; i < 100; i++) {
      int n1 = r.nextInt();
      int n2 = r.nextInt();
      Stack<Integer> stack = HackVM.parseStack( n1 + " " + n2 );
      VMState result = vm.execute(program, stack, null);
      if ( ! result.getOutput().equals( "" + (n1+n2) ) ) return false;
    }
    return true;
  }

}
TOP

Related Classes of de.danielkullmann.hackvm.solutions.AddTwoAndPrint

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.