Package org.renjin.invoke.codegen

Source Code of org.renjin.invoke.codegen.OverloadComparatorTest

package org.renjin.invoke.codegen;

import com.google.common.collect.Lists;
import org.junit.Test;
import org.renjin.invoke.model.JvmMethod;
import org.renjin.primitives.Ops;
import org.renjin.primitives.Types;
import org.renjin.primitives.Vectors;
import org.renjin.sexp.PairList;
import org.renjin.sexp.Vector;

import java.util.Collections;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertThat;

public class OverloadComparatorTest {


  @Test
  public void scalarPriority() throws Exception {

    JvmMethod intMethod = new JvmMethod(Ops.class.getMethod("minus", int.class));
    JvmMethod doubleMethod = new JvmMethod(Ops.class.getMethod("minus", double.class));

    List<JvmMethod> list = Lists.newArrayList(doubleMethod, intMethod);

    Collections.sort(list, new OverloadComparator());

    assertThat(list.get(0), is(intMethod));
    assertThat(list.get(1), is(doubleMethod));
  }

  @Test
  public void pairListVsVector() throws Exception {
    JvmMethod vectorMethod = new JvmMethod(Vectors.class.getMethod("asVector", Vector.class, String.class));
    JvmMethod pairListMethod = new JvmMethod(Vectors.class.getMethod("asVector", PairList.class, String.class));

    OverloadComparator comparator = new OverloadComparator();

    assertThat(comparator.compare(vectorMethod, pairListMethod), lessThan(0));
  }
}
TOP

Related Classes of org.renjin.invoke.codegen.OverloadComparatorTest

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.