1# Copyright 2015 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"""Test for version 3 of the zero_out op.""" 17 18from __future__ import absolute_import 19from __future__ import division 20from __future__ import print_function 21 22import tensorflow as tf 23from tensorflow.examples.adding_an_op import zero_out_op_3 24 25 26class ZeroOut3Test(tf.test.TestCase): 27 28 def test(self): 29 with self.test_session(): 30 result = zero_out_op_3.zero_out([5, 4, 3, 2, 1]) 31 self.assertAllEqual(result.eval(), [5, 0, 0, 0, 0]) 32 33 def testAttr(self): 34 with self.test_session(): 35 result = zero_out_op_3.zero_out([5, 4, 3, 2, 1], preserve_index=3) 36 self.assertAllEqual(result.eval(), [0, 0, 0, 2, 0]) 37 38 def testNegative(self): 39 with self.test_session(): 40 result = zero_out_op_3.zero_out([5, 4, 3, 2, 1], preserve_index=-1) 41 with self.assertRaisesOpError("Need preserve_index >= 0, got -1"): 42 result.eval() 43 44 def testLarge(self): 45 with self.test_session(): 46 result = zero_out_op_3.zero_out([5, 4, 3, 2, 1], preserve_index=17) 47 with self.assertRaisesOpError("preserve_index out of range"): 48 result.eval() 49 50 51if __name__ == "__main__": 52 tf.test.main() 53