Package org.nutz.el

Source Code of org.nutz.el.RPNTest

package org.nutz.el;

import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.Before;
import org.junit.Test;
import org.nutz.el.arithmetic.ShuntingYard;

public class RPNTest {
  private ShuntingYard sy = null;
 
  @Before
  public void setup(){
    sy = new ShuntingYard();
  }
  private String parseRPN(String val){
    String rpn = "";
    for(Object obj : sy.parseToRPN(val)){
      rpn += obj.toString();
    }
    return rpn;
  }
 
  @Test
  public void simpleRPN() throws IOException{
    assertEquals("11+1+", parseRPN("1+1+1"));
    assertEquals("11-", parseRPN("1-1"));
    assertEquals("11-1-", parseRPN("1-1-1"));
    assertEquals("52%1+",parseRPN("5%2+1"));
    assertEquals("152%+",parseRPN("1+5%2"));
  }
 
  @Test
  public void mulRPn() throws IOException{
    assertEquals("512+4*+3-", parseRPN("5+((1+2)*4)-3"));
    assertEquals("987*+65+412*-3+-*+", parseRPN("9+8*7+(6+5)*(-(4-1*2+3))"));
  }
TOP

Related Classes of org.nutz.el.RPNTest

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.