ScalarTest.java 2.7 KB

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