FunctionSignature { public int match(FunctionSignature functionSignature) { List<ExprType> functionTypeList = functionSignature.getParamTypeList(); if (!functionName.equals(functionSignature.getFunctionName()) || paramTypeList.size() != functionTypeList.size()) { return NOT_MATCH; } int matchDegree = EXACTLY_MATCH; for (int i = 0; i < paramTypeList.size(); i++) { ExprType paramType = paramTypeList.get(i); ExprType funcType = functionTypeList.get(i); int match = WideningTypeRule.distance(paramType, funcType); if (match == WideningTypeRule.IMPOSSIBLE_WIDENING) { return NOT_MATCH; } else { matchDegree += match; } } return matchDegree; }  int match(FunctionSignature functionSignature); String formatTypes(); static final Integer NOT_MATCH; static final Integer EXACTLY_MATCH; }
@Test void signature_name_not_match() { when(funcSignature.getFunctionName()).thenReturn(FunctionName.of(("diff"))); FunctionSignature unresolvedFunSig = new FunctionSignature(this.unresolvedFuncName, unresolvedParamTypeList); assertEquals(NOT_MATCH, unresolvedFunSig.match(funcSignature)); }
@Test void signature_arguments_size_not_match() { when(funcSignature.getFunctionName()).thenReturn(unresolvedFuncName); when(funcSignature.getParamTypeList()).thenReturn(funcParamTypeList); when(funcParamTypeList.size()).thenReturn(1); FunctionSignature unresolvedFunSig = new FunctionSignature(unresolvedFuncName, unresolvedParamTypeList); assertEquals(NOT_MATCH, unresolvedFunSig.match(funcSignature)); }
@Test void signature_exactly_match() { when(funcSignature.getFunctionName()).thenReturn(unresolvedFuncName); when(funcSignature.getParamTypeList()).thenReturn(unresolvedParamTypeList); FunctionSignature unresolvedFunSig = new FunctionSignature(unresolvedFuncName, unresolvedParamTypeList); assertEquals(EXACTLY_MATCH, unresolvedFunSig.match(funcSignature)); }
@Test void signature_not_match() { when(funcSignature.getFunctionName()).thenReturn(unresolvedFuncName); when(funcSignature.getParamTypeList()) .thenReturn(Arrays.asList(ExprCoreType.STRING, ExprCoreType.STRING)); FunctionSignature unresolvedFunSig = new FunctionSignature(unresolvedFuncName, unresolvedParamTypeList); assertEquals(NOT_MATCH, unresolvedFunSig.match(funcSignature)); }
@Test void signature_widening_match() { when(funcSignature.getFunctionName()).thenReturn(unresolvedFuncName); when(funcSignature.getParamTypeList()) .thenReturn(Arrays.asList(ExprCoreType.FLOAT, ExprCoreType.FLOAT)); FunctionSignature unresolvedFunSig = new FunctionSignature(unresolvedFuncName, unresolvedParamTypeList); assertEquals(2, unresolvedFunSig.match(funcSignature)); }