Point3Test.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // Point3Test.swift
  3. //
  4. // Created by Giles Payne on 2020/01/31.
  5. //
  6. import XCTest
  7. import OpenCV
  8. class Point3Test: OpenCVTestCase {
  9. let p1 = Point3i(x: 2, y: 2, z: 2)
  10. let p2 = Point3i(x: 1, y: 1, z: 1)
  11. func testClone() {
  12. let truth = Point3i(x: 1, y: 1, z: 1)
  13. let p1 = truth.clone()
  14. XCTAssertEqual(truth, p1)
  15. }
  16. func testCross() {
  17. let dstPoint = p1.cross(p2)
  18. let truth = Point3i(x: 0, y: 0, z: 0)
  19. XCTAssertEqual(truth, dstPoint)
  20. }
  21. func testDot() {
  22. let result = p1.dot(p2)
  23. XCTAssertEqual(6.0, result)
  24. }
  25. func testEqualsObject() {
  26. var flag = p1 == p1
  27. XCTAssert(flag)
  28. flag = p1 == p2
  29. XCTAssertFalse(flag)
  30. }
  31. func testHashCode() {
  32. XCTAssertEqual(p1.hash(), p1.hash())
  33. }
  34. func testPoint3() {
  35. let p1 = Point3i()
  36. XCTAssertNotNil(p1)
  37. XCTAssert(0 == p1.x)
  38. XCTAssert(0 == p1.y)
  39. XCTAssert(0 == p1.z)
  40. }
  41. func testPoint3DoubleArray() {
  42. let vals:[Double] = [1, 2, 3]
  43. let p1 = Point3i(vals: vals as [NSNumber])
  44. XCTAssert(1 == p1.x)
  45. XCTAssert(2 == p1.y)
  46. XCTAssert(3 == p1.z)
  47. }
  48. func testPoint3DoubleDoubleDouble() {
  49. let p1 = Point3i(x: 1, y: 2, z: 3)
  50. XCTAssertEqual(1, p1.x)
  51. XCTAssertEqual(2, p1.y)
  52. XCTAssertEqual(3, p1.z)
  53. }
  54. func testPoint3Point() {
  55. let p = Point(x: 2, y: 3)
  56. let p1 = Point3i(point: p)
  57. XCTAssertEqual(2, p1.x)
  58. XCTAssertEqual(3, p1.y)
  59. XCTAssertEqual(0, p1.z)
  60. }
  61. func testSet() {
  62. let vals1:[Double] = []
  63. p1.set(vals: vals1 as [NSNumber]);
  64. XCTAssertEqual(0, p1.x)
  65. XCTAssertEqual(0, p1.y)
  66. XCTAssertEqual(0, p1.z)
  67. let vals2 = [3, 6, 10]
  68. p1.set(vals: vals2 as [NSNumber])
  69. XCTAssertEqual(3, p1.x)
  70. XCTAssertEqual(6, p1.y)
  71. XCTAssertEqual(10, p1.z)
  72. }
  73. func testToString() {
  74. let actual = "\(p1)"
  75. let expected = "Point3i {2,2,2}"
  76. XCTAssertEqual(expected, actual)
  77. }
  78. }