1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // ScalarTest.swift
- //
- // Created by Giles Payne on 2020/01/31.
- //
- import XCTest
- import OpenCV
- class ScalarTest: OpenCVTestCase {
- let s1 = Scalar(1.0)
- let s2 = Scalar.all(1.0)
- func testAll() {
- let dstScalar = Scalar.all(2.0)
- let truth = Scalar(2.0, 2.0, 2.0, 2.0)
- XCTAssertEqual(truth, dstScalar)
- }
- func testClone() {
- let dstScalar = s2.clone()
- XCTAssertEqual(s2, dstScalar)
- }
- func testConj() {
- let dstScalar = s2.conj()
- let truth = Scalar(1, -1, -1, -1)
- XCTAssertEqual(truth, dstScalar)
- }
- func testEqualsObject() {
- let dstScalar = s2.clone()
- XCTAssert(s2 == dstScalar)
- XCTAssertFalse(s2 == s1)
- }
- func testHashCode() {
- XCTAssertEqual(s2.hash(), s2.hash())
- }
- func testIsReal() {
- XCTAssert(s1.isReal())
- XCTAssertFalse(s2.isReal())
- }
- func testMulScalar() {
- let dstScalar = s2.mul(s1)
- XCTAssertEqual(s1, dstScalar)
- }
- func testMulScalarDouble() {
- let multiplier = 2.0
- let dstScalar = s2.mul(s1, scale: multiplier)
- let truth = Scalar(2)
- XCTAssertEqual(truth, dstScalar)
- }
- func testScalarDouble() {
- let truth = Scalar(1)
- XCTAssertEqual(truth, s1)
- }
- func testScalarDoubleArray() {
- let vals: [Double] = [2.0, 4.0, 5.0, 3.0]
- let dstScalar = Scalar(vals:vals as [NSNumber])
- let truth = Scalar(2.0, 4.0, 5.0, 3.0)
- XCTAssertEqual(truth, dstScalar)
- }
- func testScalarDoubleDouble() {
- let dstScalar = Scalar(2, 5)
- let truth = Scalar(2.0, 5.0, 0.0, 0.0)
- XCTAssertEqual(truth, dstScalar)
- }
- func testScalarDoubleDoubleDouble() {
- let dstScalar = Scalar(2.0, 5.0, 5.0)
- let truth = Scalar(2.0, 5.0, 5.0, 0.0)
- XCTAssertEqual(truth, dstScalar);
- }
- func testScalarDoubleDoubleDoubleDouble() {
- let dstScalar = Scalar(2.0, 5.0, 5.0, 9.0)
- let truth = Scalar(2.0, 5.0, 5.0, 9.0)
- XCTAssertEqual(truth, dstScalar)
- }
- func testToString() {
- let actual = "\(s2)"
- let expected = "Scalar [1.000000, 1.000000, 1.000000, 1.000000]"
- XCTAssertEqual(expected, actual)
- }
- }
|