Package de.danielkullmann.hackvm

Examples of de.danielkullmann.hackvm.HackVM.execute()


public class Test3 extends TestCase {

  public void testFibonacci() {
    HackVM vm = new HackVM();
    VMState result = vm.execute("1p 48*P 1p 48*P 2p 48*P 3p 48*P 5p", "", "");
    assertNull( result.getError() );
    assertEquals( result.getOutput(), "1 1 2 3 5" );
  }

  public void testReverseList() {
View Full Code Here


  }

  public void testReverseList() {
    HackVM vm = new HackVM();
    //                           setup   loop loop end?      copy one
    VMState result = vm.execute("0^2v+1- 1^1^ 1^1^:0^1-*55*? <1v<2^>2^> 1v1+ 1v1- 8$!", "5, 1024", "1024=5,6,7,8,9");
    HashMap<Integer, Integer> m = HackVM.parseMemory( "1024=9,8,7,6,5" );
    assertNull( result.getError() );
    assertEquals( result.getMemory(), m );
  }

View Full Code Here

    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;
  }
View Full Code Here

  private void run() {
    HackVM vm = new HackVM();
    //          setup   loop loop end?      copy one
    vm.addObserver( this );
    VMState result = vm.execute("0^2v+1- 1^1^ 1^1^:0^1-*55*? <1v<2^>2^> 1v1+ 1v1- 8$!", "5, 1024", "1024=5,6,7,8,9");
    System.out.println( result.getError() );
    System.out.println( result.getMemory() );
  }

  @Override
View Full Code Here

public class Test1 extends TestCase {

  public void test1() {
    HackVM vm = new HackVM();

    VMState result = vm.execute( " ", "", null );
    assertNull( result.getError() );
    assertTrue( result.getStack().size() == 0 );

    result = vm.execute( "p", "1", null );
    assertNull( result.getError() );
View Full Code Here

    VMState result = vm.execute( " ", "", null );
    assertNull( result.getError() );
    assertTrue( result.getStack().size() == 0 );

    result = vm.execute( "p", "1", null );
    assertNull( result.getError() );
    assertTrue( result.getStack().size() == 0 );
    assertTrue( result.getOutput().equals( "1" ) );

    result = vm.execute( "P", "65", null );
View Full Code Here

    result = vm.execute( "p", "1", null );
    assertNull( result.getError() );
    assertTrue( result.getStack().size() == 0 );
    assertTrue( result.getOutput().equals( "1" ) );

    result = vm.execute( "P", "65", null );
    assertNull( result.getError() );
    assertTrue( result.getStack().size() == 0 );
    assertTrue( result.getOutput().equals( "A" ) );

    for (int i = 0; i < 10; i++) {
View Full Code Here

    assertNull( result.getError() );
    assertTrue( result.getStack().size() == 0 );
    assertTrue( result.getOutput().equals( "A" ) );

    for (int i = 0; i < 10; i++) {
      result = vm.execute( ""+i, "", null );
      assertNull( result.getError() );
      assertTrue( result.getStack().size() == 1 );
      assertTrue( result.getStack().pop() == i );
    }
View Full Code Here

      assertNull( result.getError() );
      assertTrue( result.getStack().size() == 1 );
      assertTrue( result.getStack().pop() == i );
    }

    result = vm.execute( "+", "7, 8", null );
    assertNull( result.getError() );
    assertTrue( result.getStack().size() == 1 );
    assertTrue( result.getStack().peek() == 15 );

    result = vm.execute( "-", "7, 8", null );
View Full Code Here

    result = vm.execute( "+", "7, 8", null );
    assertNull( result.getError() );
    assertTrue( result.getStack().size() == 1 );
    assertTrue( result.getStack().peek() == 15 );

    result = vm.execute( "-", "7, 8", null );
    assertNull( result.getError() );
    assertTrue( result.getStack().size() == 1 );
    assertTrue( result.getStack().peek() == -1 );

    result = vm.execute( "*", "7, 8", null );
View Full Code Here

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.