试图使用&和scala中的操作

时间:2017-08-06 01:07:25

标签: scala

案例类需要3个参数id,由内部名称应用。试图使结果长度返回3.内部名称是一个新添加的字段/参数,这就是它返回0而不是3的原因。

我当时想要使用

result.topics.find(_.topicId == "urn:emmet:1234567").get.appliedBy should be ("human") &
  result.topics.find(_.topicId == "urn:emmet:2345678").get.internalName should be ("")

它给我语法错误,请提前建议

 it should "dedup topics by id, keeping those applied by human if possible" in {
val doc = Document.empty.copy(
  topics = Array(
    Topic("urn:emmet:1234567", appliedBy = "machine" , internalName = ""),
    Topic("urn:emmet:2345678", appliedBy = "human", internalName = ""),
    Topic("urn:emmet:1234567", appliedBy = "human", internalName = ""),
    Topic("urn:emmet:2345678", appliedBy = "machine", internalName = ""),
    Topic("urn:emmet:3456789", appliedBy = "machine", internalName = ""),
    Topic("urn:emmet:3456789", appliedBy = "machine", internalName = "")
  )
)

val result = DocumentTransform.dedupSubRecords(doc)

result.topics.length should be (3)
result.topics.find(_.topicId == "urn:emmet:1234567").get.appliedBy should be ("human")
result.topics.find(_.topicId == "urn:emmet:2345678").get.appliedBy should be ("human")
result.topics.find(_.topicId == "urn:emmet:3456789").get.appliedBy should be ("machine")

}

1 个答案:

答案 0 :(得分:1)

多个测试语句已经是'和',因为如果其中任何一个失败,则整个测试失败。

val e1234567 = result.topics.find(_.topicId == "urn:emmet:1234567").get
e1234567.appliedBy shouldEqual "human"
e1234567.internalName shouldEqual ""