2

specs2を使用して2つの非常に大きな配列を比較しようとしています。残念ながら、配列が等しくない場合は、実際の配列と期待される配列の各配列の内容が表示されます。とにかく、実際のデータと予想されるデータの量を減らすか、この特定のテストのためだけにデータを完全に削除することができますか?

setMessageを使用してみましたが、実際の部分と予想される部分には影響しません。

bytes1 must be_== (bytes2).setMessage("A does not mach B")

私が実際にやろうとしているのは、2つの入力ストリームを比較することです。また、誰かが配列に変換するのではなく、それを行う方法についてより良いアイデアを持っているかどうかを聞くことに興味があります。

4

1 に答える 1

2

Diffs独自の特性を実装することにより、差異の処理方法を制御できます。

import org.specs2._
import main._

class MyDiffs extends Diffs {
  /** @return true if the differences must be shown */
  def show: Boolean = true
  /** @return true if the differences must be shown for 2 different strings */
  def show(expected: String, actual: String): Boolean = 
    expected.size + actual.size < 100
  /** @return the diffs */
  def showDiffs(expected: String, actual: String): (String, String) = 
    (expected.take(10).mkString, actual.take(10).mkString)
  /** @return true if the full strings must also be shown */
  def showFull: Boolean = false
  /** this method is not used and will be removed from the trait in a next release */
  def separators: String = ""  
}

class s extends Specification { def is = 
  args.report(diffs = new MyDiffs)^
  "test" ! {
    "abcdefghijklmnopqrstu" must_== "abcdefghijklmnopqrstuvwxyz"
  }
}


x test
'abcdefghijklmnopqrstu' is not equal to 'abcdefghijklmnopqrstuvwxyz' (<console>:47)
 Expected: qrstuvwxyz
 Actual:   lmnopqrstu
于 2013-02-13T05:12:00.890 に答える