diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-02-06 15:59:14 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-02-06 15:59:14 +0100 |
commit | cb18a346ddb89b604251564f59968d4d62b065a3 (patch) | |
tree | f16c80cfd2903c9520bb26c0e60d2513e59d712e /config-model/src/test/java/com | |
parent | 063b679c7cac060c44121a2ee7ce5a5d4b81849b (diff) |
Cleanup
Diffstat (limited to 'config-model/src/test/java/com')
-rw-r--r-- | config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java index 5c654f09c51..db3b12db1bf 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/RankingExpressionTypeValidatorTestCase.java @@ -12,7 +12,7 @@ import static org.junit.Assert.fail; public class RankingExpressionTypeValidatorTestCase { @Test - public void tensorTypeValidation() throws Exception { + public void tensorFirstPhaseMustProduceDouble() throws Exception { try { RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry); @@ -39,4 +39,66 @@ public class RankingExpressionTypeValidatorTestCase { } } + @Test + public void tensorSecondPhaseMustProduceDouble() throws Exception { + try { + RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); + SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry); + searchBuilder.importString(joinLines( + "search test {", + " document test { ", + " field a type tensor(x[],y[]) {", + " indexing: attribute", + " }", + " }", + " rank-profile my_rank_profile {", + " first-phase {", + " expression: sum(attribute(a))", + " }", + " second-phase {", + " expression: attribute(a)", + " }", + " }", + "}" + )); + searchBuilder.build(); + fail("Expected exception"); + } + catch (IllegalArgumentException expected) { + assertEquals("In search definition 'test', rank profile 'my_rank_profile': The second-phase expression must produce a double (a tensor with no dimensions), but produces tensor(x[],y[])", + Exceptions.toMessageString(expected)); + } + } + + @Test + public void tensorConditionsMustHaveTypeCompatibleBranches() throws Exception { + try { + RankProfileRegistry rankProfileRegistry = new RankProfileRegistry(); + SearchBuilder searchBuilder = new SearchBuilder(rankProfileRegistry); + searchBuilder.importString(joinLines( + "search test {", + " document test { ", + " field a type tensor(x[],y[]) {", + " indexing: attribute", + " }", + " field b type tensor(z[10]) {", + " indexing: attribute", + " }", + " }", + " rank-profile my_rank_profile {", + " first-phase {", + " expression: sum(if(1>0, attribute(a), attribute(b)))", + " }", + " }", + "}" + )); + searchBuilder.build(); + fail("Expected exception"); + } + catch (IllegalArgumentException expected) { + assertEquals("In search definition 'test', rank profile 'my_rank_profile': The first-phase expression is invalid: An if expression must produce compatible types in both alternatives, but the 'true' type is tensor(x[],y[]) while the 'false' type is tensor(z[10])", + Exceptions.toMessageString(expected)); + } + } + } |