PointTest.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // PointTest.swift
  3. //
  4. // Created by Giles Payne on 2020/01/31.
  5. //
  6. import XCTest
  7. import OpenCV
  8. class PointTest: OpenCVTestCase {
  9. let p1 = Point2d(x: 2, y: 2)
  10. let p2 = Point2d(x: 1, y: 1)
  11. func testClone() {
  12. let truth = Point2d(x: 1, y: 1)
  13. let dstPoint = truth.clone()
  14. XCTAssertEqual(truth, dstPoint);
  15. }
  16. func testDot() {
  17. let result = p1.dot(p2);
  18. XCTAssertEqual(4.0, result)
  19. }
  20. func testEqualsObject() {
  21. var flag = p1 == p1
  22. XCTAssert(flag)
  23. flag = p1 == p2
  24. XCTAssertFalse(flag)
  25. }
  26. func testHashCode() {
  27. XCTAssertEqual(p1.hash(), p1.hash())
  28. }
  29. func testInside() {
  30. let rect = Rect2d(x: 0, y: 0, width: 5, height: 3)
  31. XCTAssert(p1.inside(rect))
  32. let p2 = Point2d(x: 3, y: 3)
  33. XCTAssertFalse(p2.inside(rect))
  34. }
  35. func testPoint() {
  36. let p = Point2d()
  37. XCTAssertNotNil(p)
  38. XCTAssertEqual(0.0, p.x)
  39. XCTAssertEqual(0.0, p.y)
  40. }
  41. func testPointDoubleArray() {
  42. let vals:[Double] = [2, 4]
  43. let p = Point2d(vals: vals as [NSNumber])
  44. XCTAssertEqual(2.0, p.x);
  45. XCTAssertEqual(4.0, p.y);
  46. }
  47. func testPointDoubleDouble() {
  48. let p1 = Point2d(x: 7, y: 5)
  49. XCTAssertNotNil(p1)
  50. XCTAssertEqual(7.0, p1.x);
  51. XCTAssertEqual(5.0, p1.y);
  52. }
  53. func testSet() {
  54. let vals1:[Double] = []
  55. p1.set(vals: vals1 as [NSNumber])
  56. XCTAssertEqual(0.0, p1.x)
  57. XCTAssertEqual(0.0, p1.y)
  58. let vals2 = [ 6, 10 ]
  59. p2.set(vals: vals2 as [NSNumber])
  60. XCTAssertEqual(6.0, p2.x)
  61. XCTAssertEqual(10.0, p2.y)
  62. }
  63. func testToString() {
  64. let actual = "\(p1)"
  65. let expected = "Point2d {2.000000,2.000000}"
  66. XCTAssertEqual(expected, actual)
  67. }
  68. }