summaryrefslogtreecommitdiffstats
path: root/config-model/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-02-18 23:34:41 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2017-02-18 23:34:41 +0100
commita0f547c0d7e38e0662d71a197162314bbd3c2f64 (patch)
treeeb12f828326671768a337ad1ce62c6a925506347 /config-model/src
parent9cd49b8ba910378c93b4337d64a478782b10ee47 (diff)
Add a test that proves that macro-inlining is broken.
Diffstat (limited to 'config-model/src')
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java51
1 files changed, 48 insertions, 3 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java
index 95682407597..acf95b5a1c2 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/RankingExpressionInliningTestCase.java
@@ -2,15 +2,12 @@
package com.yahoo.searchdefinition;
import com.yahoo.collections.Pair;
-import com.yahoo.config.model.application.provider.BaseDeployLogger;
import com.yahoo.searchdefinition.derived.AttributeFields;
import com.yahoo.searchdefinition.derived.RawRankProfile;
import com.yahoo.searchdefinition.parser.ParseException;
import org.junit.Test;
-import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import static org.junit.Assert.assertEquals;
@@ -20,6 +17,54 @@ import static org.junit.Assert.assertEquals;
public class RankingExpressionInliningTestCase extends SearchDefinitionTestCase {
@Test
+ public void testMacroInliningPreserveArithemticOrdering() throws ParseException {
+ RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
+ SearchBuilder builder = new SearchBuilder(rankProfileRegistry);
+ builder.importString(
+ "search test {\n" +
+ " document test { \n" +
+ " field a type double { \n" +
+ " indexing: attribute \n" +
+ " }\n" +
+ " field b type double { \n" +
+ " indexing: attribute \n" +
+ " }\n" +
+ " }\n" +
+ " \n" +
+ " rank-profile parent {\n" +
+ " constants {\n" +
+ " p1: 7 \n" +
+ " p2: 0 \n" +
+ " }\n" +
+ " first-phase {\n" +
+ " expression: p1 * add\n" +
+ " }\n" +
+ " macro inline add() {\n" +
+ " expression: 3 + attribute(a) + attribute(b) * mul3\n" +
+ " }\n" +
+ " macro inline mul3() {\n" +
+ " expression: attribute(a) * 3 + singleif\n" +
+ " }\n" +
+ " macro inline singleif() {\n" +
+ " expression: if (p1 < attribute(a), 1, 2) == 0\n" +
+ " }\n" +
+ " }\n" +
+ " rank-profile child inherits parent {\n" +
+ " macro inline add() {\n" +
+ " expression: 9 + attribute(a)\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ "}\n");
+ builder.build();
+ Search s = builder.getSearch();
+
+ RankProfile parent = rankProfileRegistry.getRankProfile(s, "parent").compile();
+ assertEquals("7.0 * (3 + attribute(a) + attribute(b) * (attribute(a) * 3 + if (7.0 < attribute(a), 1, 2) == 0))", parent.getFirstPhaseRanking().getRoot().toString());
+ RankProfile child = rankProfileRegistry.getRankProfile(s, "child").compile();
+ assertEquals("7.0 * (9 + attribute(a))", child.getFirstPhaseRanking().getRoot().toString());
+ }
+ @Test
public void testConstants() throws ParseException {
RankProfileRegistry rankProfileRegistry = new RankProfileRegistry();
SearchBuilder builder = new SearchBuilder(rankProfileRegistry);