ScalarTest.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // ScalarTest.swift
  3. //
  4. // Created by Giles Payne on 2020/01/31.
  5. //
  6. import XCTest
  7. import OpenCV
  8. class ScalarTest: OpenCVTestCase {
  9. let s1 = Scalar(1.0)
  10. let s2 = Scalar.all(1.0)
  11. func testAll() {
  12. let dstScalar = Scalar.all(2.0)
  13. let truth = Scalar(2.0, 2.0, 2.0, 2.0)
  14. XCTAssertEqual(truth, dstScalar)
  15. }
  16. func testClone() {
  17. let dstScalar = s2.clone()
  18. XCTAssertEqual(s2, dstScalar)
  19. }
  20. func testConj() {
  21. let dstScalar = s2.conj()
  22. let truth = Scalar(1, -1, -1, -1)
  23. XCTAssertEqual(truth, dstScalar)
  24. }
  25. func testEqualsObject() {
  26. let dstScalar = s2.clone()
  27. XCTAssert(s2 == dstScalar)
  28. XCTAssertFalse(s2 == s1)
  29. }
  30. func testHashCode() {
  31. XCTAssertEqual(s2.hash(), s2.hash())
  32. }
  33. func testIsReal() {
  34. XCTAssert(s1.isReal())
  35. XCTAssertFalse(s2.isReal())
  36. }
  37. func testMulScalar() {
  38. let dstScalar = s2.mul(s1)
  39. XCTAssertEqual(s1, dstScalar)
  40. }
  41. func testMulScalarDouble() {
  42. let multiplier = 2.0
  43. let dstScalar = s2.mul(s1, scale: multiplier)
  44. let truth = Scalar(2)
  45. XCTAssertEqual(truth, dstScalar)
  46. }
  47. func testScalarDouble() {
  48. let truth = Scalar(1)
  49. XCTAssertEqual(truth, s1)
  50. }
  51. func testScalarDoubleArray() {
  52. let vals: [Double] = [2.0, 4.0, 5.0, 3.0]
  53. let dstScalar = Scalar(vals:vals as [NSNumber])
  54. let truth = Scalar(2.0, 4.0, 5.0, 3.0)
  55. XCTAssertEqual(truth, dstScalar)
  56. }
  57. func testScalarDoubleDouble() {
  58. let dstScalar = Scalar(2, 5)
  59. let truth = Scalar(2.0, 5.0, 0.0, 0.0)
  60. XCTAssertEqual(truth, dstScalar)
  61. }
  62. func testScalarDoubleDoubleDouble() {
  63. let dstScalar = Scalar(2.0, 5.0, 5.0)
  64. let truth = Scalar(2.0, 5.0, 5.0, 0.0)
  65. XCTAssertEqual(truth, dstScalar);
  66. }
  67. func testScalarDoubleDoubleDoubleDouble() {
  68. let dstScalar = Scalar(2.0, 5.0, 5.0, 9.0)
  69. let truth = Scalar(2.0, 5.0, 5.0, 9.0)
  70. XCTAssertEqual(truth, dstScalar)
  71. }
  72. func testToString() {
  73. let actual = "\(s2)"
  74. let expected = "Scalar [1.000000, 1.000000, 1.000000, 1.000000]"
  75. XCTAssertEqual(expected, actual)
  76. }
  77. }