• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 package org.tensorflow.op;
17 
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertNotEquals;
21 import static org.junit.Assert.assertTrue;
22 
23 import java.util.HashSet;
24 import java.util.Set;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
28 import org.tensorflow.Graph;
29 import org.tensorflow.Output;
30 import org.tensorflow.TestUtil;
31 
32 /** Unit tests for {@link org.tensorflow.op.PrimitiveOp} */
33 @RunWith(JUnit4.class)
34 public class PrimitiveOpTest {
35 
36   @Test
equalsHashcode()37   public void equalsHashcode() {
38     try (Graph g = new Graph()) {
39       Output<Integer> array = TestUtil.constant(g, "array", new int[2]);
40 
41       PrimitiveOp test1 =
42           new PrimitiveOp(g.opBuilder("Shape", "shape1").addInput(array).build()) {};
43       PrimitiveOp test2 =
44           new PrimitiveOp(g.opBuilder("Shape", "shape2").addInput(array).build()) {};
45       PrimitiveOp test3 = new PrimitiveOp(test1.operation) {};
46 
47       // equals() tests
48       assertNotEquals(test1, test2);
49       assertEquals(test1, test3);
50       assertEquals(test3, test1);
51       assertNotEquals(test2, test3);
52 
53       // hashcode() tests
54       Set<PrimitiveOp> ops = new HashSet<>();
55       assertTrue(ops.add(test1));
56       assertTrue(ops.add(test2));
57       assertFalse(ops.add(test3));
58     }
59   }
60 }
61