RangeTest.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // RangeTest.swift
  3. //
  4. // Created by Giles Payne on 2020/01/31.
  5. //
  6. import XCTest
  7. import OpenCV
  8. class RangeTest: OpenCVTestCase {
  9. let r1 = Range(start: 1, end: 11)
  10. let r2 = Range(start: 1, end: 1)
  11. func testAll() {
  12. let range = Range.all()
  13. XCTAssertEqual(Int32.min, range.start)
  14. XCTAssertEqual(Int32.max, range.end)
  15. }
  16. func testClone() {
  17. let dstRange = r1.clone()
  18. XCTAssertEqual(r1, dstRange)
  19. }
  20. func testEmpty() {
  21. var flag = r1.empty()
  22. XCTAssertFalse(flag)
  23. flag = r2.empty()
  24. XCTAssert(flag)
  25. }
  26. func testEqualsObject() {
  27. XCTAssertFalse(r2 == r1)
  28. let range = r1.clone()
  29. XCTAssert(r1 == range)
  30. }
  31. func testHashCode() {
  32. XCTAssertEqual(r1.hash(), r1.hash())
  33. }
  34. func testIntersection() {
  35. let range = r1.intersection(r2)
  36. XCTAssertEqual(r2, range)
  37. }
  38. func testRange() {
  39. let range = Range()
  40. XCTAssertNotNil(range)
  41. XCTAssertEqual(0, range.start)
  42. XCTAssertEqual(0, range.end)
  43. }
  44. func testRangeDoubleArray() {
  45. let vals:[Double] = [2, 4]
  46. let r = Range(vals: vals as [NSNumber])
  47. XCTAssert(2 == r.start);
  48. XCTAssert(4 == r.end);
  49. }
  50. func testRangeIntInt() {
  51. let r1 = Range(start: 12, end: 13)
  52. XCTAssertNotNil(r1);
  53. XCTAssertEqual(12, r1.start);
  54. XCTAssertEqual(13, r1.end);
  55. }
  56. func testSet() {
  57. let vals1:[Double] = []
  58. r1.set(vals: vals1 as [NSNumber])
  59. XCTAssertEqual(0, r1.start)
  60. XCTAssertEqual(0, r1.end)
  61. let vals2 = [6, 10]
  62. r2.set(vals: vals2 as [NSNumber])
  63. XCTAssertEqual(6, r2.start)
  64. XCTAssertEqual(10, r2.end)
  65. }
  66. func testShift() {
  67. let delta:Int32 = 1
  68. let range = Range().shift(delta)
  69. XCTAssertEqual(r2, range)
  70. }
  71. func testSize() {
  72. XCTAssertEqual(10, r1.size())
  73. XCTAssertEqual(0, r2.size())
  74. }
  75. func testToString() {
  76. let actual = "\(r1)"
  77. let expected = "Range {1, 11}"
  78. XCTAssertEqual(expected, actual)
  79. }
  80. }