• 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"""Tests for logical_expressions module."""
16
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import print_function
20
21from tensorflow.contrib.py2tf.converters import converter_test_base
22from tensorflow.contrib.py2tf.converters import logical_expressions
23from tensorflow.python.ops import math_ops
24from tensorflow.python.platform import test
25
26
27class GradientsFunctionTest(converter_test_base.TestCase):
28
29  def test_equals(self):
30
31    def test_fn(a, b):
32      return a == b
33
34    node = self.parse_and_analyze(test_fn, {})
35    node = logical_expressions.transform(node)
36
37    with self.compiled(node, math_ops.equal) as result:
38      with self.test_session() as sess:
39        self.assertTrue(sess.run(result.test_fn(1, 1)))
40        self.assertFalse(sess.run(result.test_fn(1, 2)))
41
42  def test_bool_ops(self):
43
44    def test_fn(a, b, c):
45      return (a or b) and (a or b or c)
46
47    node = self.parse_and_analyze(test_fn, {})
48    node = logical_expressions.transform(node)
49
50    with self.compiled(node, math_ops.logical_or,
51                       math_ops.logical_and) as result:
52      with self.test_session() as sess:
53        self.assertTrue(sess.run(result.test_fn(True, False, True)))
54
55
56if __name__ == '__main__':
57  test.main()
58