1 package org.opencv.test.core;
2 
3 import org.opencv.core.Scalar;
4 import org.opencv.test.OpenCVTestCase;
5 
6 public class ScalarTest extends OpenCVTestCase {
7 
8     private Scalar dstScalar;
9     private Scalar s1;
10     private Scalar s2;
11 
12     @Override
setUp()13     protected void setUp() throws Exception {
14         super.setUp();
15 
16         s1 = new Scalar(1.0);
17         s2 = Scalar.all(1.0);
18         dstScalar = null;
19     }
20 
testAll()21     public void testAll() {
22         dstScalar = Scalar.all(2.0);
23         Scalar truth = new Scalar(2.0, 2.0, 2.0, 2.0);
24         assertEquals(truth, dstScalar);
25     }
26 
testClone()27     public void testClone() {
28         dstScalar = s2.clone();
29         assertEquals(s2, dstScalar);
30     }
31 
testConj()32     public void testConj() {
33         dstScalar = s2.conj();
34         Scalar truth = new Scalar(1, -1, -1, -1);
35         assertEquals(truth, dstScalar);
36     }
37 
testEqualsObject()38     public void testEqualsObject() {
39         dstScalar = s2.clone();
40         assertTrue(s2.equals(dstScalar));
41 
42         assertFalse(s2.equals(s1));
43     }
44 
testHashCode()45     public void testHashCode() {
46         assertEquals(s2.hashCode(), s2.hashCode());
47     }
48 
testIsReal()49     public void testIsReal() {
50         assertTrue(s1.isReal());
51 
52         assertFalse(s2.isReal());
53     }
54 
testMulScalar()55     public void testMulScalar() {
56         dstScalar = s2.mul(s1);
57         assertEquals(s1, dstScalar);
58     }
59 
testMulScalarDouble()60     public void testMulScalarDouble() {
61         double multiplier = 2.0;
62         dstScalar = s2.mul(s1, multiplier);
63         Scalar truth = new Scalar(2);
64         assertEquals(truth, dstScalar);
65     }
66 
testScalarDouble()67     public void testScalarDouble() {
68         Scalar truth = new Scalar(1);
69         assertEquals(truth, s1);
70     }
71 
testScalarDoubleArray()72     public void testScalarDoubleArray() {
73         double[] vals = { 2.0, 4.0, 5.0, 3.0 };
74         dstScalar = new Scalar(vals);
75 
76         Scalar truth = new Scalar(2.0, 4.0, 5.0, 3.0);
77         assertEquals(truth, dstScalar);
78     }
79 
testScalarDoubleDouble()80     public void testScalarDoubleDouble() {
81         dstScalar = new Scalar(2, 5);
82         Scalar truth = new Scalar(2.0, 5.0, 0.0, 0.0);
83         assertEquals(truth, dstScalar);
84     }
85 
testScalarDoubleDoubleDouble()86     public void testScalarDoubleDoubleDouble() {
87         dstScalar = new Scalar(2.0, 5.0, 5.0);
88         Scalar truth = new Scalar(2.0, 5.0, 5.0, 0.0);
89         assertEquals(truth, dstScalar);
90     }
91 
testScalarDoubleDoubleDoubleDouble()92     public void testScalarDoubleDoubleDoubleDouble() {
93         dstScalar = new Scalar(2.0, 5.0, 5.0, 9.0);
94         Scalar truth = new Scalar(2.0, 5.0, 5.0, 9.0);
95         assertEquals(truth, dstScalar);
96     }
97 
testSet()98     public void testSet() {
99         double[] vals = { 1.0, 1.0, 1.0, 1.0 };
100         s1.set(vals);
101         assertEquals(s2, s1);
102     }
103 
testToString()104     public void testToString() {
105         String actual = s2.toString();
106         String expected = "[1.0, 1.0, 1.0, 1.0]";
107         assertEquals(expected, actual);
108     }
109 
110 }
111