2016-11-30 27 views
0

当我为了测试利用spark-testing-base火花检测基地奇怪校验失败

Map("result" -> Array(3, 6, 9, 12, 15, 18, 21, 24, 27, 0)) did not equal Map("result" -> Array(3, 6, 9, 12, 15, 18, 21, 24, 27, 0)) 

为一个测试情况下,火花应用执行sbt test

val input: Map[String, Any] = Map("digits" -> Seq(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)) 
val expectedOutput: Map[String, Any] = Map("result" -> Array(3, 6, 9, 12, 15, 18, 21, 24, 27, 0)) 
val result = SimpleContext.runTheJOb(session, input) 

最小例子可以发现https://github.com/geoHeil/apache-spark-restAPI-example

编辑

w孔测试用例直接

class SimpleTest extends FunSuite with SharedSparkContext with DatasetSuiteBase { 

    test("SimpleContext should multiply input numbers by 3") { 
    val session = spark 

    val input: Map[String, Any] = Map("digits" -> Seq(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)) 
    val expectedOutput: Map[String, Any] = Map("result" -> Array(3, 6, 9, 12, 15, 18, 21, 24, 27, 0)) 
    val result = SimpleContext.runTheJOb(session, input) 
    assert(expectedOutput === result) 
    } 
} 
+0

@LostInOverflow最小的“代码”已包含在内。但是如果你喜欢整个代码,我会编辑这个问题。 –

+0

谢谢!你的要点可能会在任何时候失效,这个问题不仅适用于你。 – 2016-11-30 20:47:42

回答

4

您有问题是,Scala的Array S,在引擎盖下是Java数组,没有可比性使用==(参见this answer用于解释)。

实施例:

scala> Array(1,2) == Array(1,2) 
res0: Boolean = false 

然而大多数其他集合的可比:

scala> List(1,2) == List(1,2) 
res1: Boolean = true 

您的选项将是要么使用其他集合(如List)中的一个或以使用deep进行比较:

scala> Array(1,2).deep == Array(1,2).deep 
res22: Boolean = true 

scala> Array(1,2).deep == Array(1,3).deep 
res23: Boolean = false 
+2

所以Array(1,2)应该等于(Array(1,2))通过http://www.scalatest.org/user_guide/using_matchers#checkingEqualityWithMatchers应该是解决方案。 –