github.com/google/grumpy@v0.0.0-20171122020858-3ec87959189c/lib/math_test.py (about) 1 # Copyright 2016 Google Inc. 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 import math 16 17 import weetest 18 19 # Tests exist for all functions which have logic in the math.py module, instead 20 # of simply calling the go equivalent. 21 22 23 def TestFactorial(): 24 assert math.factorial(0) == 1 25 assert math.factorial(1) == 1 26 assert math.factorial(2) == 2 27 assert math.factorial(3) == 6 28 assert math.factorial(4) == 24 29 assert math.factorial(5) == 120 30 31 32 def TestFactorialError(): 33 try: 34 math.factorial(-1) 35 except ValueError: 36 pass 37 else: 38 raise AssertionError 39 40 try: 41 math.factorial(0.5) 42 except ValueError: 43 pass 44 else: 45 raise AssertionError 46 47 48 def TestLdexp(): 49 assert math.ldexp(1,1) == 2 50 assert math.ldexp(1,2) == 4 51 assert math.ldexp(1.5,1) == 3 52 assert math.ldexp(1.5,2) == 6 53 54 55 def TestLog(): 56 assert math.log(math.e) == 1 57 assert math.log(2,2) == 1 58 assert math.log(10,10) == 1 59 assert math.log(100,10) == 2 60 61 62 def TestRadians(): 63 assert math.radians(180) == math.pi 64 assert math.radians(360) == 2 * math.pi 65 66 67 def TestDegrees(): 68 assert math.degrees(math.pi) == 180 69 assert math.degrees(2 * math.pi) == 360 70 71 72 if __name__ == '__main__': 73 weetest.RunTests()