TermCriteriaTest.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // TermCriteriaTest.swift
  3. //
  4. // Created by Giles Payne on 2020/01/31.
  5. //
  6. import XCTest
  7. import OpenCV
  8. class TermCriteriaTest: OpenCVTestCase {
  9. let tc2 = TermCriteria(type: 2, maxCount: 4, epsilon: EPS)
  10. func testClone() {
  11. let tc1 = tc2.clone()
  12. XCTAssertEqual(tc2, tc1)
  13. }
  14. func testEqualsObject() {
  15. var tc1 = TermCriteria()
  16. XCTAssertFalse(tc2 == tc1)
  17. tc1 = tc2.clone()
  18. XCTAssert(tc2 == tc1)
  19. }
  20. func testHashCode() {
  21. XCTAssertEqual(tc2.hash(), tc2.hash())
  22. }
  23. func testSet() {
  24. let tc1 = TermCriteria()
  25. let vals1:[Double] = []
  26. tc1.set(vals: vals1 as [NSNumber])
  27. XCTAssertEqual(0, tc1.type)
  28. XCTAssertEqual(0, tc1.maxCount)
  29. XCTAssertEqual(0.0, tc1.epsilon)
  30. let vals2 = [9, 8, 0.002]
  31. tc2.set(vals: vals2 as [NSNumber])
  32. XCTAssertEqual(9, tc2.type)
  33. XCTAssertEqual(8, tc2.maxCount)
  34. XCTAssertEqual(0.002, tc2.epsilon)
  35. }
  36. func testTermCriteria() {
  37. let tc1 = TermCriteria()
  38. XCTAssertNotNil(tc1)
  39. XCTAssertEqual(0, tc1.type)
  40. XCTAssertEqual(0, tc1.maxCount)
  41. XCTAssertEqual(0.0, tc1.epsilon)
  42. }
  43. func testTermCriteriaDoubleArray() {
  44. let vals = [ 3, 2, 0.007]
  45. let tc1 = TermCriteria(vals: vals as [NSNumber])
  46. XCTAssertEqual(3, tc1.type)
  47. XCTAssertEqual(2, tc1.maxCount)
  48. XCTAssertEqual(0.007, tc1.epsilon)
  49. }
  50. func testTermCriteriaIntIntDouble() {
  51. let tc1 = TermCriteria(type: 2, maxCount: 4, epsilon: OpenCVTestCase.EPS)
  52. XCTAssertNotNil(tc1)
  53. XCTAssertEqual(2, tc1.type)
  54. XCTAssertEqual(4, tc1.maxCount)
  55. XCTAssertEqual(OpenCVTestCase.EPS, tc1.epsilon)
  56. }
  57. func testToString() {
  58. let actual = "\(tc2)"
  59. let expected = "TermCriteria { type: 2, maxCount: 4, epsilon: 0.001000}"
  60. XCTAssertEqual(expected, actual)
  61. }
  62. }