From efbc66ca8f36541d9d5f4b0bceeeb1e67643cee6 Mon Sep 17 00:00:00 2001 From: Erick Erickson Date: Thu, 28 Nov 2013 03:17:30 +0000 Subject: [PATCH] SOLR-5488: Added more test info output. Somehow lost some of what I did yesterday git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1546263 13f79535-47bb-0310-9956-ffa450edef68 --- .../analytics/AbstractAnalyticsStatsTest.java | 25 +++- .../apache/solr/analytics/NoFacetTest.java | 129 +++++++++--------- .../analytics/expression/ExpressionTest.java | 50 +++---- .../util/valuesource/FunctionTest.java | 65 +++++---- 4 files changed, 137 insertions(+), 132 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java b/solr/core/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java index 7bba1ff98f5..7c64673422f 100644 --- a/solr/core/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java +++ b/solr/core/src/test/org/apache/solr/analytics/AbstractAnalyticsStatsTest.java @@ -76,12 +76,19 @@ public class AbstractAnalyticsStatsTest extends SolrTestCaseJ4 { static private Document doc; static private XPathFactory xPathFact = XPathFactory.newInstance(); + static private String rawResponse; + public static void setResponse(String response) throws ParserConfigurationException, IOException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); // never forget this! DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.parse(new InputSource(new ByteArrayInputStream(response.getBytes("UTF-8")))); xPathFact = XPathFactory.newInstance(); + rawResponse = response; + } + + protected String getRawResponse() { + return rawResponse; } public Object getStatResult(String section, String name, VAL_TYPE type) throws XPathExpressionException { @@ -93,13 +100,17 @@ public class AbstractAnalyticsStatsTest extends SolrTestCaseJ4 { // VAL_TYPE.DOUBLE, the element in question is 47.0. sb.append("/").append(type.toString()).append("[@name='").append(name).append("']"); String val = xPathFact.newXPath().compile(sb.toString()).evaluate(doc, XPathConstants.STRING).toString(); - switch (type) { - case INTEGER: return Integer.parseInt(val); - case DOUBLE: return Double.parseDouble(val); - case FLOAT: return Float.parseFloat(val); - case LONG: return Long.parseLong(val); - case STRING: return val; - case DATE: return val; + try { + switch (type) { + case INTEGER: return Integer.parseInt(val); + case DOUBLE: return Double.parseDouble(val); + case FLOAT: return Float.parseFloat(val); + case LONG: return Long.parseLong(val); + case STRING: return val; + case DATE: return val; + } + } catch (Exception e) { + fail("Caught exception in getStatResult, xPath = " + sb.toString() + " \nraw data: " + rawResponse); } fail("Unknown type used in getStatResult"); return null; // Really can't get here, but the compiler thinks we can! diff --git a/solr/core/src/test/org/apache/solr/analytics/NoFacetTest.java b/solr/core/src/test/org/apache/solr/analytics/NoFacetTest.java index 0ab1be5c849..986b88d59c8 100644 --- a/solr/core/src/test/org/apache/solr/analytics/NoFacetTest.java +++ b/solr/core/src/test/org/apache/solr/analytics/NoFacetTest.java @@ -143,22 +143,22 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int Double intResult = (Double)getStatResult("sr", "int_id", VAL_TYPE.DOUBLE); Double intTest = (Double)calculateNumberStat(intTestStart, "sum"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long Double longResult = (Double)getStatResult("sr", "long_ld", VAL_TYPE.DOUBLE); Double longTest = (Double)calculateNumberStat(longTestStart, "sum"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float Double floatResult = (Double)getStatResult("sr", "float_fd", VAL_TYPE.DOUBLE); Double floatTest = (Double)calculateNumberStat(floatTestStart, "sum"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double Double doubleResult = (Double)getStatResult("sr", "double_dd", VAL_TYPE.DOUBLE); Double doubleTest = (Double) calculateNumberStat(doubleTestStart, "sum"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); } @Test @@ -166,22 +166,22 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int Double intResult = (Double)getStatResult("sosr", "int_id", VAL_TYPE.DOUBLE); Double intTest = (Double)calculateNumberStat(intTestStart, "sumOfSquares"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long Double longResult = (Double)getStatResult("sosr", "long_ld", VAL_TYPE.DOUBLE); Double longTest = (Double)calculateNumberStat(longTestStart, "sumOfSquares"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float Double floatResult = (Double)getStatResult("sosr", "float_fd", VAL_TYPE.DOUBLE); Double floatTest = (Double)calculateNumberStat(floatTestStart, "sumOfSquares"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double Double doubleResult = (Double)getStatResult("sosr", "double_dd", VAL_TYPE.DOUBLE); Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "sumOfSquares"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); } @Test @@ -189,22 +189,22 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int Double intResult = (Double)getStatResult("mr", "int_id", VAL_TYPE.DOUBLE); Double intTest = (Double)calculateNumberStat(intTestStart, "mean"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long Double longResult = (Double)getStatResult("mr", "long_ld", VAL_TYPE.DOUBLE); Double longTest = (Double)calculateNumberStat(longTestStart, "mean"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float Double floatResult = (Double)getStatResult("mr", "float_fd", VAL_TYPE.DOUBLE); Double floatTest = (Double)calculateNumberStat(floatTestStart, "mean"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double Double doubleResult = (Double)getStatResult("mr", "double_dd", VAL_TYPE.DOUBLE); Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "mean"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); } @Test @@ -212,28 +212,23 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int Double intResult = (Double)getStatResult("str", "int_id", VAL_TYPE.DOUBLE); Double intTest = (Double)calculateNumberStat(intTestStart, "stddev"); - assertTrue(Math.abs(intResult-intTest)<.00000000001); + assertEquals(getRawResponse(), intResult, intTest, 0.00000000001); //Long Double longResult = (Double)getStatResult("str", "long_ld", VAL_TYPE.DOUBLE); Double longTest = (Double)calculateNumberStat(longTestStart, "stddev"); - assertTrue(Math.abs(longResult-longTest)<.00000000001); + assertEquals(getRawResponse(), longResult, longTest, 0.00000000001); //Float Double floatResult = (Double)getStatResult("str", "float_fd", VAL_TYPE.DOUBLE); Double floatTest = (Double)calculateNumberStat(floatTestStart, "stddev"); - assertTrue("Oops: (double raws) " + Double.doubleToRawLongBits(floatResult) + " - " - + Double.doubleToRawLongBits(floatTest) + " < " + Double.doubleToRawLongBits(.00000000001) + - " Calculated diff " + Double.doubleToRawLongBits(floatResult - floatTest) - + " Let's see what the JVM thinks these bits are. FloatResult: " + floatResult.toString() + - " floatTest: " + floatTest.toString() + " Diff " + Double.toString(floatResult - floatTest), - Math.abs(floatResult - floatTest) < .00000000001); + assertEquals(getRawResponse(), floatResult, floatTest, 0.00000000001); //Double Double doubleResult = (Double)getStatResult("str", "double_dd", VAL_TYPE.DOUBLE); Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "stddev"); - assertTrue(Math.abs(doubleResult-doubleTest)<.00000000001); + assertEquals(getRawResponse(), doubleResult, doubleTest, 0.00000000001); } @Test @@ -241,22 +236,22 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int Double intResult = (Double)getStatResult("medr", "int_id", VAL_TYPE.DOUBLE); Double intTest = (Double)calculateNumberStat(intTestStart, "median"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long Double longResult = (Double)getStatResult("medr", "long_ld", VAL_TYPE.DOUBLE); Double longTest = (Double)calculateNumberStat(longTestStart, "median"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float Double floatResult = (Double)getStatResult("medr", "float_fd", VAL_TYPE.DOUBLE); Double floatTest = (Double)calculateNumberStat(floatTestStart, "median"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double Double doubleResult = (Double)getStatResult("medr", "double_dd", VAL_TYPE.DOUBLE); Double doubleTest = (Double)calculateNumberStat(doubleTestStart, "median"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); } @Test @@ -264,32 +259,32 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int 20 Integer intResult = (Integer)getStatResult("p2r", "int_id", VAL_TYPE.INTEGER); Integer intTest = (Integer)calculateStat(intTestStart, "perc_20"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long 20 Long longResult = (Long)getStatResult("p2r", "long_ld", VAL_TYPE.LONG); Long longTest = (Long)calculateStat(longTestStart, "perc_20"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float 20 Float floatResult = (Float)getStatResult("p2r", "float_fd", VAL_TYPE.FLOAT); Float floatTest = (Float)calculateStat(floatTestStart, "perc_20"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double 20 Double doubleResult = (Double)getStatResult("p2r", "double_dd", VAL_TYPE.DOUBLE); Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_20"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); //Date 20 String dateResult = (String)getStatResult("p2r", "date_dtd", VAL_TYPE.DATE); String dateTest = (String)calculateStat(dateTestStart, "perc_20"); - assertEquals(dateResult,dateTest); + assertEquals(getRawResponse(), dateResult,dateTest); //String 20 String stringResult = (String)getStatResult("p2r", "string_sd", VAL_TYPE.STRING); String stringTest = (String)calculateStat(stringTestStart, "perc_20"); - assertEquals(stringResult,stringTest); + assertEquals(getRawResponse(), stringResult,stringTest); } @Test @@ -297,32 +292,32 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int 60 Integer intResult = (Integer)getStatResult("p6r", "int_id", VAL_TYPE.INTEGER); Integer intTest = (Integer)calculateStat(intTestStart, "perc_60"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long 60 Long longResult = (Long)getStatResult("p6r", "long_ld", VAL_TYPE.LONG); Long longTest = (Long)calculateStat(longTestStart, "perc_60"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float 60 Float floatResult = (Float)getStatResult("p6r", "float_fd", VAL_TYPE.FLOAT); Float floatTest = (Float)calculateStat(floatTestStart, "perc_60"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double 60 Double doubleResult = (Double)getStatResult("p6r", "double_dd", VAL_TYPE.DOUBLE); Double doubleTest = (Double)calculateStat(doubleTestStart, "perc_60"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); //Date 60 String dateResult = (String)getStatResult("p6r", "date_dtd", VAL_TYPE.DATE); String dateTest = (String)calculateStat(dateTestStart, "perc_60"); - assertEquals(dateResult,dateTest); + assertEquals(getRawResponse(), dateResult,dateTest); //String 60 String stringResult = (String)getStatResult("p6r", "string_sd", VAL_TYPE.STRING); String stringTest = (String)calculateStat(stringTestStart, "perc_60"); - assertEquals(stringResult,stringTest); + assertEquals(getRawResponse(), stringResult,stringTest); } @Test @@ -330,32 +325,32 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int Integer intResult = (Integer)getStatResult("mir", "int_id", VAL_TYPE.INTEGER); Integer intTest = (Integer)calculateStat(intTestStart, "min"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long Long longResult = (Long)getStatResult("mir", "long_ld", VAL_TYPE.LONG); Long longTest = (Long)calculateStat(longTestStart, "min"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float Float floatResult = (Float)getStatResult("mir", "float_fd", VAL_TYPE.FLOAT); Float floatTest = (Float)calculateStat(floatTestStart, "min"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double Double doubleResult = (Double)getStatResult("mir", "double_dd", VAL_TYPE.DOUBLE); Double doubleTest = (Double)calculateStat(doubleTestStart, "min"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); //Date String dateResult = (String)getStatResult("mir", "date_dtd", VAL_TYPE.DATE); String dateTest = (String)calculateStat(dateTestStart, "min"); - assertEquals(dateResult,dateTest); + assertEquals(getRawResponse(), dateResult,dateTest); //String String stringResult = (String)getStatResult("mir", "string_sd", VAL_TYPE.STRING); String stringTest = (String)calculateStat(stringTestStart, "min"); - assertEquals(stringResult,stringTest); + assertEquals(getRawResponse(), stringResult,stringTest); } @Test @@ -363,32 +358,32 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int Integer intResult = (Integer)getStatResult("mar", "int_id", VAL_TYPE.INTEGER); Integer intTest = (Integer)calculateStat(intTestStart, "max"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long Long longResult = (Long)getStatResult("mar", "long_ld", VAL_TYPE.LONG); Long longTest = (Long)calculateStat(longTestStart, "max"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float Float floatResult = (Float)getStatResult("mar", "float_fd", VAL_TYPE.FLOAT); Float floatTest = (Float)calculateStat(floatTestStart, "max"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double Double doubleResult = (Double)getStatResult("mar", "double_dd", VAL_TYPE.DOUBLE); Double doubleTest = (Double)calculateStat(doubleTestStart, "max"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); //Date String dateResult = (String)getStatResult("mar", "date_dtd", VAL_TYPE.DATE); String dateTest = (String)calculateStat(dateTestStart, "max"); - assertEquals(dateResult,dateTest); + assertEquals(getRawResponse(), dateResult,dateTest); //String String stringResult = (String)getStatResult("mar", "string_sd", VAL_TYPE.STRING); String stringTest = (String)calculateStat(stringTestStart, "max"); - assertEquals(stringResult,stringTest); + assertEquals(getRawResponse(), stringResult,stringTest); } @Test @@ -396,32 +391,32 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int Long intResult = (Long)getStatResult("ur", "int_id", VAL_TYPE.LONG); Long intTest = (Long)calculateStat(intTestStart, "unique"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long Long longResult = (Long)getStatResult("ur", "long_ld", VAL_TYPE.LONG); Long longTest = (Long)calculateStat(longTestStart, "unique"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float Long floatResult = (Long)getStatResult("ur", "float_fd", VAL_TYPE.LONG); Long floatTest = (Long)calculateStat(floatTestStart, "unique"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double Long doubleResult = (Long)getStatResult("ur", "double_dd", VAL_TYPE.LONG); Long doubleTest = (Long)calculateStat(doubleTestStart, "unique"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); //Date Long dateResult = (Long)getStatResult("ur", "date_dtd", VAL_TYPE.LONG); Long dateTest = (Long)calculateStat(dateTestStart, "unique"); - assertEquals(dateResult,dateTest); + assertEquals(getRawResponse(), dateResult,dateTest); //String Long stringResult = (Long)getStatResult("ur", "string_sd", VAL_TYPE.LONG); Long stringTest = (Long)calculateStat(stringTestStart, "unique"); - assertEquals(stringResult,stringTest); + assertEquals(getRawResponse(), stringResult,stringTest); } @Test @@ -429,59 +424,59 @@ public class NoFacetTest extends AbstractAnalyticsStatsTest { //Int Long intResult = (Long)getStatResult("cr", "int_id", VAL_TYPE.LONG); Long intTest = (Long)calculateStat(intTestStart, "count"); - assertEquals(intResult,intTest); + assertEquals(getRawResponse(), intResult,intTest); //Long Long longResult = (Long)getStatResult("cr", "long_ld", VAL_TYPE.LONG); Long longTest = (Long)calculateStat(longTestStart, "count"); - assertEquals(longResult,longTest); + assertEquals(getRawResponse(), longResult,longTest); //Float Long floatResult = (Long)getStatResult("cr", "float_fd", VAL_TYPE.LONG); Long floatTest = (Long)calculateStat(floatTestStart, "count"); - assertEquals(floatResult,floatTest); + assertEquals(getRawResponse(), floatResult,floatTest); //Double Long doubleResult = (Long)getStatResult("cr", "double_dd", VAL_TYPE.LONG); Long doubleTest = (Long)calculateStat(doubleTestStart, "count"); - assertEquals(doubleResult,doubleTest); + assertEquals(getRawResponse(), doubleResult,doubleTest); //Date Long dateResult = (Long)getStatResult("cr", "date_dtd", VAL_TYPE.LONG); Long dateTest = (Long)calculateStat(dateTestStart, "count"); - assertEquals(dateResult,dateTest); + assertEquals(getRawResponse(), dateResult,dateTest); //String Long stringResult = (Long)getStatResult("cr", "string_sd", VAL_TYPE.LONG); Long stringTest = (Long)calculateStat(stringTestStart, "count"); - assertEquals(stringResult,stringTest); + assertEquals(getRawResponse(), stringResult,stringTest); } @Test public void missingDefaultTest() throws Exception { //Int long intResult = (Long)getStatResult("misr", "int_id", VAL_TYPE.LONG); - assertEquals(intMissing,intResult); + assertEquals(getRawResponse(), intMissing,intResult); //Long long longResult = (Long)getStatResult("misr", "long_ld", VAL_TYPE.LONG); - assertEquals(longMissing,longResult); + assertEquals(getRawResponse(), longMissing,longResult); //Float long floatResult = (Long)getStatResult("misr", "float_fd", VAL_TYPE.LONG); - assertEquals(floatMissing,floatResult); + assertEquals(getRawResponse(), floatMissing,floatResult); //Double long doubleResult = (Long)getStatResult("misr", "double_dd", VAL_TYPE.LONG); - assertEquals(doubleMissing,doubleResult); + assertEquals(getRawResponse(), doubleMissing,doubleResult); //Date long dateResult = (Long)getStatResult("misr", "date_dtd", VAL_TYPE.LONG); - assertEquals(dateMissing,dateResult); + assertEquals(getRawResponse(), dateMissing,dateResult); //String long stringResult = (Long)getStatResult("misr", "string_sd", VAL_TYPE.LONG); - assertEquals(stringMissing, stringResult); + assertEquals(getRawResponse(), stringMissing, stringResult); } } diff --git a/solr/core/src/test/org/apache/solr/analytics/expression/ExpressionTest.java b/solr/core/src/test/org/apache/solr/analytics/expression/ExpressionTest.java index 45d86d83715..d1ea7585ed6 100644 --- a/solr/core/src/test/org/apache/solr/analytics/expression/ExpressionTest.java +++ b/solr/core/src/test/org/apache/solr/analytics/expression/ExpressionTest.java @@ -78,13 +78,13 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest { double sumResult = (Double) getStatResult("ar", "sum", VAL_TYPE.DOUBLE); double uniqueResult = ((Long) getStatResult("ar", "unique", VAL_TYPE.LONG)).doubleValue(); double result = (Double) getStatResult("ar", "su", VAL_TYPE.DOUBLE); - assertEquals(sumResult + uniqueResult, result, 0.0); + assertEquals(getRawResponse(), sumResult + uniqueResult, result, 0.0); double meanResult = (Double) getStatResult("ar", "mean", VAL_TYPE.DOUBLE); double medianResult = (Double) getStatResult("ar", "median", VAL_TYPE.DOUBLE); double countResult = ((Long) getStatResult("ar", "count", VAL_TYPE.LONG)).doubleValue(); result = (Double) getStatResult("ar", "mcm", VAL_TYPE.DOUBLE); - assertEquals(meanResult + countResult + medianResult, result, 0.0); + assertEquals(getRawResponse(), meanResult + countResult + medianResult, result, 0.0); } @Test @@ -92,13 +92,13 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest { double sumResult = (Double) getStatResult("mr", "sum", VAL_TYPE.DOUBLE); double uniqueResult = ((Long) getStatResult("mr", "unique", VAL_TYPE.LONG)).doubleValue(); double result = (Double) getStatResult("mr", "su", VAL_TYPE.DOUBLE); - assertEquals(sumResult * uniqueResult, result, 0.0); + assertEquals(getRawResponse(), sumResult * uniqueResult, result, 0.0); double meanResult = (Double) getStatResult("mr", "mean", VAL_TYPE.DOUBLE); double medianResult = (Double) getStatResult("mr", "median", VAL_TYPE.DOUBLE); double countResult = ((Long) getStatResult("mr", "count", VAL_TYPE.LONG)).doubleValue(); result = (Double) getStatResult("mr", "mcm", VAL_TYPE.DOUBLE); - assertEquals(meanResult * countResult * medianResult, result, 0.0); + assertEquals(getRawResponse(), meanResult * countResult * medianResult, result, 0.0); } @Test @@ -106,12 +106,12 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest { double sumResult = (Double) getStatResult("dr", "sum", VAL_TYPE.DOUBLE); double uniqueResult = ((Long) getStatResult("dr", "unique", VAL_TYPE.LONG)).doubleValue(); double result = (Double) getStatResult("dr", "su", VAL_TYPE.DOUBLE); - assertEquals(sumResult / uniqueResult, result, 0.0); + assertEquals(getRawResponse(), sumResult / uniqueResult, result, 0.0); double meanResult = (Double) getStatResult("dr", "mean", VAL_TYPE.DOUBLE); double countResult = ((Long) getStatResult("dr", "count", VAL_TYPE.LONG)).doubleValue(); result = (Double) getStatResult("dr", "mc", VAL_TYPE.DOUBLE); - assertEquals(meanResult / countResult, result, 0.0); + assertEquals(getRawResponse(), meanResult / countResult, result, 0.0); } @Test @@ -119,43 +119,43 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest { double sumResult = (Double) getStatResult("pr", "sum", VAL_TYPE.DOUBLE); double uniqueResult = ((Long) getStatResult("pr", "unique", VAL_TYPE.LONG)).doubleValue(); double result = (Double) getStatResult("pr", "su", VAL_TYPE.DOUBLE); - assertEquals(Math.pow(sumResult, uniqueResult), result, 0.0); + assertEquals(getRawResponse(), Math.pow(sumResult, uniqueResult), result, 0.0); double meanResult = (Double) getStatResult("pr", "mean", VAL_TYPE.DOUBLE); double countResult = ((Long) getStatResult("pr", "count", VAL_TYPE.LONG)).doubleValue(); result = (Double) getStatResult("pr", "mc", VAL_TYPE.DOUBLE); - assertEquals(Math.pow(meanResult, countResult), result, 0.0); + assertEquals(getRawResponse(), Math.pow(meanResult, countResult), result, 0.0); } @Test public void negateTest() throws Exception { double sumResult = (Double) getStatResult("nr", "sum", VAL_TYPE.DOUBLE); double result = (Double) getStatResult("nr", "s", VAL_TYPE.DOUBLE); - assertEquals(-1 * sumResult, result, 0.0); + assertEquals(getRawResponse(), -1 * sumResult, result, 0.0); double countResult = ((Long) getStatResult("nr", "count", VAL_TYPE.LONG)).doubleValue(); result = (Double) getStatResult("nr", "c", VAL_TYPE.DOUBLE); - assertEquals(-1 * countResult, result, 0.0); + assertEquals(getRawResponse(), -1 * countResult, result, 0.0); } @Test public void absoluteValueTest() throws Exception { double sumResult = (Double) getStatResult("avr", "sum", VAL_TYPE.DOUBLE); double result = (Double) getStatResult("avr", "s", VAL_TYPE.DOUBLE); - assertEquals(sumResult, result, 0.0); + assertEquals(getRawResponse(), sumResult, result, 0.0); double countResult = ((Long) getStatResult("avr", "count", VAL_TYPE.LONG)).doubleValue(); result = (Double) getStatResult("avr", "c", VAL_TYPE.DOUBLE); - assertEquals(countResult, result, 0.0); + assertEquals(getRawResponse(), countResult, result, 0.0); } @Test public void constantNumberTest() throws Exception { double result = (Double) getStatResult("cnr", "c8", VAL_TYPE.DOUBLE); - assertEquals(8, result, 0.0); + assertEquals(getRawResponse(), 8, result, 0.0); result = (Double) getStatResult("cnr", "c10", VAL_TYPE.DOUBLE); - assertEquals(10, result, 0.0); + assertEquals(getRawResponse(), 10, result, 0.0); } @SuppressWarnings("deprecation") @@ -165,36 +165,36 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest { DateMathParser date = new DateMathParser(); date.setNow(TrieDateField.parseDate((String) getStatResult("dmr", "median", VAL_TYPE.DATE))); String dateMath = (String) getStatResult("dmr", "dmme", VAL_TYPE.DATE); - assertEquals(TrieDateField.parseDate(dateMath), date.parseMath(math)); + assertEquals(getRawResponse(), TrieDateField.parseDate(dateMath), date.parseMath(math)); math = (String) getStatResult("dmr", "cma", VAL_TYPE.STRING); date = new DateMathParser(); date.setNow(TrieDateField.parseDate((String) getStatResult("dmr", "max", VAL_TYPE.DATE))); dateMath = (String) getStatResult("dmr", "dmma", VAL_TYPE.DATE); - assertEquals(TrieDateField.parseDate(dateMath), date.parseMath(math)); + assertEquals(getRawResponse(), TrieDateField.parseDate(dateMath), date.parseMath(math)); } @Test public void constantDateTest() throws Exception { String date = (String) getStatResult("cdr", "cd1", VAL_TYPE.DATE); String str = (String) getStatResult("cdr", "cs1", VAL_TYPE.STRING); - assertEquals(date, str); + assertEquals(getRawResponse(), date, str); date = (String) getStatResult("cdr", "cd2", VAL_TYPE.DATE); str = (String) getStatResult("cdr", "cs2", VAL_TYPE.STRING); - assertEquals(date, str); + assertEquals(getRawResponse(), date, str); } @Test public void constantStringTest() throws Exception { String str = (String) getStatResult("csr", "cs1", VAL_TYPE.STRING); - assertEquals(str, "this is the first"); + assertEquals(getRawResponse(), str, "this is the first"); str = (String) getStatResult("csr", "cs2", VAL_TYPE.STRING); - assertEquals(str, "this is the second"); + assertEquals(getRawResponse(), str, "this is the second"); str = (String) getStatResult("csr", "cs3", VAL_TYPE.STRING); - assertEquals(str, "this is the third"); + assertEquals(getRawResponse(), str, "this is the third"); } @Test @@ -203,13 +203,13 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest { builder.append((String) getStatResult("cr", "csmin", VAL_TYPE.STRING)); builder.append((String) getStatResult("cr", "min", VAL_TYPE.STRING)); String concat = (String) getStatResult("cr", "ccmin", VAL_TYPE.STRING); - assertEquals(concat, builder.toString()); + assertEquals(getRawResponse(), concat, builder.toString()); builder.setLength(0); builder.append((String) getStatResult("cr", "csmax", VAL_TYPE.STRING)); builder.append((String) getStatResult("cr", "max", VAL_TYPE.STRING)); concat = (String) getStatResult("cr", "ccmax", VAL_TYPE.STRING); - assertEquals(concat, builder.toString()); + assertEquals(getRawResponse(), concat, builder.toString()); } @Test @@ -217,12 +217,12 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest { StringBuilder builder = new StringBuilder(); builder.append((String) getStatResult("rr", "min", VAL_TYPE.STRING)); String rev = (String) getStatResult("rr", "rmin", VAL_TYPE.STRING); - assertEquals(rev, builder.reverse().toString()); + assertEquals(getRawResponse(), rev, builder.reverse().toString()); builder.setLength(0); builder.append((String) getStatResult("rr", "max", VAL_TYPE.STRING)); rev = (String) getStatResult("rr", "rmax", VAL_TYPE.STRING); - assertEquals(rev, builder.reverse().toString()); + assertEquals(getRawResponse(), rev, builder.reverse().toString()); } public static SolrQueryRequest request(String... args) { diff --git a/solr/core/src/test/org/apache/solr/analytics/util/valuesource/FunctionTest.java b/solr/core/src/test/org/apache/solr/analytics/util/valuesource/FunctionTest.java index eca83685249..a9dd8b749d6 100644 --- a/solr/core/src/test/org/apache/solr/analytics/util/valuesource/FunctionTest.java +++ b/solr/core/src/test/org/apache/solr/analytics/util/valuesource/FunctionTest.java @@ -89,148 +89,147 @@ public class FunctionTest extends AbstractAnalyticsStatsTest { public void addTest() throws Exception { double result = (Double)getStatResult("ar", "sum", VAL_TYPE.DOUBLE); double calculated = (Double)getStatResult("ar", "sumc", VAL_TYPE.DOUBLE); - assertTrue(result==calculated); - assertEquals("add sum", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); result = (Double)getStatResult("ar", "mean", VAL_TYPE.DOUBLE); calculated = (Double)getStatResult("ar", "meanc", VAL_TYPE.DOUBLE); assertTrue(result==calculated); - assertEquals("add mean", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); } @Test public void multiplyTest() throws Exception { double result = (Double)getStatResult("mr", "sum", VAL_TYPE.DOUBLE); double calculated = (Double)getStatResult("mr", "sumc", VAL_TYPE.DOUBLE); - assertEquals("multiply sum", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); result = (Double)getStatResult("mr", "mean", VAL_TYPE.DOUBLE); calculated = (Double)getStatResult("mr", "meanc", VAL_TYPE.DOUBLE); - assertEquals("multiply mean", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); } @Test public void divideTest() throws Exception { Double result = (Double)getStatResult("dr", "sum", VAL_TYPE.DOUBLE); Double calculated = (Double)getStatResult("dr", "sumc", VAL_TYPE.DOUBLE); - assertEquals("power sum", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); result = (Double)getStatResult("dr", "mean", VAL_TYPE.DOUBLE); calculated = (Double)getStatResult("dr", "meanc", VAL_TYPE.DOUBLE); - assertEquals("power mean", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); } @Test public void powerTest() throws Exception { double result = (Double)getStatResult("pr", "sum", VAL_TYPE.DOUBLE); double calculated = (Double)getStatResult("pr", "sumc", VAL_TYPE.DOUBLE); - assertTrue(result==calculated); - assertEquals("power sum", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); result = (Double)getStatResult("pr", "mean", VAL_TYPE.DOUBLE); calculated = (Double)getStatResult("pr", "meanc", VAL_TYPE.DOUBLE); - assertTrue(result==calculated); - assertEquals("power mean", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); } @Test public void negateTest() throws Exception { double result = (Double)getStatResult("nr", "sum", VAL_TYPE.DOUBLE); double calculated = (Double)getStatResult("nr", "sumc", VAL_TYPE.DOUBLE); - assertEquals("negate sum", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); result = (Double)getStatResult("nr", "mean", VAL_TYPE.DOUBLE); calculated = (Double)getStatResult("nr", "meanc", VAL_TYPE.DOUBLE); - assertEquals("negate mean", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); } @Test public void absoluteValueTest() throws Exception { double result = (Double)getStatResult("avr", "sum", VAL_TYPE.DOUBLE); double calculated = (Double)getStatResult("avr", "sumc", VAL_TYPE.DOUBLE); - System.out.println(Double.doubleToRawLongBits(result) + " " + Double.doubleToRawLongBits(calculated) ); - assertEquals("absolute values sum", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); result = (Double)getStatResult("avr", "mean", VAL_TYPE.DOUBLE); calculated = (Double)getStatResult("avr", "meanc", VAL_TYPE.DOUBLE); - assertEquals("absolute values mean", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); } @Test public void constantNumberTest() throws Exception { double result = (Double)getStatResult("cnr", "sum", VAL_TYPE.DOUBLE); double calculated = (Double)getStatResult("cnr", "sumc", VAL_TYPE.DOUBLE); - assertTrue(result==calculated); - assertEquals("constant sum", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); result = (Double)getStatResult("cnr", "mean", VAL_TYPE.DOUBLE); calculated = (Double)getStatResult("cnr", "meanc", VAL_TYPE.DOUBLE); - assertTrue(result==calculated); - assertEquals("constant mean", result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); + assertEquals(getRawResponse(), result, calculated, 0.0); } @Test public void dateMathTest() throws Exception { String result = (String)getStatResult("dmr", "median", VAL_TYPE.STRING); String calculated = (String)getStatResult("dmr", "medianc", VAL_TYPE.STRING); - assertEquals("date math median", result, calculated); + assertEquals(getRawResponse(), result, calculated); result = (String)getStatResult("dmr", "max", VAL_TYPE.STRING); calculated = (String)getStatResult("dmr", "maxc", VAL_TYPE.STRING); - assertEquals("date math mean", result, calculated); + assertEquals(getRawResponse(), result, calculated); } @Test public void constantDateTest() throws Exception { String result = (String)getStatResult("cdr", "median", VAL_TYPE.STRING); String calculated = (String)getStatResult("cdr", "medianc", VAL_TYPE.STRING); - assertTrue(result.equals(calculated)); - assertEquals("constant date median", result, calculated); + assertEquals(getRawResponse(), result, calculated); + assertEquals(getRawResponse(), result, calculated); result = (String)getStatResult("cdr", "max", VAL_TYPE.STRING); calculated = (String)getStatResult("cdr", "maxc", VAL_TYPE.STRING); - assertEquals("constant date mean", result, calculated); + assertEquals(getRawResponse(), result, calculated); } @Test public void constantStringTest() throws Exception { String result = (String)getStatResult("csr", "min", VAL_TYPE.STRING); String calculated = (String)getStatResult("csr", "minc", VAL_TYPE.STRING); - assertEquals("constant min", result, calculated); + assertEquals(getRawResponse(), result, calculated); result = (String)getStatResult("csr", "max", VAL_TYPE.STRING); calculated = (String)getStatResult("csr", "maxc", VAL_TYPE.STRING); - assertEquals("constant max", result, calculated); + assertEquals(getRawResponse(), result, calculated); } @Test public void concatenateTest() throws Exception { String result = (String)getStatResult("cr", "min", VAL_TYPE.STRING); String calculated = (String)getStatResult("cr", "minc", VAL_TYPE.STRING); - assertEquals("concat min", result, calculated); + assertEquals(getRawResponse(), result, calculated); result = (String)getStatResult("cr", "max", VAL_TYPE.STRING); calculated = (String)getStatResult("cr", "maxc", VAL_TYPE.STRING); - assertEquals("concat max", result, calculated); + assertEquals(getRawResponse(), result, calculated); } @Test public void reverseTest() throws Exception { String result = (String)getStatResult("rr", "min", VAL_TYPE.STRING); String calculated = (String)getStatResult("rr", "minc", VAL_TYPE.STRING); - assertEquals("reverse min", result, calculated); + assertEquals(getRawResponse(), result, calculated); result = (String)getStatResult("rr", "max", VAL_TYPE.STRING); calculated = (String)getStatResult("rr", "maxc", VAL_TYPE.STRING); - assertEquals("reverse max", result, calculated); + assertEquals(getRawResponse(), result, calculated); } @Test public void missingTest() throws Exception { double min = (Double)getStatResult("ms", "min", VAL_TYPE.DOUBLE); double max = (Double)getStatResult("ms", "max", VAL_TYPE.DOUBLE); - assertEquals("missingTest 1", 48.0d, max, 0.0); - assertEquals("missingTest 2", 1.0d, min, 0.0); + assertEquals(getRawResponse(), 48.0d, max, 0.0); + assertEquals(getRawResponse(), 1.0d, min, 0.0); } }